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 | |
parent | 49f40a952943f26494d6407dc608b50b2ec0df7f (diff) |
Update vendor libs
Diffstat (limited to 'vendor/google.golang.org/cloud')
-rw-r--r-- | vendor/google.golang.org/cloud/AUTHORS | 1 | ||||
-rw-r--r-- | vendor/google.golang.org/cloud/CONTRIBUTORS | 1 | ||||
-rw-r--r-- | vendor/google.golang.org/cloud/README.md | 13 | ||||
-rw-r--r-- | vendor/google.golang.org/cloud/compute/metadata/metadata.go | 87 | ||||
-rw-r--r-- | vendor/google.golang.org/cloud/internal/opts/option.go | 25 | ||||
-rw-r--r-- | vendor/google.golang.org/cloud/internal/transport/dial.go | 56 | ||||
-rw-r--r-- | vendor/google.golang.org/cloud/option.go | 75 | ||||
-rw-r--r-- | vendor/google.golang.org/cloud/storage/acl.go | 38 | ||||
-rw-r--r-- | vendor/google.golang.org/cloud/storage/storage.go | 59 |
9 files changed, 170 insertions, 185 deletions
diff --git a/vendor/google.golang.org/cloud/AUTHORS b/vendor/google.golang.org/cloud/AUTHORS index f92e5cf..c364af1 100644 --- a/vendor/google.golang.org/cloud/AUTHORS +++ b/vendor/google.golang.org/cloud/AUTHORS @@ -6,6 +6,7 @@ # Name or Organization <email address> # The email address is not required for organizations. +Filippo Valsorda <hi@filippo.io> Google Inc. Ingo Oeser <nightlyone@googlemail.com> Palm Stone Games, Inc. diff --git a/vendor/google.golang.org/cloud/CONTRIBUTORS b/vendor/google.golang.org/cloud/CONTRIBUTORS index 27db791..6e1e7f1 100644 --- a/vendor/google.golang.org/cloud/CONTRIBUTORS +++ b/vendor/google.golang.org/cloud/CONTRIBUTORS @@ -17,6 +17,7 @@ Burcu Dogan <jbd@google.com> Dave Day <djd@golang.org> David Sansome <me@davidsansome.com> David Symonds <dsymonds@golang.org> +Filippo Valsorda <hi@filippo.io> Glenn Lewis <gmlewis@google.com> Ingo Oeser <nightlyone@googlemail.com> Johan Euphrosine <proppy@google.com> diff --git a/vendor/google.golang.org/cloud/README.md b/vendor/google.golang.org/cloud/README.md index 13b7a0d..75b94eb 100644 --- a/vendor/google.golang.org/cloud/README.md +++ b/vendor/google.golang.org/cloud/README.md @@ -19,7 +19,7 @@ Google API | Status | Package [Datastore][cloud-datastore] | beta | [`google.golang.org/cloud/datastore`][cloud-datastore-ref] [Storage][cloud-storage] | beta | [`google.golang.org/cloud/storage`][cloud-storage-ref] [Pub/Sub][cloud-pubsub] | experimental | [`google.golang.org/cloud/pubsub`][cloud-pubsub-ref] -[BigTable][cloud-bigtable] | stable | [`google.golang.org/cloud/bigtable`][cloud-bigtable-ref] +[Bigtable][cloud-bigtable] | stable | [`google.golang.org/cloud/bigtable`][cloud-bigtable-ref] [BigQuery][cloud-bigquery] | experimental | [`google.golang.org/cloud/bigquery`][cloud-bigquery-ref] [Logging][cloud-logging] | experimental | [`google.golang.org/cloud/logging`][cloud-logging-ref] @@ -37,6 +37,17 @@ Google API | Status | Package Documentation and examples are available at https://godoc.org/google.golang.org/cloud +Visit or join the +[google-api-go-announce group](https://groups.google.com/forum/#!forum/google-api-go-announce) +for updates on these packages. + +## Go Versions Supported + +We support the two most recent major versions of Go. If Google App Engine uses +an older version, we support that as well. You can see which versions are +currently supported by looking at the lines following `go:` in +[`.travis.yml`](.travis.yml). + ## Authorization By default, each API will use [Google Application Default Credentials][default-creds] diff --git a/vendor/google.golang.org/cloud/compute/metadata/metadata.go b/vendor/google.golang.org/cloud/compute/metadata/metadata.go index 13a1ed9..9821843 100644 --- a/vendor/google.golang.org/cloud/compute/metadata/metadata.go +++ b/vendor/google.golang.org/cloud/compute/metadata/metadata.go @@ -27,6 +27,7 @@ import ( "net/http" "net/url" "os" + "runtime" "strings" "sync" "time" @@ -37,8 +38,17 @@ import ( "google.golang.org/cloud/internal" ) -// metadataIP is the documented metadata server IP address. -const metadataIP = "169.254.169.254" +const ( + // metadataIP is the documented metadata server IP address. + metadataIP = "169.254.169.254" + + // metadataHostEnv is the environment variable specifying the + // GCE metadata hostname. If empty, the default value of + // metadataIP ("169.254.169.254") is used instead. + // This is variable name is not defined by any spec, as far as + // I know; it was made up for the Go package. + metadataHostEnv = "GCE_METADATA_HOST" +) type cachedValue struct { k string @@ -110,7 +120,7 @@ func getETag(client *http.Client, suffix string) (value, etag string, err error) // deployments. To enable spoofing of the metadata service, the environment // variable GCE_METADATA_HOST is first inspected to decide where metadata // requests shall go. - host := os.Getenv("GCE_METADATA_HOST") + host := os.Getenv(metadataHostEnv) if host == "" { // Using 169.254.169.254 instead of "metadata" here because Go // binaries built with the "netgo" tag and without cgo won't @@ -163,25 +173,27 @@ func (c *cachedValue) get() (v string, err error) { return } -var onGCE struct { - sync.Mutex - set bool - v bool -} +var ( + onGCEOnce sync.Once + onGCE bool +) // OnGCE reports whether this process is running on Google Compute Engine. func OnGCE() bool { - defer onGCE.Unlock() - onGCE.Lock() - if onGCE.set { - return onGCE.v - } - onGCE.set = true - onGCE.v = testOnGCE() - return onGCE.v + onGCEOnce.Do(initOnGCE) + return onGCE +} + +func initOnGCE() { + onGCE = testOnGCE() } func testOnGCE() bool { + // The user explicitly said they're on GCE, so trust them. + if os.Getenv(metadataHostEnv) != "" { + return true + } + ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -208,9 +220,52 @@ func testOnGCE() bool { resc <- strsContains(addrs, metadataIP) }() + tryHarder := systemInfoSuggestsGCE() + if tryHarder { + res := <-resc + if res { + // The first strategy succeeded, so let's use it. + return true + } + // Wait for either the DNS or metadata server probe to + // contradict the other one and say we are running on + // GCE. Give it a lot of time to do so, since the system + // info already suggests we're running on a GCE BIOS. + timer := time.NewTimer(5 * time.Second) + defer timer.Stop() + select { + case res = <-resc: + return res + case <-timer.C: + // Too slow. Who knows what this system is. + return false + } + } + + // There's no hint from the system info that we're running on + // GCE, so use the first probe's result as truth, whether it's + // true or false. The goal here is to optimize for speed for + // users who are NOT running on GCE. We can't assume that + // either a DNS lookup or an HTTP request to a blackholed IP + // address is fast. Worst case this should return when the + // metaClient's Transport.ResponseHeaderTimeout or + // Transport.Dial.Timeout fires (in two seconds). return <-resc } +// systemInfoSuggestsGCE reports whether the local system (without +// doing network requests) suggests that we're running on GCE. If this +// returns true, testOnGCE tries a bit harder to reach its metadata +// server. +func systemInfoSuggestsGCE() bool { + if runtime.GOOS != "linux" { + // We don't have any non-Linux clues available, at least yet. + return false + } + slurp, _ := ioutil.ReadFile("/sys/class/dmi/id/product_name") + return strings.TrimSpace(string(slurp)) == "Google" +} + // Subscribe subscribes to a value from the metadata service. // The suffix is appended to "http://${GCE_METADATA_HOST}/computeMetadata/v1/". // The suffix may contain query parameters. diff --git a/vendor/google.golang.org/cloud/internal/opts/option.go b/vendor/google.golang.org/cloud/internal/opts/option.go deleted file mode 100644 index 844d310..0000000 --- a/vendor/google.golang.org/cloud/internal/opts/option.go +++ /dev/null @@ -1,25 +0,0 @@ -// Package opts holds the DialOpts struct, configurable by -// cloud.ClientOptions to set up transports for cloud packages. -// -// This is a separate page to prevent cycles between the core -// cloud packages. -package opts - -import ( - "net/http" - - "golang.org/x/oauth2" - "google.golang.org/grpc" -) - -type DialOpt struct { - Endpoint string - Scopes []string - UserAgent string - - TokenSource oauth2.TokenSource - - HTTPClient *http.Client - GRPCClient *grpc.ClientConn - GRPCDialOpts []grpc.DialOption -} diff --git a/vendor/google.golang.org/cloud/internal/transport/dial.go b/vendor/google.golang.org/cloud/internal/transport/dial.go index a0f8bd9..f554953 100644 --- a/vendor/google.golang.org/cloud/internal/transport/dial.go +++ b/vendor/google.golang.org/cloud/internal/transport/dial.go @@ -15,18 +15,14 @@ package transport import ( - "errors" "fmt" "net/http" "golang.org/x/net/context" - "golang.org/x/oauth2" - "golang.org/x/oauth2/google" + "google.golang.org/api/option" + "google.golang.org/api/transport" "google.golang.org/cloud" - "google.golang.org/cloud/internal/opts" "google.golang.org/grpc" - "google.golang.org/grpc/credentials" - "google.golang.org/grpc/credentials/oauth" ) // ErrHTTP is returned when on a non-200 HTTP response. @@ -47,55 +43,19 @@ func (e *ErrHTTP) Error() string { // service, configured with the given ClientOptions. It also returns the endpoint // for the service as specified in the options. func NewHTTPClient(ctx context.Context, opt ...cloud.ClientOption) (*http.Client, string, error) { - var o opts.DialOpt + o := make([]option.ClientOption, 0, len(opt)) for _, opt := range opt { - opt.Resolve(&o) + o = append(o, opt.Resolve()) } - if o.GRPCClient != nil { - return nil, "", errors.New("unsupported GRPC base transport specified") - } - // TODO(djd): Wrap all http.Clients with appropriate internal version to add - // UserAgent header and prepend correct endpoint. - if o.HTTPClient != nil { - return o.HTTPClient, o.Endpoint, nil - } - if o.TokenSource == nil { - var err error - o.TokenSource, err = google.DefaultTokenSource(ctx, o.Scopes...) - if err != nil { - return nil, "", fmt.Errorf("google.DefaultTokenSource: %v", err) - } - } - return oauth2.NewClient(ctx, o.TokenSource), o.Endpoint, nil + return transport.NewHTTPClient(ctx, o...) } // DialGRPC returns a GRPC connection for use communicating with a Google cloud // service, configured with the given ClientOptions. func DialGRPC(ctx context.Context, opt ...cloud.ClientOption) (*grpc.ClientConn, error) { - var o opts.DialOpt + o := make([]option.ClientOption, 0, len(opt)) for _, opt := range opt { - opt.Resolve(&o) - } - if o.HTTPClient != nil { - return nil, errors.New("unsupported HTTP base transport specified") - } - if o.GRPCClient != nil { - return o.GRPCClient, nil - } - if o.TokenSource == nil { - var err error - o.TokenSource, err = google.DefaultTokenSource(ctx, o.Scopes...) - if err != nil { - return nil, fmt.Errorf("google.DefaultTokenSource: %v", err) - } - } - grpcOpts := []grpc.DialOption{ - grpc.WithPerRPCCredentials(oauth.TokenSource{o.TokenSource}), - grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, "")), - } - grpcOpts = append(grpcOpts, o.GRPCDialOpts...) - if o.UserAgent != "" { - grpcOpts = append(grpcOpts, grpc.WithUserAgent(o.UserAgent)) + o = append(o, opt.Resolve()) } - return grpc.Dial(o.Endpoint, grpcOpts...) + return transport.DialGRPC(ctx, o...) } diff --git a/vendor/google.golang.org/cloud/option.go b/vendor/google.golang.org/cloud/option.go index 8a443b4..4788c67 100644 --- a/vendor/google.golang.org/cloud/option.go +++ b/vendor/google.golang.org/cloud/option.go @@ -18,97 +18,64 @@ import ( "net/http" "golang.org/x/oauth2" - "google.golang.org/cloud/internal/opts" + "google.golang.org/api/option" "google.golang.org/grpc" ) // ClientOption is used when construct clients for each cloud service. type ClientOption interface { - // Resolve configures the given DialOpts for this option. - Resolve(*opts.DialOpt) + // Resolve returns the equivalent option from the + // google.golang.org/api/option package. + Resolve() option.ClientOption } -// WithTokenSource returns a ClientOption that specifies an OAuth2 token -// source to be used as the basis for authentication. -func WithTokenSource(s oauth2.TokenSource) ClientOption { - return withTokenSource{s} +type wrapOpt struct { + o option.ClientOption } -type withTokenSource struct{ ts oauth2.TokenSource } +func (w wrapOpt) Resolve() option.ClientOption { + return w.o +} -func (w withTokenSource) Resolve(o *opts.DialOpt) { - o.TokenSource = w.ts +// WithTokenSource returns a ClientOption that specifies an OAuth2 token +// source to be used as the basis for authentication. +func WithTokenSource(s oauth2.TokenSource) ClientOption { + return wrapOpt{option.WithTokenSource(s)} } // WithEndpoint returns a ClientOption that overrides the default endpoint // to be used for a service. func WithEndpoint(url string) ClientOption { - return withEndpoint(url) -} - -type withEndpoint string - -func (w withEndpoint) Resolve(o *opts.DialOpt) { - o.Endpoint = string(w) + return wrapOpt{option.WithEndpoint(url)} } // WithScopes returns a ClientOption that overrides the default OAuth2 scopes // to be used for a service. func WithScopes(scope ...string) ClientOption { - return withScopes(scope) -} - -type withScopes []string - -func (w withScopes) Resolve(o *opts.DialOpt) { - s := make([]string, len(w)) - copy(s, w) - o.Scopes = s + return wrapOpt{option.WithScopes(scope...)} } // WithUserAgent returns a ClientOption that sets the User-Agent. func WithUserAgent(ua string) ClientOption { - return withUA(ua) + return wrapOpt{option.WithUserAgent(ua)} } -type withUA string - -func (w withUA) Resolve(o *opts.DialOpt) { o.UserAgent = string(w) } - // WithBaseHTTP returns a ClientOption that specifies the HTTP client to // use as the basis of communications. This option may only be used with // services that support HTTP as their communication transport. func WithBaseHTTP(client *http.Client) ClientOption { - return withBaseHTTP{client} -} - -type withBaseHTTP struct{ client *http.Client } - -func (w withBaseHTTP) Resolve(o *opts.DialOpt) { - o.HTTPClient = w.client + return wrapOpt{option.WithHTTPClient(client)} } // WithBaseGRPC returns a ClientOption that specifies the gRPC client // connection to use as the basis of communications. This option many only be // used with services that support gRPC as their communication transport. -func WithBaseGRPC(client *grpc.ClientConn) ClientOption { - return withBaseGRPC{client} -} - -type withBaseGRPC struct{ client *grpc.ClientConn } - -func (w withBaseGRPC) Resolve(o *opts.DialOpt) { - o.GRPCClient = w.client +func WithBaseGRPC(conn *grpc.ClientConn) ClientOption { + return wrapOpt{option.WithGRPCConn(conn)} } // WithGRPCDialOption returns a ClientOption that appends a new grpc.DialOption // to an underlying gRPC dial. It does not work with WithBaseGRPC. -func WithGRPCDialOption(opt grpc.DialOption) ClientOption { - return withGRPCDialOption{opt} -} - -type withGRPCDialOption struct{ opt grpc.DialOption } - -func (w withGRPCDialOption) Resolve(o *opts.DialOpt) { - o.GRPCDialOpts = append(o.GRPCDialOpts, w.opt) +func WithGRPCDialOption(o grpc.DialOption) ClientOption { + return wrapOpt{option.WithGRPCDialOption(o)} } 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() |