github.com/grailbio/base@v0.0.11/cmd/grail-role-group/update.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/go-test/deep" 8 groupssettings "google.golang.org/api/groupssettings/v1" 9 "v.io/x/lib/cmdline" 10 "v.io/x/lib/vlog" 11 ) 12 13 func newGroup(g groupssettings.Groups) *groupssettings.Groups { 14 return &groupssettings.Groups{ 15 Description: description(g.Email), 16 17 AllowExternalMembers: "false", 18 AllowGoogleCommunication: "true", 19 AllowWebPosting: "false", 20 ArchiveOnly: "true", 21 IncludeCustomFooter: "false", 22 IncludeInGlobalAddressList: "true", 23 IsArchived: "true", 24 MembersCanPostAsTheGroup: "false", 25 MessageModerationLevel: "MODERATE_NONE", 26 ReplyTo: "REPLY_TO_IGNORE", 27 SendMessageDenyNotification: "false", 28 ShowInGroupDirectory: "true", 29 SpamModerationLevel: "MODERATE", 30 WhoCanAdd: "ALL_MANAGERS_CAN_ADD", 31 WhoCanContactOwner: "ALL_IN_DOMAIN_CAN_CONTACT", 32 WhoCanInvite: "ALL_MANAGERS_CAN_INVITE", 33 WhoCanJoin: "CAN_REQUEST_TO_JOIN", 34 WhoCanLeaveGroup: "ALL_MEMBERS_CAN_LEAVE", 35 WhoCanPostMessage: "NONE_CAN_POST", 36 WhoCanViewGroup: "ALL_IN_DOMAIN_CAN_VIEW", 37 WhoCanViewMembership: "ALL_IN_DOMAIN_CAN_VIEW", 38 39 Email: g.Email, 40 Kind: g.Kind, 41 MaxMessageBytes: g.MaxMessageBytes, 42 MessageDisplayFont: g.MessageDisplayFont, 43 Name: g.Name, 44 } 45 } 46 47 func runUpdate(_ *cmdline.Env, args []string) error { 48 if len(args) != 1 { 49 return fmt.Errorf("bad number of arguments, expected 1, got %q", args) 50 } 51 groupName := args[0] 52 if !Any(groupSuffix, func(v string) bool { 53 return strings.HasSuffix(groupName, v) 54 }) { 55 return fmt.Errorf("bad suffix: the group name %q doesn't end in %q", groupName, groupSuffix) 56 } 57 58 service, err := newGroupsSettingsService() 59 if err != nil { 60 return err 61 } 62 63 origGroup, err := service.Groups.Get(groupName).Do() 64 if err != nil { 65 return fmt.Errorf("groupssettings.Group.Get(%q): %v", groupName, err) 66 } 67 // We need to zero some fields to make the diff nicer. 68 origGroup.ServerResponse.HTTPStatusCode = 0 69 origGroup.ServerResponse.Header = nil 70 71 group := newGroup(*origGroup) 72 if !descriptionFlag { 73 group.Description = origGroup.Description 74 } 75 diff := deep.Equal(origGroup, group) 76 if len(diff) == 0 { 77 fmt.Println("No diffs") 78 return nil 79 } 80 81 fmt.Printf("Found %d diffs:\n\n", len(diff)) 82 for _, l := range diff { 83 fmt.Printf("\t%s\n", l) 84 } 85 fmt.Println() 86 87 if dryRunFlag { 88 return nil 89 } 90 updatedGroup, err := service.Groups.Update(groupName, group).Do() 91 vlog.Infof("%#v", updatedGroup) 92 if err != nil { 93 return fmt.Errorf("groupssettings.Group.Update(%q): %v", groupName, err) 94 } 95 return nil 96 }