Skip to content
This repository has been archived by the owner on Jun 27, 2021. It is now read-only.

Commit

Permalink
Skip the return on hasMember, immediately create (#24)
Browse files Browse the repository at this point in the history
* Skip the return on hasMember

* update version

* fix

* not duplicating code

* Release v0.1.6

Signed-off-by: Chase Sillevis <[email protected]>
  • Loading branch information
DeviaVir authored Jun 20, 2018
1 parent 8848f4b commit 05f7f05
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ GOVERSION := 1.9.3
PROJECT := $(CURRENT_DIR:$(GOPATH)/src/%=%)
OWNER := $(notdir $(patsubst %/,%,$(dir $(PROJECT))))
NAME := $(notdir $(PROJECT))
VERSION := 0.1.5
VERSION := 0.1.6
EXTERNAL_TOOLS = \
github.com/golang/dep/cmd/dep

Expand Down
26 changes: 16 additions & 10 deletions gsuite/resource_group_members.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func upsertMember(email, groupEmail, role string, config *Config) error {
return err
})
if err != nil {
return fmt.Errorf("Error checking hasmember: %s, %s", err, email)
return createGroupMember(groupMember, groupEmail, config)
}

if hasMemberResponse.IsMember == true {
Expand All @@ -327,21 +327,27 @@ func upsertMember(email, groupEmail, role string, config *Config) error {
}
log.Printf("[INFO] Updated groupMember: %s", updatedGroupMember.Email)
} else {
var createdGroupMember *directory.Member
err = retry(func() error {
createdGroupMember, err = config.directory.Members.Insert(groupEmail, groupMember).Do()
return err
})
if err != nil {
return fmt.Errorf("Error creating groupMember: %s, %s", err, email)
}
log.Printf("[INFO] Created groupMember: %s", createdGroupMember.Email)
return createGroupMember(groupMember, groupEmail, config)
}
}

return nil
}

func createGroupMember(groupMember *directory.Member, groupEmail string, config *Config) (err error) {
var createdGroupMember *directory.Member
err = retry(func() error {
createdGroupMember, err = config.directory.Members.Insert(groupEmail, groupMember).Do()
return err
})
if err != nil {
return fmt.Errorf("Error creating groupMember: %s, %s", err, groupMember.Email)
}
log.Printf("[INFO] Created groupMember: %s", createdGroupMember.Email)

return nil
}

func deleteMember(email, groupEmail string, config *Config) (err error) {
err = retry(func() error {
err = config.directory.Members.Delete(groupEmail, email).Do()
Expand Down

0 comments on commit 05f7f05

Please sign in to comment.