Merge pull request #1627 from jfrabaute/master

google: Retrieve all the groups for a user
This commit is contained in:
Nándor István Krácser 2020-01-20 08:30:17 +01:00 committed by GitHub
commit aca67b0839
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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