feat: allow deleting replications with remotes (#417)
This commit is contained in:
@ -151,10 +151,18 @@ 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()
|
||||
func (c Client) Get(ctx context.Context, remoteID string) (api.RemoteConnection, error) {
|
||||
conn, err := c.GetRemoteConnectionByID(ctx, remoteID).Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete remote connection %q: %w", remoteID, err)
|
||||
return conn, fmt.Errorf("failed to find remote connection with ID %q: %w", remoteID, err)
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
func (c Client) Delete(ctx context.Context, remoteID string) error {
|
||||
connection, err := c.Get(ctx, remoteID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := c.DeleteRemoteConnectionByID(ctx, remoteID)
|
||||
|
@ -190,6 +190,30 @@ func (c Client) Delete(ctx context.Context, replicationID string) error {
|
||||
return c.printReplication(printOpts)
|
||||
}
|
||||
|
||||
func (c Client) DeleteWithRemoteID(ctx context.Context, conn api.RemoteConnection) error {
|
||||
reps, err := c.GetReplications(ctx).OrgID(conn.OrgID).RemoteID(conn.Id).Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find replication streams with remote ID %q: %w", conn.Id, err)
|
||||
}
|
||||
|
||||
if reps.Replications != nil {
|
||||
for _, rep := range reps.GetReplications() {
|
||||
if err := c.DeleteReplicationByID(ctx, rep.Id).Execute(); err != nil {
|
||||
return fmt.Errorf("failed to delete replication with ID %q: %w", rep.Id, err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("no replications found for remote ID %q", conn.Id)
|
||||
}
|
||||
|
||||
printOpts := printReplicationOpts{
|
||||
replications: reps.GetReplications(),
|
||||
deleted: true,
|
||||
}
|
||||
|
||||
return c.printReplication(printOpts)
|
||||
}
|
||||
|
||||
type printReplicationOpts struct {
|
||||
replication *api.Replication
|
||||
replications []api.Replication
|
||||
|
Reference in New Issue
Block a user