Skip to content

Commit

Permalink
COSI-40: ignore-failure-if-access-key-deleted-in-flight
Browse files Browse the repository at this point in the history
  • Loading branch information
anurag4DSB committed Dec 13, 2024
1 parent 78e7736 commit 0fc0c11
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/clients/iam/iam_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,17 @@ func (client *IAMClient) DeleteAllAccessKeys(ctx context.Context, userName strin
if err != nil {
return fmt.Errorf("failed to list access keys for IAM user %s: %w", userName, err)
}

var noSuchEntityErr *types.NoSuchEntityException
for _, key := range listKeysOutput.AccessKeyMetadata {
_, err := client.IAMService.DeleteAccessKey(ctx, &iam.DeleteAccessKeyInput{
UserName: &userName,
AccessKeyId: key.AccessKeyId,
})
if err != nil {
if errors.As(err, &noSuchEntityErr) {
klog.V(5).InfoS("Access key does not exist, skipping deletion", "user", userName, "accessKeyId", *key.AccessKeyId)
continue
}
return fmt.Errorf("failed to delete access key %s for IAM user %s: %w", *key.AccessKeyId, userName, err)
}
klog.V(5).InfoS("Successfully deleted access key", "user", userName, "accessKeyId", *key.AccessKeyId)
Expand All @@ -230,7 +234,7 @@ func (client *IAMClient) DeleteUser(ctx context.Context, userName string) error
var noSuchEntityErr *types.NoSuchEntityException
if errors.As(err, &noSuchEntityErr) {
klog.InfoS("IAM user does not exist, skipping deletion", "user", userName)
return nil // User doesn't exist, nothing to delete
return nil
}
return fmt.Errorf("failed to delete IAM user %s: %w", userName, err)
}
Expand Down

0 comments on commit 0fc0c11

Please sign in to comment.