Skip to content

Commit

Permalink
Fix pagination for SSO groups and added groupID to error log (#25)
Browse files Browse the repository at this point in the history
* Fix pagination

* Empty string checking

* Spelling
  • Loading branch information
loganintech authored Dec 22, 2023
1 parent 221bee7 commit d94f3ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 8 additions & 2 deletions pkg/connector/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ func ssoGroupIdFromARN(input string) (string, error) {
}
_, after, found := strings.Cut(id.Resource, "/group/")
if !found {
return "", fmt.Errorf("ssoGroupIdFromARN: invalid resrouce '%s' in ARN", input)
return "", fmt.Errorf("ssoGroupIdFromARN: invalid resource '%s' in ARN", input)
}
if after == "" {
return "", fmt.Errorf("ssoGroupIdFromARN: invalid resource '%s' in ARN", input)
}
return after, nil
}
Expand All @@ -76,7 +79,10 @@ func ssoUserIdFromARN(input string) (string, error) {
}
_, after, found := strings.Cut(id.Resource, "/user/")
if !found {
return "", fmt.Errorf("ssoUserIdFromARN: invalid resrouce '%s' in ARN", input)
return "", fmt.Errorf("ssoUserIdFromARN: invalid resource '%s' in ARN", input)
}
if after == "" {
return "", fmt.Errorf("ssoUserIdFromARN: invalid resource '%s' in ARN", input)
}
return after, nil
}
7 changes: 4 additions & 3 deletions pkg/connector/sso_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (o *ssoGroupResourceType) Grants(ctx context.Context, resource *v2.Resource

resp, err := o.identityStoreClient.ListGroupMemberships(ctx, input)
if err != nil {
return nil, "", nil, fmt.Errorf("aws-connector: identitystore.ListGroupMemberships failed: %w", err)
return nil, "", nil, fmt.Errorf("aws-connector: identitystore.ListGroupMemberships failed [%s]: %w", awsSdk.ToString(input.GroupId), err)
}

for _, user := range resp.GroupMemberships {
Expand All @@ -160,9 +160,10 @@ func (o *ssoGroupResourceType) Grants(ctx context.Context, resource *v2.Resource
}
rv = append(rv, grant)
}
nextPage, err := bag.Marshal()

nextPage, err := bag.NextToken(awsSdk.ToString(resp.NextToken))
if err != nil {
return nil, "", nil, fmt.Errorf("aws-connector: failed to marshal pagination bag: %w", err)
return nil, "", nil, fmt.Errorf("aws-connector: failed to marshal pagination bag [%s]: %w", awsSdk.ToString(input.GroupId), err)
}
return rv, nextPage, nil, nil
}
Expand Down

0 comments on commit d94f3ef

Please sign in to comment.