Skip to content
Snippets Groups Projects
Unverified Commit b85d7849 authored by Fabrice Rabaute's avatar Fabrice Rabaute
Browse files

google: Retrieve all the groups for a user

The list of groups is paginated (default page is 200), so when a user
has more than 200 groups, only the first 200 are retrieve.

This change is retrieving all the groups for a user by querying all the
pages.
parent 1cdb2b1d
Branches
Tags
No related merge requests found
...@@ -240,15 +240,24 @@ func (c *googleConnector) createIdentity(ctx context.Context, identity connector ...@@ -240,15 +240,24 @@ func (c *googleConnector) createIdentity(ctx context.Context, identity connector
// getGroups creates a connection to the admin directory service and lists // getGroups creates a connection to the admin directory service and lists
// all groups the user is a member of // all groups the user is a member of
func (c *googleConnector) getGroups(email string) ([]string, error) { func (c *googleConnector) getGroups(email string) ([]string, error) {
groupsList, err := c.adminSrv.Groups.List().UserKey(email).Do()
if err != nil {
return nil, fmt.Errorf("could not list groups: %v", err)
}
var userGroups []string var userGroups []string
for _, group := range groupsList.Groups { var err error
// TODO (joelspeed): Make desried group key configurable groupsList := &admin.Groups{}
userGroups = append(userGroups, group.Email) for {
groupsList, err = c.adminSrv.Groups.List().
UserKey(email).PageToken(groupsList.NextPageToken).Do()
if err != nil {
return nil, fmt.Errorf("could not list groups: %v", err)
}
for _, group := range groupsList.Groups {
// TODO (joelspeed): Make desried group key configurable
userGroups = append(userGroups, group.Email)
}
if groupsList.NextPageToken == "" {
break
}
} }
return userGroups, nil return userGroups, nil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment