Skip to content

Commit 1dcdcab

Browse files
committed
add comment to grantRole and simplify setting member slice
1 parent 863fb62 commit 1dcdcab

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

google/apistore.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ func (c *APIStore) GrantObjectAdmin(bucket, member string) error {
106106
return c.grantRole(bucket, member, "roles/storage.objectAdmin")
107107
}
108108

109+
// grantRole updates the IAM policy for @bucket in order to rant @role to @member
110+
// we have to retrieve the existing policy in order to modify it, per https://cloud.google.com/storage/docs/json_api/v1/buckets/setIamPolicy
109111
func (c *APIStore) grantRole(bucket, member, role string) error {
110112
existingPolicy, err := c.service.Buckets.GetIamPolicy(bucket).Do()
111113
if err != nil {
@@ -130,7 +132,7 @@ func (c *APIStore) grantRole(bucket, member, role string) error {
130132
if !added {
131133
b := new(storage.PolicyBindings)
132134
b.Role = role
133-
b.Members = append(b.Members, member)
135+
b.Members = []string{member}
134136
existingPolicy.Bindings = append(existingPolicy.Bindings, b)
135137
}
136138
_, err = c.service.Buckets.SetIamPolicy(bucket, existingPolicy).Do()

0 commit comments

Comments
 (0)