github.com/grailbio/base@v0.0.11/cmd/grail-role-group/create.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "strings" 6 7 admin "google.golang.org/api/admin/directory/v1" 8 "v.io/x/lib/cmdline" 9 "v.io/x/lib/vlog" 10 ) 11 12 func runCreate(_ *cmdline.Env, args []string) error { 13 if len(args) != 1 { 14 return fmt.Errorf("bad number of arguments, expected 1, got %q", args) 15 } 16 groupName := args[0] 17 if !Any(groupSuffix, func(v string) bool { 18 return strings.HasSuffix(groupName, v) 19 }) { 20 return fmt.Errorf("bad suffix: the group name %q doesn't end in %q", groupName, groupSuffix) 21 } 22 23 adminService, err := newAdminService() 24 if err != nil { 25 return err 26 } 27 28 group, err := adminService.Groups.Insert(&admin.Group{ 29 Email: groupName, 30 Description: description(groupName), 31 }).Do() 32 if err != nil { 33 return err 34 } 35 vlog.Infof("%+v\n", group) 36 37 groupssettingService, err := newGroupsSettingsService() 38 if err != nil { 39 return err 40 } 41 42 settingsGroup, err := groupssettingService.Groups.Get(groupName).Do() 43 if err != nil { 44 return fmt.Errorf("groupssettings.Group.Get(%q): %v", groupName, err) 45 } 46 settingsGroup = newGroup(*settingsGroup) 47 updatedGroup, err := groupssettingService.Groups.Update(groupName, settingsGroup).Do() 48 vlog.Infof("%#v", updatedGroup) 49 if err != nil { 50 return fmt.Errorf("groupssettings.Group.Update(%q): %v", groupName, err) 51 } 52 return nil 53 }