A predefined ACL is an alias for a list of ACLs. The alias is expanded by the service at write time; it is not present in returned bucket or object metadata.
Predefined ACLs would need to be supported for the following methods (* = not yet implemented):
BucketHandle.Create, Update: PredefinedACL, PredefinedDefaultObjectACL
ObjectHandle.CopyTo, Compose, Rewrite*: DestinationPredefinedACL
ObjectHandle.NewWriter, Update: PredefinedACL
We already have Conditions, which are effectively call options applied to subsequent calls. We should use Conditions for predefined ACLs as well.
Other choices, for completeness:
OK, not Conditions, since these are more like options on the call. So here are two alternatives, one per comment. Comment on or vote for (via the "reactions" smiley face) your fave.
We could add a PredefinedACL field to ObjectAttrs and BucketAttrs, and a PredefinedDefaultObjectACL field to BucketAttrs. These would be documented as write-only: set them on an Attrs that you pass to one of the methods that creates or changes an object or bucket. They will always be empty when retrieving an Attrs from the service.
Examples:
bkt := client.Bucket("mybucket").Create(ctx, "myproject", &BucketAttrs{
PredefinedACL: "private",
PredefinedDefaultObjectACL: "authenticatedRead",
})
bkt.Object("foo").Update(ctx, ObjectAttrs{PredefinedACL: "publicRead"})
Pros:
Cons:
Variant: Change the type of the ACL fields of the Attrs so it can be either a []ACLRule (which it is now) or a string, the predefined ACL name.
type ACL interface { implsACL() }
type PredefinedACL string
type ACLRules []ACLRule
...
Pros:
Cons:
ObjectAttrs{ACL: PredefinedACL("private")}var rs []ACLRule; ObjectAttrs{ACL: ACLRules(rs)}ObjectAttrs{ACL: ACLRules{{...}, {...}}}Second alternative: Options.
type Option interface { ... }
func PredefinedACL(string) Option {...}
func PredefinedDefaultObjectACL(string) Option {...}
func (*BucketHandle) Create(ctx context.Context, projectID string, attrs *BucketAttrs,
opts ...Option) {...}
Pros:
Cons:
PredefinedDefaultObjectACL.BucketOption and ObjectOption types, but then we need two functions for PredefinedACL.@okdave @mcgreevy @broady @bradfitz
I am having similar problems and I can't find the answer in the API documentation.
In my case, I want to set PredefinedACL: "publicRead" while uploading a file.
object := &storage.Object{Name: fileName}
service.Objects.Insert(*bucketName, object).Media(file).Do();
How should I set PredefinedACL?
Cheers
PS: A link to the answer in the documentation would be hugely appreciated, probably it is there but I don't know where to find it.
This issue is about the high-level client, cloud.google.com/go/storage, which we generally recommend. However, since we don't have this feature yet, you should continue using the google.golang.org/api/storage client for now.
To answer your question, call PredefinedAcl as one of the chained methods in your second line, before calling Do.
Wonderful, thanks a bunch @jba
Most helpful comment
This issue is about the high-level client, cloud.google.com/go/storage, which we generally recommend. However, since we don't have this feature yet, you should continue using the google.golang.org/api/storage client for now.
To answer your question, call PredefinedAcl as one of the chained methods in your second line, before calling
Do.