feat: allow deleting replications with remotes (#417)

This commit is contained in:
Dane Strandboge
2022-08-02 11:03:38 -05:00
committed by GitHub
parent 78ef3c127c
commit 0b6ce21cfe
3 changed files with 65 additions and 5 deletions

View File

@ -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)

View File

@ -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