-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(storage): add UpdateBucketACL implementation #5974
Changes from 4 commits
14624d3
8ab2cf4
b66b5e1
933cf81
0c81e39
d672a26
ba181e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -314,6 +314,12 @@ func (c *grpcStorageClient) UpdateBucket(ctx context.Context, bucket string, uat | |
if uattrs.PredefinedDefaultObjectACL != "" { | ||
fieldMask.Paths = append(fieldMask.Paths, "default_object_acl") | ||
} | ||
if uattrs.acl != nil { | ||
fieldMask.Paths = append(fieldMask.Paths, "acl") | ||
} | ||
if uattrs.defaultObjectACL != nil { | ||
fieldMask.Paths = append(fieldMask.Paths, "default_object_acl") | ||
} | ||
if uattrs.StorageClass != "" { | ||
fieldMask.Paths = append(fieldMask.Paths, "storage_class") | ||
} | ||
|
@@ -425,8 +431,24 @@ func (c *grpcStorageClient) ListBucketACLs(ctx context.Context, bucket string, o | |
} | ||
return attrs.ACL, nil | ||
} | ||
|
||
func (c *grpcStorageClient) UpdateBucketACL(ctx context.Context, bucket string, entity ACLEntity, role ACLRole, opts ...storageOption) (*ACLRule, error) { | ||
return nil, errMethodNotSupported | ||
// There is no separate API for PATCH in gRPC. | ||
// Make a GET call first to retrieve BucketAttrs. | ||
attrs, err := c.GetBucket(ctx, bucket, nil, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var acl []ACLRule | ||
acl = append(attrs.ACL, ACLRule{Entity: entity, Role: role}) | ||
uattrs := &BucketAttrsToUpdate{acl: acl} | ||
tritone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Call UpdateBucket with a MetagenerationMatch precondition set. | ||
b, err := c.UpdateBucket(ctx, bucket, uattrs, &BucketConditions{MetagenerationMatch: attrs.MetaGeneration}, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
aclRule := b.ACL[len(b.ACL)-1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's just return the ACLRule we sent rather than picking the last one off the list (I'm not sure if the ordering is guaranteed) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
return &aclRule, err | ||
} | ||
|
||
// Object ACL methods. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -423,6 +423,28 @@ func (c *httpStorageClient) ListBucketACLs(ctx context.Context, bucket string, o | |
return toBucketACLRules(acls.Items), nil | ||
} | ||
|
||
func (c *httpStorageClient) UpdateBucketACL(ctx context.Context, bucket string, entity ACLEntity, role ACLRole, opts ...storageOption) (*ACLRule, error) { | ||
s := callSettings(c.settings, opts...) | ||
acl := &raw.BucketAccessControl{ | ||
Bucket: bucket, | ||
Entity: string(entity), | ||
Role: string(role), | ||
} | ||
var aclRule ACLRule | ||
var err error | ||
err = run(ctx, func() error { | ||
req := c.raw.BucketAccessControls.Update(bucket, string(entity), acl) | ||
configureACLCall(ctx, s.userProject, req) | ||
acl, err = req.Do() | ||
aclRule = toBucketACLRule(acl) | ||
return err | ||
}, s.retry, false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, use |
||
if err != nil { | ||
return nil, err | ||
} | ||
return &aclRule, nil | ||
} | ||
|
||
// configureACLCall sets the context, user project and headers on the apiary library call. | ||
// This will panic if the call does not have the correct methods. | ||
func configureACLCall(ctx context.Context, userProject string, call interface{ Header() http.Header }) { | ||
|
@@ -434,10 +456,6 @@ func configureACLCall(ctx context.Context, userProject string, call interface{ H | |
setClientHeader(call.Header()) | ||
} | ||
|
||
func (c *httpStorageClient) UpdateBucketACL(ctx context.Context, bucket string, entity ACLEntity, role ACLRole, opts ...storageOption) (*ACLRule, error) { | ||
return nil, errMethodNotSupported | ||
} | ||
|
||
// Object ACL methods. | ||
|
||
func (c *httpStorageClient) DeleteObjectACL(ctx context.Context, bucket, object string, entity ACLEntity, opts ...storageOption) error { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very confused about what is going on with PredefinedACL and PredefinedDefaultObjectACL here... it doesn't seem like they are actually being set on the returned bucket?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, one cannot provide both a predefinedAcl and an acl while patching/updating a bucket. I tried out buckets.patch and buckets.update with the JSON API, and it results in a 409 conflict error.
So in the library code here,, PredefinedACL and PredefinedDefaultObjectACL take precedence and therefore clears ACLs.
That being said, I believe I need to handle the updateMask with more care under the update semantics. Let me know if this clarifies your question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, gotcha. Yeah I think ForceSendFields plays the same role for JSON that the updateMask plays for gRPC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appreciate the review, Chris! Added some inline comments. Hopefully that's clearer for readers and our future selves.