feat: added functionality for remote update command (#282)

* feat: added functionality for remote update command

* refactor: removed extra get request for TLS flag and minor changes to help text

* chore: pulled newest changes to openapi and ran make fmt

* refactor: shortened conditional statement to one line
This commit is contained in:
mcfarlm3
2021-10-04 10:28:07 -07:00
committed by GitHub
parent b7627a33c8
commit 3c3d70cc60
2 changed files with 99 additions and 3 deletions

View File

@ -57,6 +57,54 @@ func (c Client) Create(ctx context.Context, params *CreateParams) error {
return c.printRemote(printRemoteOpts{remote: &res}) return c.printRemote(printRemoteOpts{remote: &res})
} }
type UpdateParams struct {
RemoteID string
Name string
Description string
RemoteURL string
RemoteAPIToken string
RemoteOrgID string
AllowInsecureTLS bool
TLSFlagIsSet bool
}
func (c Client) Update(ctx context.Context, params *UpdateParams) error {
// build request
body := api.RemoteConnenctionUpdateRequest{}
if params.Name != "" {
body.SetName(params.Name)
}
if params.Description != "" {
body.SetDescription(params.Description)
}
if params.RemoteURL != "" {
body.SetRemoteURL(params.RemoteURL)
}
if params.RemoteAPIToken != "" {
body.SetRemoteAPIToken(params.RemoteAPIToken)
}
if params.RemoteOrgID != "" {
body.SetRemoteOrgID(params.RemoteOrgID)
}
if params.TLSFlagIsSet {
body.SetAllowInsecureTLS(params.AllowInsecureTLS)
}
// send patch request
res, err := c.PatchRemoteConnectionByID(ctx, params.RemoteID).RemoteConnenctionUpdateRequest(body).Execute()
if err != nil {
return fmt.Errorf("failed to update remote connection %q: %w", params.RemoteID, err)
}
// print updated remote connection info
return c.printRemote(printRemoteOpts{remote: &res})
}
type ListParams struct { type ListParams struct {
Name string Name string
OrgID string OrgID string

View File

@ -166,13 +166,61 @@ func newRemoteListCmd() cli.Command {
} }
func newRemoteUpdateCmd() cli.Command { func newRemoteUpdateCmd() cli.Command {
var params remote.UpdateParams
return cli.Command{ return cli.Command{
Name: "update", Name: "update",
Usage: "Update an existing remote connection", Usage: "Update an existing remote connection",
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs), Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
Flags: commonFlags(), Flags: append(
Action: func(ctx *cli.Context) { commonFlags(),
fmt.Println("remote update command was called") &cli.StringFlag{
Name: "remote-id, id",
Usage: "Remote connection ID",
Required: true,
Destination: &params.RemoteID,
},
&cli.StringFlag{
Name: "name, n",
Usage: "New name for the remote connection",
Destination: &params.Name,
},
&cli.StringFlag{
Name: "description, d",
Usage: "New description for the remote connection",
Destination: &params.Description,
},
&cli.StringFlag{
Name: "remote-url",
Usage: "New url for the remote database",
Destination: &params.RemoteURL,
},
&cli.StringFlag{
Name: "remote-api-token",
Usage: "New API token for the remote database",
Destination: &params.RemoteAPIToken,
},
&cli.StringFlag{
Name: "remote-org-id",
Usage: "New ID of the remote organization",
Destination: &params.RemoteOrgID,
},
&cli.BoolFlag{
Name: "allow-insecure-tls",
Usage: "Allows insecure TLS",
Destination: &params.AllowInsecureTLS,
},
),
Action: func(ctx *cli.Context) error {
api := getAPI(ctx)
client := remote.Client{
CLI: getCLI(ctx),
RemoteConnectionsApi: api.RemoteConnectionsApi,
}
params.TLSFlagIsSet = ctx.IsSet("allow-insecure-tls")
return client.Update(getContext(ctx), &params)
}, },
} }
} }