mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-03 03:12:50 +02:00
internal/directory: improve google user groups list (#1092)
Skip group without members, so it saves us time to handle group members, and reduce the size of groups. While at it, also querying API with the fields we need. Fixes #567
This commit is contained in:
parent
02b4e4b619
commit
59c17fb497
1 changed files with 6 additions and 0 deletions
|
@ -92,9 +92,14 @@ func (p *Provider) UserGroups(ctx context.Context) ([]*directory.User, error) {
|
|||
var groups []string
|
||||
err = apiClient.Groups.List().
|
||||
Context(ctx).
|
||||
Fields("id", "email", "directMembersCount").
|
||||
Customer("my_customer").
|
||||
Pages(ctx, func(res *admin.Groups) error {
|
||||
for _, g := range res.Groups {
|
||||
// Skip group without member.
|
||||
if g.DirectMembersCount == 0 {
|
||||
continue
|
||||
}
|
||||
groups = append(groups, g.Id)
|
||||
groupIDToEmails[g.Id] = g.Email
|
||||
}
|
||||
|
@ -109,6 +114,7 @@ func (p *Provider) UserGroups(ctx context.Context) ([]*directory.User, error) {
|
|||
group := group
|
||||
err = apiClient.Members.List(group).
|
||||
Context(ctx).
|
||||
Fields("id").
|
||||
Pages(ctx, func(res *admin.Members) error {
|
||||
for _, member := range res.Members {
|
||||
userIDToGroups[member.Id] = append(userIDToGroups[member.Id], group, groupIDToEmails[group])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue