Skip to content

Commit

Permalink
Make getAccessTokenFromServiceProvider less complex
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninja243 committed Aug 21, 2023
1 parent b2f64d6 commit 553556a
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions accesstoken/accesstoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,31 @@ func getAccessTokenFromServiceProvider(tokenDescription string) (*credentials.Cr
})
credential, err := credResp.Extract()
if err != nil {
var badRequest golangsdk.ErrDefault400
if errors.As(err, &badRequest) {
accessTokens, listErr := ListAccessToken()
if listErr != nil {
return nil, listErr
}
credential, err = handlePotentialLimitError(err, user, client, tokenDescription)
}
return credential, err
}

//nolint:gomnd // The OpenTelekomCloud only lets users have up to two keys
if len(accessTokens) == 2 {
log.Printf("Hit the limit for access keys on OTC. You can only have 2. Removing keys made by otc-auth...")
return conditionallyReplaceAccessTokens(user, client, tokenDescription, accessTokens)
}
return nil, err
func handlePotentialLimitError(err error,
user *tokens.User,
client *golangsdk.ServiceClient,
tokenDescription string,
) (*credentials.Credential, error) {
var badRequest golangsdk.ErrDefault400
if errors.As(err, &badRequest) {
accessTokens, listErr := ListAccessToken()
if listErr != nil {
return nil, listErr
}
common.OutputErrorToConsoleAndExit(err)
}

return credential, err
//nolint:gomnd // The OpenTelekomCloud only lets users have up to two keys
if len(accessTokens) == 2 {
log.Printf("Hit the limit for access keys on OTC. You can only have 2. Removing keys made by otc-auth...")
return conditionallyReplaceAccessTokens(user, client, tokenDescription, accessTokens)
}
return nil, err
}
return nil, err
}

// Replaces AK/SKs made by otc-auth if their descriptions match the default..
Expand Down

0 comments on commit 553556a

Please sign in to comment.