diff options
author | Niall Sheridan <nsheridan@gmail.com> | 2016-07-17 17:16:14 +0100 |
---|---|---|
committer | Niall Sheridan <nsheridan@gmail.com> | 2016-07-17 18:24:20 +0100 |
commit | c9849d667ab55c23d343332a11afb3eb8ede3f2d (patch) | |
tree | 86684d5481d8b12be84ea1a3a8f32afaac007efa /vendor/google.golang.org/cloud/storage | |
parent | 49f40a952943f26494d6407dc608b50b2ec0df7f (diff) |
Update vendor libs
Diffstat (limited to 'vendor/google.golang.org/cloud/storage')
-rw-r--r-- | vendor/google.golang.org/cloud/storage/acl.go | 38 | ||||
-rw-r--r-- | vendor/google.golang.org/cloud/storage/storage.go | 59 |
2 files changed, 56 insertions, 41 deletions
diff --git a/vendor/google.golang.org/cloud/storage/acl.go b/vendor/google.golang.org/cloud/storage/acl.go index 1c7be32..e4d968b 100644 --- a/vendor/google.golang.org/cloud/storage/acl.go +++ b/vendor/google.golang.org/cloud/storage/acl.go @@ -96,17 +96,7 @@ func (a *ACLHandle) bucketDefaultList(ctx context.Context) ([]ACLRule, error) { if err != nil { return nil, fmt.Errorf("storage: error listing default object ACL for bucket %q: %v", a.bucket, err) } - r := make([]ACLRule, 0, len(acls.Items)) - for _, v := range acls.Items { - if m, ok := v.(map[string]interface{}); ok { - entity, ok1 := m["entity"].(string) - role, ok2 := m["role"].(string) - if ok1 && ok2 { - r = append(r, ACLRule{Entity: ACLEntity(entity), Role: ACLRole(role)}) - } - } - } - return r, nil + return toACLRules(acls.Items), nil } func (a *ACLHandle) bucketDefaultSet(ctx context.Context, entity ACLEntity, role ACLRole) error { @@ -169,17 +159,7 @@ func (a *ACLHandle) objectList(ctx context.Context) ([]ACLRule, error) { if err != nil { return nil, fmt.Errorf("storage: error listing object ACL for bucket %q, file %q: %v", a.bucket, a.object, err) } - r := make([]ACLRule, 0, len(acls.Items)) - for _, v := range acls.Items { - if m, ok := v.(map[string]interface{}); ok { - entity, ok1 := m["entity"].(string) - role, ok2 := m["role"].(string) - if ok1 && ok2 { - r = append(r, ACLRule{Entity: ACLEntity(entity), Role: ACLRole(role)}) - } - } - } - return r, nil + return toACLRules(acls.Items), nil } func (a *ACLHandle) objectSet(ctx context.Context, entity ACLEntity, role ACLRole) error { @@ -202,3 +182,17 @@ func (a *ACLHandle) objectDelete(ctx context.Context, entity ACLEntity) error { } return nil } + +func toACLRules(items []interface{}) []ACLRule { + r := make([]ACLRule, 0, len(items)) + for _, v := range items { + if m, ok := v.(map[string]interface{}); ok { + entity, ok1 := m["entity"].(string) + role, ok2 := m["role"].(string) + if ok1 && ok2 { + r = append(r, ACLRule{Entity: ACLEntity(entity), Role: ACLRole(role)}) + } + } + } + return r +} diff --git a/vendor/google.golang.org/cloud/storage/storage.go b/vendor/google.golang.org/cloud/storage/storage.go index 75f0e55..1f667c1 100644 --- a/vendor/google.golang.org/cloud/storage/storage.go +++ b/vendor/google.golang.org/cloud/storage/storage.go @@ -68,50 +68,45 @@ const ( // AdminClient is a client type for performing admin operations on a project's // buckets. +// +// Deprecated: Client has all of AdminClient's methods. type AdminClient struct { - hc *http.Client - raw *raw.Service + c *Client projectID string } // NewAdminClient creates a new AdminClient for a given project. +// +// Deprecated: use NewClient instead. func NewAdminClient(ctx context.Context, projectID string, opts ...cloud.ClientOption) (*AdminClient, error) { c, err := NewClient(ctx, opts...) if err != nil { return nil, err } return &AdminClient{ - hc: c.hc, - raw: c.raw, + c: c, projectID: projectID, }, nil } // Close closes the AdminClient. func (c *AdminClient) Close() error { - c.hc = nil - return nil + return c.c.Close() } // Create creates a Bucket in the project. // If attrs is nil the API defaults will be used. +// +// Deprecated: use BucketHandle.Create instead. func (c *AdminClient) CreateBucket(ctx context.Context, bucketName string, attrs *BucketAttrs) error { - var bkt *raw.Bucket - if attrs != nil { - bkt = attrs.toRawBucket() - } else { - bkt = &raw.Bucket{} - } - bkt.Name = bucketName - req := c.raw.Buckets.Insert(c.projectID, bkt) - _, err := req.Context(ctx).Do() - return err + return c.c.Bucket(bucketName).Create(ctx, c.projectID, attrs) } // Delete deletes a Bucket in the project. +// +// Deprecated: use BucketHandle.Delete instead. func (c *AdminClient) DeleteBucket(ctx context.Context, bucketName string) error { - req := c.raw.Buckets.Delete(bucketName) - return req.Context(ctx).Do() + return c.c.Bucket(bucketName).Delete(ctx) } // Client is a client for interacting with Google Cloud Storage. @@ -180,6 +175,27 @@ func (c *Client) Bucket(name string) *BucketHandle { } } +// Create creates the Bucket in the project. +// If attrs is nil the API defaults will be used. +func (b *BucketHandle) Create(ctx context.Context, projectID string, attrs *BucketAttrs) error { + var bkt *raw.Bucket + if attrs != nil { + bkt = attrs.toRawBucket() + } else { + bkt = &raw.Bucket{} + } + bkt.Name = b.name + req := b.c.raw.Buckets.Insert(projectID, bkt) + _, err := req.Context(ctx).Do() + return err +} + +// Delete deletes the Bucket. +func (b *BucketHandle) Delete(ctx context.Context) error { + req := b.c.raw.Buckets.Delete(b.name) + return req.Context(ctx).Do() +} + // ACL returns an ACLHandle, which provides access to the bucket's access control list. // This controls who can list, create or overwrite the objects in a bucket. // This call does not perform any network operations. @@ -543,8 +559,13 @@ func (o *ObjectHandle) NewRangeReader(ctx context.Context, offset, length int64) return nil, ErrObjectNotExist } if res.StatusCode < 200 || res.StatusCode > 299 { + body, _ := ioutil.ReadAll(res.Body) res.Body.Close() - return nil, fmt.Errorf("storage: can't read object %v/%v, status code: %v", o.bucket, o.object, res.Status) + return nil, &googleapi.Error{ + Code: res.StatusCode, + Header: res.Header, + Body: string(body), + } } if offset > 0 && length != 0 && res.StatusCode != http.StatusPartialContent { res.Body.Close() |