github.com/grailbio/base@v0.0.11/cmd/grail-role-group/list.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"strings"
     7  
     8  	admin "google.golang.org/api/admin/directory/v1"
     9  	"google.golang.org/api/groupssettings/v1"
    10  	goauth2 "google.golang.org/api/oauth2/v1"
    11  	"v.io/x/lib/cmdline"
    12  )
    13  
    14  var scopes = []string{
    15  	goauth2.UserinfoEmailScope,
    16  	admin.AdminDirectoryGroupScope,
    17  	admin.AdminDirectoryGroupMemberScope,
    18  	admin.AdminDirectoryGroupReadonlyScope,
    19  	groupssettings.AppsGroupsSettingsScope,
    20  }
    21  
    22  func runList(_ *cmdline.Env, args []string) error {
    23  	service, err := newAdminService()
    24  	if err != nil {
    25  		return err
    26  	}
    27  	ctx := context.Background()
    28  	return service.Groups.List().Domain(domain).Pages(ctx, func(groups *admin.Groups) error {
    29  		for _, g := range groups.Groups {
    30  			if Any(groupSuffix, func(v string) bool {
    31  				return strings.HasSuffix(g.Email, v)
    32  			}) {
    33  				fmt.Printf("%v\n", g.Email)
    34  			}
    35  		}
    36  		return nil
    37  	})
    38  }