Skip to content

Commit

Permalink
use pagination for keycloak_group_memberships resource (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
sl-benoitoyez authored May 24, 2021
1 parent afb5f1d commit 458fa5c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion docs/resources/group_memberships.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Also note that you should not use `keycloak_group_memberships` with a group has
This resource **should not** be used to control membership of a group that has its members federated from an external
source via group mapping.

To non-exclusivly manage the group's of a user, see the [`keycloak_user_groups` resource][1]
To non-exclusively manage the group's of a user, see the [`keycloak_user_groups` resource][1]

This resource paginates its data loading on refresh by 50 items.

## Example Usage

Expand Down
13 changes: 10 additions & 3 deletions keycloak/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,17 @@ func (keycloakClient *KeycloakClient) ListGroupsWithName(realmId, name string) (

func (keycloakClient *KeycloakClient) GetGroupMembers(realmId, groupId string) ([]*User, error) {
var users []*User
var first, pagination int = 0, 50
var iterationUsers []*User

err := keycloakClient.get(fmt.Sprintf("/realms/%s/groups/%s/members?max=-1", realmId, groupId), &users, nil)
if err != nil {
return nil, err
for ok := true; ok; ok = (len(iterationUsers) > 0) {
iterationUsers = nil
err := keycloakClient.get(fmt.Sprintf("/realms/%s/groups/%s/members?max=%d&first=%d", realmId, groupId, pagination, first), &iterationUsers, nil)
if err != nil {
return nil, err
}
users = append(users, iterationUsers...)
first += pagination
}

for _, user := range users {
Expand Down

0 comments on commit 458fa5c

Please sign in to comment.