feat: added functionality for replication update
command (#299)
* feat: added functionality for replication update command * refactor: changed replication update usage text for clarity * fix: added closing bracket back in * chore: ran make fmt
This commit is contained in:
@ -104,6 +104,48 @@ func (c Client) List(ctx context.Context, params *ListParams) error {
|
|||||||
return c.printReplication(printOpts)
|
return c.printReplication(printOpts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdateParams struct {
|
||||||
|
ReplicationID string
|
||||||
|
Name string
|
||||||
|
Description string
|
||||||
|
RemoteID string
|
||||||
|
RemoteBucketID string
|
||||||
|
MaxQueueSize int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c Client) Update(ctx context.Context, params *UpdateParams) error {
|
||||||
|
// build request
|
||||||
|
body := api.ReplicationUpdateRequest{}
|
||||||
|
|
||||||
|
if params.Name != "" {
|
||||||
|
body.SetName(params.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
if params.Description != "" {
|
||||||
|
body.SetDescription(params.Description)
|
||||||
|
}
|
||||||
|
|
||||||
|
if params.RemoteID != "" {
|
||||||
|
body.SetRemoteID(params.RemoteID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if params.RemoteBucketID != "" {
|
||||||
|
body.SetRemoteBucketID(params.RemoteBucketID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if params.MaxQueueSize != 0 {
|
||||||
|
body.SetMaxQueueSizeBytes(params.MaxQueueSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
// send patch request
|
||||||
|
res, err := c.PatchReplicationByID(ctx, params.ReplicationID).ReplicationUpdateRequest(body).Execute()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to update replication stream %q: %w", params.ReplicationID, err)
|
||||||
|
}
|
||||||
|
// print updated replication stream info
|
||||||
|
return c.printReplication(printReplicationOpts{replication: &res})
|
||||||
|
}
|
||||||
|
|
||||||
func (c Client) Delete(ctx context.Context, replicationID string) error {
|
func (c Client) Delete(ctx context.Context, replicationID string) error {
|
||||||
// get replication stream via ID
|
// get replication stream via ID
|
||||||
connection, err := c.GetReplicationByID(ctx, replicationID).Execute()
|
connection, err := c.GetReplicationByID(ctx, replicationID).Execute()
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/influxdata/influx-cli/v2/clients/replication"
|
"github.com/influxdata/influx-cli/v2/clients/replication"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
|
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
@ -172,13 +170,54 @@ func newReplicationListCmd() cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newReplicationUpdateCmd() cli.Command {
|
func newReplicationUpdateCmd() cli.Command {
|
||||||
|
var params replication.UpdateParams
|
||||||
return cli.Command{
|
return cli.Command{
|
||||||
Name: "update",
|
Name: "update",
|
||||||
Usage: "Update an existing replication stream",
|
Usage: "Update an existing replication stream",
|
||||||
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("replication update command was called")
|
&cli.StringFlag{
|
||||||
|
Name: "id, i",
|
||||||
|
Usage: "ID of the replication stream to be updated",
|
||||||
|
Required: true,
|
||||||
|
Destination: ¶ms.ReplicationID,
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "name, n",
|
||||||
|
Usage: "New name for the replication stream",
|
||||||
|
Destination: ¶ms.Name,
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "description, d",
|
||||||
|
Usage: "New description for the replication stream",
|
||||||
|
Destination: ¶ms.Description,
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "remote-id",
|
||||||
|
Usage: "New ID of remote connection the replication stream should send data to",
|
||||||
|
Destination: ¶ms.RemoteID,
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "remote-bucket",
|
||||||
|
Usage: "New ID of remote bucket that data should be replicated to",
|
||||||
|
Destination: ¶ms.RemoteBucketID,
|
||||||
|
},
|
||||||
|
&cli.Int64Flag{
|
||||||
|
Name: "max-queue-bytes",
|
||||||
|
Usage: "New max queue size in bytes",
|
||||||
|
Destination: ¶ms.MaxQueueSize,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
Action: func(ctx *cli.Context) error {
|
||||||
|
api := getAPI(ctx)
|
||||||
|
|
||||||
|
client := replication.Client{
|
||||||
|
CLI: getCLI(ctx),
|
||||||
|
ReplicationsApi: api.ReplicationsApi,
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.Update(getContext(ctx), ¶ms)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user