Skip to content

Commit

Permalink
fix(accounts): avoiding break if have more than 20 accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
thalescosta committed Feb 22, 2023
1 parent 72d9392 commit 1ee9b72
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pkg/aws/sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,22 @@ func newOIDCToken(ctx context.Context, startUrl, region string) (*ssooidc.Create
}

func ListAccounts(ctx context.Context, client *sso.Client, token *string) []types.AccountInfo {
acc, err := client.ListAccounts(ctx, &sso.ListAccountsInput{AccessToken: token})
if err != nil {
log.Fatalf("unable to list accounts, %v", err)
var (
nextToken *string
accounts []types.AccountInfo
)
for {
acc, err := client.ListAccounts(ctx, &sso.ListAccountsInput{AccessToken: token, NextToken: nextToken, MaxResults: aws.Int32(50)})
if err != nil {
log.Fatalf("unable to list accounts, %v", err)
}
accounts = append(accounts, acc.AccountList...)
nextToken = acc.NextToken
if nextToken == nil {
break
}
}

return acc.AccountList
return accounts
}

func GetRolesByAccount(ctx context.Context, client *sso.Client, account types.AccountInfo, token *string) []types.RoleInfo {
Expand Down

0 comments on commit 1ee9b72

Please sign in to comment.