Skip to content

fix: use ListAccountsPages instead of manual pagination loop#59

Open
stark256-spec wants to merge 1 commit into
GSA:masterfrom
stark256-spec:fix/use-list-accounts-pages
Open

fix: use ListAccountsPages instead of manual pagination loop#59
stark256-spec wants to merge 1 commit into
GSA:masterfrom
stark256-spec:fix/use-list-accounts-pages

Conversation

@stark256-spec

Copy link
Copy Markdown

Closes #21.

Change

Replaces the hand-rolled NextToken pagination loop in listAccountsForMaster() with Organizations.ListAccountsPages(), which handles pagination automatically.

Before (~20 lines of manual pagination):

result, err := as.organizationsSvc.ListAccounts(input)
// ...
for token != "" {
    input.NextToken = &token
    result, err := as.organizationsSvc.ListAccounts(input)
    // ...
}

After (idiomatic SDK pagination):

err := as.organizationsSvc.ListAccountsPages(
    &organizations.ListAccountsInput{},
    func(page *organizations.ListAccountsOutput, lastPage bool) bool {
        accounts = append(accounts, page.Accounts...)
        return !lastPage
    },
)

The test mock is updated from ListAccounts to ListAccountsPages to match the new call site.

Replace the hand-rolled NextToken pagination loop in listAccountsForMaster
with Organizations.ListAccountsPages(), which handles pagination internally
and reduces boilerplate.

Update the mockOrgSvc test double to implement ListAccountsPages instead
of ListAccounts to match the new call site.

Closes GSA#21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use Organizations.ListAccountsPages()

1 participant