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:
@ -57,6 +57,54 @@ func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
||||
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 {
|
||||
Name string
|
||||
OrgID string
|
||||
|
@ -166,13 +166,61 @@ func newRemoteListCmd() cli.Command {
|
||||
}
|
||||
|
||||
func newRemoteUpdateCmd() cli.Command {
|
||||
var params remote.UpdateParams
|
||||
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")
|
||||
Flags: append(
|
||||
commonFlags(),
|
||||
&cli.StringFlag{
|
||||
Name: "remote-id, id",
|
||||
Usage: "Remote connection ID",
|
||||
Required: true,
|
||||
Destination: ¶ms.RemoteID,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "name, n",
|
||||
Usage: "New name for the remote connection",
|
||||
Destination: ¶ms.Name,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "description, d",
|
||||
Usage: "New description for the remote connection",
|
||||
Destination: ¶ms.Description,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "remote-url",
|
||||
Usage: "New url for the remote database",
|
||||
Destination: ¶ms.RemoteURL,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "remote-api-token",
|
||||
Usage: "New API token for the remote database",
|
||||
Destination: ¶ms.RemoteAPIToken,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "remote-org-id",
|
||||
Usage: "New ID of the remote organization",
|
||||
Destination: ¶ms.RemoteOrgID,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "allow-insecure-tls",
|
||||
Usage: "Allows insecure TLS",
|
||||
Destination: ¶ms.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), ¶ms)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user