Skip to content

Commit

Permalink
Delete existing access keys before creating new one
Browse files Browse the repository at this point in the history
  • Loading branch information
katherinelc321 committed Sep 9, 2021
1 parent c1b5a39 commit 60b6330
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cmd/account/rotate-secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,29 @@ func (o *rotateSecretOptions) run() error {
// Username is osdManagedAdmin-aaabbb
osdManagedAdminUsername := common.OSDManagedAdminIAM + "-" + accountIDSuffixLabel

// List and delete any existing access keys
inputListAccessKeys := &iam.ListAccessKeysInput{
UserName: &osdManagedAdminUsername,
}

accessKeys, err := awsClient.ListAccessKeys(inputListAccessKeys)
if err != nil {
return err
}

for _, k := range accessKeys.AccessKeyMetadata {

inputDelKey := &iam.DeleteAccessKeyInput{
AccessKeyId: k.AccessKeyId,
UserName: &osdManagedAdminUsername,
}
_, err = awsClient.DeleteAccessKey(inputDelKey)
if err != nil {
return err
}
}

// Create new access key
createAccessKeyOutput, err := awsClient.CreateAccessKey(&iam.CreateAccessKeyInput{
UserName: aws.String(osdManagedAdminUsername),
})
Expand Down

0 comments on commit 60b6330

Please sign in to comment.