Skip to content

Commit

Permalink
blob/gcsblob: Don't hard-fail if no DefaultCredentials are found
Browse files Browse the repository at this point in the history
  • Loading branch information
vangent committed Aug 21, 2023
1 parent 1b4bd15 commit 8b1d729
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions blob/gcsblob/gcsblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import (
"google.golang.org/api/iterator"
"google.golang.org/api/option"


"gocloud.dev/blob"
"gocloud.dev/blob/driver"
"gocloud.dev/gcerrors"
Expand Down Expand Up @@ -160,14 +161,16 @@ func (o *lazyCredsOpener) OpenBucketURL(ctx context.Context, u *url.URL) (*blob.
var err error
creds, err = gcp.DefaultCredentials(ctx)
if err != nil {
o.err = err
return
fmt.Printf("Warning: unable to load GCP Default Credentials: %v", err)
// Use empty credentials, in case the user isn't going to actually use
// them; e.g., getting signed URLs with GoogleAccessID=-.
creds = &google.Credentials{}
}

// Populate default values from credentials files, where available.
opts.GoogleAccessID, opts.PrivateKey = readDefaultCredentials(creds.JSON)

// else, on GCE, at least get the instance's main service account.
// ... else, on GCE, at least get the instance's main service account.
if opts.GoogleAccessID == "" && metadata.OnGCE() {
mc := metadata.NewClient(nil)
opts.GoogleAccessID, _ = mc.Email("")
Expand Down

0 comments on commit 8b1d729

Please sign in to comment.