
* feat: implement remote create subcommand * chore: generate mocks for testing remote command * refactor: separated out test code, made small changes to remote create code * chore: ran make fmt * chore: removed excess print statements * refactor: made changes suggested in code review * refactor: added name and remote id to printed table
128 lines
3.4 KiB
Go
128 lines
3.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/influxdata/influx-cli/v2/clients/remote"
|
|
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
func newRemoteCmd() cli.Command {
|
|
return cli.Command{
|
|
Name: "remote",
|
|
Usage: "Remote connection management commands",
|
|
Hidden: true, // Remove this line when all subcommands are completed
|
|
Subcommands: []cli.Command{
|
|
newRemoteCreateCmd(),
|
|
newRemoteDeleteCmd(),
|
|
newRemoteListCmd(),
|
|
newRemoteUpdateCmd(),
|
|
},
|
|
}
|
|
}
|
|
|
|
func newRemoteCreateCmd() cli.Command {
|
|
var params remote.CreateParams
|
|
return cli.Command{
|
|
Name: "create",
|
|
Usage: "Create a new remote connection",
|
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
|
Flags: append(
|
|
commonFlags(),
|
|
&cli.StringFlag{
|
|
Name: "name, n",
|
|
Usage: "Name for the new remote connection",
|
|
Required: true,
|
|
Destination: ¶ms.Name,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "description, d",
|
|
Usage: "Description for the new remote connection",
|
|
Destination: ¶ms.Description,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "org-id",
|
|
Usage: "The ID of the local organization",
|
|
EnvVar: "INFLUX_ORG_ID",
|
|
Destination: ¶ms.OrgID,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "org, o",
|
|
Usage: "The name of the organization",
|
|
EnvVar: "INFLUX_ORG",
|
|
Destination: ¶ms.OrgName,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "remote-url",
|
|
Usage: "The url for the remote database",
|
|
Required: true,
|
|
Destination: ¶ms.RemoteURL,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "remote-api-token",
|
|
Usage: "The API token for the remote database",
|
|
Required: true,
|
|
Destination: ¶ms.RemoteAPIToken,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "remote-org-id",
|
|
Usage: "The ID of the remote organization",
|
|
Required: true,
|
|
Destination: ¶ms.RemoteOrgID,
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "allow-insecure-tls",
|
|
Usage: "Allows insecure TLS",
|
|
Destination: ¶ms.AllowInsecureTLS,
|
|
},
|
|
),
|
|
Action: func(ctx *cli.Context) error {
|
|
client := remote.Client{
|
|
CLI: getCLI(ctx),
|
|
RemoteConnectionsApi: getAPI(ctx).RemoteConnectionsApi,
|
|
OrganizationsApi: getAPI(ctx).OrganizationsApi,
|
|
}
|
|
|
|
return client.Create(getContext(ctx), ¶ms)
|
|
},
|
|
}
|
|
}
|
|
|
|
func newRemoteDeleteCmd() cli.Command {
|
|
return cli.Command{
|
|
Name: "delete",
|
|
Usage: "Delete an existing remote connection",
|
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
|
Flags: commonFlags(),
|
|
Action: func(ctx *cli.Context) {
|
|
fmt.Println("remote delete command was called")
|
|
},
|
|
}
|
|
}
|
|
|
|
func newRemoteListCmd() cli.Command {
|
|
return cli.Command{
|
|
Name: "list",
|
|
Usage: "List all remote connections",
|
|
Aliases: []string{"find", "ls"},
|
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
|
Flags: commonFlags(),
|
|
Action: func(ctx *cli.Context) {
|
|
fmt.Println("remote list command was called")
|
|
},
|
|
}
|
|
}
|
|
|
|
func newRemoteUpdateCmd() cli.Command {
|
|
return cli.Command{
|
|
Name: "update",
|
|
Usage: "Update an existing remote connection",
|
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
|
Flags: commonFlags(),
|
|
Action: func(ctx *cli.Context) {
|
|
fmt.Println("remote update command was called")
|
|
},
|
|
}
|
|
}
|