Skip to content

Commit 7e69c32

Browse files
author
AJ Kerrigan
committed
Support pagination when fetching IAM users. wallix#12
1 parent c64e826 commit 7e69c32

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

cloud/aws/api.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,19 @@ func (s *Access) fetch_all_user_graph() (*graph.Graph, []*iam.UserDetail, error)
126126
go func() {
127127
defer wg.Done()
128128

129-
out, err := s.ListUsers(&iam.ListUsersInput{})
129+
err := s.ListUsersPages(&iam.ListUsersInput{}, func(page *iam.ListUsersOutput, lastPage bool) bool {
130+
for _, user := range page.Users {
131+
res, err := newResource(user)
132+
if err != nil {
133+
errc <- err
134+
return false
135+
}
136+
g.AddResource(res)
137+
}
138+
return true
139+
})
130140
if err != nil {
131141
errc <- err
132-
return
133-
}
134-
135-
for _, output := range out.Users {
136-
res, err := newResource(output)
137-
if err != nil {
138-
errc <- err
139-
return
140-
}
141-
g.AddResource(res)
142142
}
143143
}()
144144

cloud/aws/mocks_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ func (m *mockIam) ListUsers(input *iam.ListUsersInput) (*iam.ListUsersOutput, er
7979
return &iam.ListUsersOutput{Users: m.users}, nil
8080
}
8181

82+
func (m *mockIam) ListUsersPages(input *iam.ListUsersInput, fn func(p *iam.ListUsersOutput, lastPage bool) (shouldContinue bool)) error {
83+
fn(&iam.ListUsersOutput{Users: m.users}, true)
84+
return nil
85+
}
86+
8287
func (m *mockIam) ListPolicies(input *iam.ListPoliciesInput) (*iam.ListPoliciesOutput, error) {
8388
var policies []*iam.Policy
8489
for _, p := range m.managedPolicies {

0 commit comments

Comments
 (0)