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

Commit

Permalink
Upper/Lower case (#27)
Browse files Browse the repository at this point in the history
* Upper/Lower case

* up version to 0.1.8

* Release v0.1.8

Signed-off-by: Chase Sillevis <[email protected]>
  • Loading branch information
DeviaVir authored Jul 23, 2018
1 parent 1ece8af commit 5908636
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 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.7
VERSION := 0.1.8
EXTERNAL_TOOLS = \
github.com/golang/dep/cmd/dep

Expand Down
5 changes: 3 additions & 2 deletions gsuite/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gsuite
import (
"fmt"
"log"
"strings"

"github.com/hashicorp/terraform/helper/schema"

Expand Down Expand Up @@ -64,7 +65,7 @@ func resourceGroupCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

group := &directory.Group{
Email: d.Get("email").(string),
Email: strings.ToLower(d.Get("email").(string)),
}

if v, ok := d.GetOk("name"); ok {
Expand Down Expand Up @@ -101,7 +102,7 @@ func resourceGroupUpdate(d *schema.ResourceData, meta interface{}) error {

if d.HasChange("email") {
log.Printf("[DEBUG] Updating group email: %s", d.Get("email").(string))
group.Email = d.Get("email").(string)
group.Email = strings.ToLower(d.Get("email").(string))
}

if d.HasChange("name") {
Expand Down
16 changes: 8 additions & 8 deletions gsuite/resource_group_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func resourceGroupMemberCreate(d *schema.ResourceData, meta interface{}) error {
group := d.Get("group").(string)

groupMember := &directory.Member{
Role: d.Get("role").(string),
Email: d.Get("email").(string),
Role: strings.ToUpper(d.Get("role").(string)),
Email: strings.ToLower(d.Get("email").(string)),
}

var createdGroupMember *directory.Member
Expand All @@ -101,7 +101,7 @@ func resourceGroupMemberUpdate(d *schema.ResourceData, meta interface{}) error {

if d.HasChange("email") {
log.Printf("[DEBUG] Updating groupMember email: %s", d.Get("email").(string))
groupMember.Email = d.Get("email").(string)
groupMember.Email = strings.ToLower(d.Get("email").(string))
}

if len(nullFields) > 0 {
Expand All @@ -111,7 +111,7 @@ func resourceGroupMemberUpdate(d *schema.ResourceData, meta interface{}) error {
var updatedGroupMember *directory.Member
var err error
err = retry(func() error {
updatedGroupMember, err = config.directory.Members.Patch(d.Get("group").(string), d.Id(), groupMember).Do()
updatedGroupMember, err = config.directory.Members.Patch(strings.ToLower(d.Get("group").(string)), d.Id(), groupMember).Do()
return err
})

Expand All @@ -129,7 +129,7 @@ func resourceGroupMemberRead(d *schema.ResourceData, meta interface{}) error {
var groupMember *directory.Member
var err error
err = retry(func() error {
groupMember, err = config.directory.Members.Get(d.Get("group").(string), d.Id()).Do()
groupMember, err = config.directory.Members.Get(strings.ToLower(d.Get("group").(string)), d.Id()).Do()
return err
})

Expand All @@ -138,7 +138,7 @@ func resourceGroupMemberRead(d *schema.ResourceData, meta interface{}) error {
}

d.SetId(groupMember.Id)
d.Set("email", groupMember.Email)
d.Set("email", strings.ToLower(groupMember.Email))
d.Set("etag", groupMember.Etag)
d.Set("kind", groupMember.Kind)
d.Set("status", groupMember.Status)
Expand All @@ -152,7 +152,7 @@ func resourceGroupMemberDelete(d *schema.ResourceData, meta interface{}) error {

var err error
err = retry(func() error {
err = config.directory.Members.Delete(d.Get("group").(string), d.Id()).Do()
err = config.directory.Members.Delete(strings.ToLower(d.Get("group").(string)), d.Id()).Do()
return err
})
if err != nil {
Expand All @@ -175,7 +175,7 @@ func resourceGroupMemberImporter(d *schema.ResourceData, meta interface{}) ([]*s
if len(s) < 2 {
return nil, fmt.Errorf("Import via [group]:[member email] or [group]/[member email]!")
}
group, member := s[0], s[1]
group, member := strings.ToLower(s[0]), strings.ToLower(s[1])

id, err := config.directory.Members.Get(group, member).Do()

Expand Down
19 changes: 10 additions & 9 deletions gsuite/resource_group_members.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gsuite
import (
"fmt"
"log"
"strings"

"github.com/hashicorp/terraform/helper/schema"
directory "google.golang.org/api/admin/directory/v1"
Expand Down Expand Up @@ -47,7 +48,7 @@ func resourceGroupMembersRead(d *schema.ResourceData, meta interface{}) error {
return err
}

d.Set("group_email", groupEmail)
d.Set("group_email", strings.ToLower(groupEmail))
d.Set("member", membersToCfg(members))
return nil
}
Expand Down Expand Up @@ -118,7 +119,7 @@ func resourceMembers(d *schema.ResourceData) (members []map[string]interface{})

func createOrUpdateGroupMembers(d *schema.ResourceData, meta interface{}) (string, error) {
config := meta.(*Config)
groupEmail := d.Get("group_email").(string)
groupEmail := strings.ToLower(d.Get("group_email").(string))

// Get members from config
cfgMembers := resourceMembers(d)
Expand Down Expand Up @@ -168,8 +169,8 @@ func reconcileMembers(d *schema.ResourceData, cfgMembers, apiMembers []map[strin
} else {
// The member exists in the config and the API
// If role has changed update, otherwise do nothing
cfgRole = cfgMember["role"].(string)
apiRole = apiMember["role"].(string)
cfgRole = strings.ToUpper(cfgMember["role"].(string))
apiRole = strings.ToUpper(apiMember["role"].(string))
if cfgRole != apiRole {
groupMember := &directory.Member{
Role: cfgRole,
Expand All @@ -183,8 +184,8 @@ func reconcileMembers(d *schema.ResourceData, cfgMembers, apiMembers []map[strin
var err error
err = retry(func() error {
updatedGroupMember, err = config.directory.Members.Patch(
d.Get("group_email").(string),
cfgMember["email"].(string),
strings.ToLower(d.Get("group_email").(string)),
strings.ToLower(cfgMember["email"].(string)),
groupMember).Do()
return err
})
Expand Down Expand Up @@ -239,8 +240,8 @@ func getApiMembers(groupEmail string, config *Config) ([]*directory.Member, erro

func upsertMember(email, groupEmail, role string, config *Config) error {
groupMember := &directory.Member{
Role: role,
Email: email,
Role: strings.ToUpper(role),
Email: strings.ToLower(email),
}

// Check if the email address belongs to a user, or to a group
Expand Down Expand Up @@ -367,7 +368,7 @@ func resourceGroupMembersImporter(d *schema.ResourceData, meta interface{}) ([]*
var group *directory.Group
var err error
err = retry(func() error {
group, err = config.directory.Groups.Get(d.Id()).Do()
group, err = config.directory.Groups.Get(strings.ToLower(d.Id())).Do()
return err
})

Expand Down
3 changes: 2 additions & 1 deletion gsuite/resource_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gsuite
import (
"fmt"
"log"
"strings"

"github.com/hashicorp/terraform/helper/schema"

Expand Down Expand Up @@ -289,7 +290,7 @@ func resourceUserCreate(d *schema.ResourceData, meta interface{}) error {
}
if v, ok := d.GetOk("primary_email"); ok {
log.Printf("[DEBUG] Setting %s: %s", "primary_email", v.(string))
user.PrimaryEmail = v.(string)
user.PrimaryEmail = strings.ToLower(v.(string))
}
if v, ok := d.GetOk("password"); ok {
log.Printf("[DEBUG] Setting %s: %s", "password", v.(string))
Expand Down

0 comments on commit 5908636

Please sign in to comment.