feat: added functionality for remote create subcommand (#268)

* 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
This commit is contained in:
mcfarlm3
2021-09-14 13:03:17 -07:00
committed by GitHub
parent 2d1f3ee3bc
commit dcf9f5bc9a
11 changed files with 2327 additions and 6 deletions

View File

@ -3,6 +3,7 @@ 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"
)
@ -22,13 +23,68 @@ func newRemoteCmd() cli.Command {
}
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: commonFlags(),
Action: func(ctx *cli.Context) {
fmt.Println("remote create command was called")
Flags: append(
commonFlags(),
&cli.StringFlag{
Name: "name, n",
Usage: "Name for the new remote connection",
Required: true,
Destination: &params.Name,
},
&cli.StringFlag{
Name: "description, d",
Usage: "Description for the new remote connection",
Destination: &params.Description,
},
&cli.StringFlag{
Name: "org-id",
Usage: "The ID of the local organization",
EnvVar: "INFLUX_ORG_ID",
Destination: &params.OrgID,
},
&cli.StringFlag{
Name: "org, o",
Usage: "The name of the organization",
EnvVar: "INFLUX_ORG",
Destination: &params.OrgName,
},
&cli.StringFlag{
Name: "remote-url",
Usage: "The url for the remote database",
Required: true,
Destination: &params.RemoteURL,
},
&cli.StringFlag{
Name: "remote-api-token",
Usage: "The API token for the remote database",
Required: true,
Destination: &params.RemoteAPIToken,
},
&cli.StringFlag{
Name: "remote-org-id",
Usage: "The ID of the remote organization",
Required: true,
Destination: &params.RemoteOrgID,
},
&cli.BoolFlag{
Name: "allow-insecure-tls",
Usage: "Allows insecure TLS",
Destination: &params.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), &params)
},
}
}