aboutsummaryrefslogtreecommitdiff
path: root/vendor/cloud.google.com/go/storage/storage.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/cloud.google.com/go/storage/storage.go')
-rw-r--r--vendor/cloud.google.com/go/storage/storage.go53
1 files changed, 27 insertions, 26 deletions
diff --git a/vendor/cloud.google.com/go/storage/storage.go b/vendor/cloud.google.com/go/storage/storage.go
index 2681922..f47654a 100644
--- a/vendor/cloud.google.com/go/storage/storage.go
+++ b/vendor/cloud.google.com/go/storage/storage.go
@@ -346,7 +346,7 @@ func (o *ObjectHandle) Generation(gen int64) *ObjectHandle {
// If returns a new ObjectHandle that applies a set of preconditions.
// Preconditions already set on the ObjectHandle are ignored.
-// Operations on the new handle will only occur if the preconditions are
+// Operations on the new handle will return an error if the preconditions are not
// satisfied. See https://cloud.google.com/storage/docs/generations-preconditions
// for more details.
func (o *ObjectHandle) If(conds Conditions) *ObjectHandle {
@@ -467,6 +467,9 @@ func (o *ObjectHandle) Update(ctx context.Context, uattrs ObjectAttrsToUpdate) (
if o.userProject != "" {
call.UserProject(o.userProject)
}
+ if uattrs.PredefinedACL != "" {
+ call.PredefinedAcl(uattrs.PredefinedACL)
+ }
if err := setEncryptionHeaders(call.Header(), o.encryptionKey, false); err != nil {
return nil, err
}
@@ -501,6 +504,10 @@ type ObjectAttrsToUpdate struct {
CacheControl optional.String
Metadata map[string]string // set to map[string]string{} to delete
ACL []ACLRule
+
+ // If not empty, applies a predefined set of access controls. ACL must be nil.
+ // See https://cloud.google.com/storage/docs/json_api/v1/objects/patch.
+ PredefinedACL string
}
// Delete deletes the single specified object.
@@ -595,23 +602,8 @@ func parseKey(key []byte) (*rsa.PrivateKey, error) {
return parsed, nil
}
-func toRawObjectACL(oldACL []ACLRule) []*raw.ObjectAccessControl {
- var acl []*raw.ObjectAccessControl
- if len(oldACL) > 0 {
- acl = make([]*raw.ObjectAccessControl, len(oldACL))
- for i, rule := range oldACL {
- acl[i] = &raw.ObjectAccessControl{
- Entity: string(rule.Entity),
- Role: string(rule.Role),
- }
- }
- }
- return acl
-}
-
// toRawObject copies the editable attributes from o to the raw library's Object type.
func (o *ObjectAttrs) toRawObject(bucket string) *raw.Object {
- acl := toRawObjectACL(o.ACL)
return &raw.Object{
Bucket: bucket,
Name: o.Name,
@@ -621,7 +613,7 @@ func (o *ObjectAttrs) toRawObject(bucket string) *raw.Object {
CacheControl: o.CacheControl,
ContentDisposition: o.ContentDisposition,
StorageClass: o.StorageClass,
- Acl: acl,
+ Acl: toRawObjectACL(o.ACL),
Metadata: o.Metadata,
}
}
@@ -649,6 +641,14 @@ type ObjectAttrs struct {
// ACL is the list of access control rules for the object.
ACL []ACLRule
+ // If not empty, applies a predefined set of access controls. It should be set
+ // only when writing, copying or composing an object. When copying or composing,
+ // it acts as the destinationPredefinedAcl parameter.
+ // PredefinedACL is always empty for ObjectAttrs returned from the service.
+ // See https://cloud.google.com/storage/docs/json_api/v1/objects/insert
+ // for valid values.
+ PredefinedACL string
+
// Owner is the owner of the object. This field is read-only.
//
// If non-zero, it is in the form of "user-<userId>".
@@ -751,13 +751,6 @@ func newObject(o *raw.Object) *ObjectAttrs {
if o == nil {
return nil
}
- acl := make([]ACLRule, len(o.Acl))
- for i, rule := range o.Acl {
- acl[i] = ACLRule{
- Entity: ACLEntity(rule.Entity),
- Role: ACLRole(rule.Role),
- }
- }
owner := ""
if o.Owner != nil {
owner = o.Owner.Entity
@@ -774,7 +767,7 @@ func newObject(o *raw.Object) *ObjectAttrs {
ContentType: o.ContentType,
ContentLanguage: o.ContentLanguage,
CacheControl: o.CacheControl,
- ACL: acl,
+ ACL: toObjectACLRules(o.Acl),
Owner: owner,
ContentEncoding: o.ContentEncoding,
ContentDisposition: o.ContentDisposition,
@@ -1073,4 +1066,12 @@ func setEncryptionHeaders(headers http.Header, key []byte, copySource bool) erro
return nil
}
-// TODO(jbd): Add storage.objects.watch.
+// ServiceAccount fetches the email address of the given project's Google Cloud Storage service account.
+func (c *Client) ServiceAccount(ctx context.Context, projectID string) (string, error) {
+ r := c.raw.Projects.ServiceAccount.Get(projectID)
+ res, err := r.Context(ctx).Do()
+ if err != nil {
+ return "", err
+ }
+ return res.EmailAddress, nil
+}