diff --git a/api/contract/openapi b/api/contract/openapi index d6f9073..588064f 160000 --- a/api/contract/openapi +++ b/api/contract/openapi @@ -1 +1 @@ -Subproject commit d6f9073685dfb58e36f20c2ed351cf872ad31a86 +Subproject commit 588064fe68e7dfeebd019695aa805832632cbfb6 diff --git a/clients/remote/remote.go b/clients/remote/remote.go index 0f7a253..ecfa434 100644 --- a/clients/remote/remote.go +++ b/clients/remote/remote.go @@ -101,6 +101,29 @@ func (c Client) List(ctx context.Context, params *ListParams) error { return c.printRemote(printOpts) } +func (c Client) Delete(ctx context.Context, remoteID string) error { + connection, err := c.GetRemoteConnectionByID(ctx, remoteID).Execute() + if err != nil { + return fmt.Errorf("failed to delete remote connection %q: %w", remoteID, err) + } + + req := c.DeleteRemoteConnectionByID(ctx, remoteID) + + // send delete request + err = req.Execute() + if err != nil { + return fmt.Errorf("failed to delete remote connection %q: %w", remoteID, err) + } + + // print deleted connection info + printOpts := printRemoteOpts{ + remote: &connection, + deleted: true, + } + + return c.printRemote(printOpts) +} + type printRemoteOpts struct { remote *api.RemoteConnection remotes []api.RemoteConnection diff --git a/cmd/influx/remote.go b/cmd/influx/remote.go index 3e8992a..d55f04f 100644 --- a/cmd/influx/remote.go +++ b/cmd/influx/remote.go @@ -92,13 +92,29 @@ func newRemoteCreateCmd() cli.Command { } func newRemoteDeleteCmd() cli.Command { + var remoteID string 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") + Flags: append( + commonFlags(), + &cli.StringFlag{ + Name: "remote-id, id", + Usage: "ID of the remote connection to be deleted", + Required: true, + Destination: &remoteID, + }, + ), + Action: func(ctx *cli.Context) error { + api := getAPI(ctx) + + client := remote.Client{ + CLI: getCLI(ctx), + RemoteConnectionsApi: api.RemoteConnectionsApi, + } + + return client.Delete(getContext(ctx), remoteID) }, } }