Skip to content

Commit

Permalink
Support pagination when fetching IAM users. wallix#12
Browse files Browse the repository at this point in the history
  • Loading branch information
AJ Kerrigan committed Feb 24, 2017
1 parent c64e826 commit 47397b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
21 changes: 10 additions & 11 deletions cloud/aws/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,18 @@ func (s *Access) fetch_all_user_graph() (*graph.Graph, []*iam.UserDetail, error)
go func() {
defer wg.Done()

out, err := s.ListUsers(&iam.ListUsersInput{})
err := s.ListUsersPages(&iam.ListUsersInput{}, func(page *iam.ListUsersOutput, lastPage bool) bool {
for _, user := range page.Users {
res, badResErr := newResource(user)
if badResErr != nil {
return false
}
g.AddResource(res)
}
return true
})
if err != nil {
errc <- err
return
}

for _, output := range out.Users {
res, err := newResource(output)
if err != nil {
errc <- err
return
}
g.AddResource(res)
}
}()

Expand Down
5 changes: 5 additions & 0 deletions cloud/aws/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ func (m *mockIam) ListUsers(input *iam.ListUsersInput) (*iam.ListUsersOutput, er
return &iam.ListUsersOutput{Users: m.users}, nil
}

func (m *mockIam) ListUsersPages(input *iam.ListUsersInput, fn func(p *iam.ListUsersOutput, lastPage bool) (shouldContinue bool)) error {
fn(&iam.ListUsersOutput{Users: m.users}, true)
return nil
}

func (m *mockIam) ListPolicies(input *iam.ListPoliciesInput) (*iam.ListPoliciesOutput, error) {
var policies []*iam.Policy
for _, p := range m.managedPolicies {
Expand Down

0 comments on commit 47397b8

Please sign in to comment.