From 8b1d729667171fc38967a5db5a7308981f48ce39 Mon Sep 17 00:00:00 2001 From: Robert van Gent Date: Mon, 21 Aug 2023 20:55:17 +0000 Subject: [PATCH] blob/gcsblob: Don't hard-fail if no DefaultCredentials are found --- blob/gcsblob/gcsblob.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/blob/gcsblob/gcsblob.go b/blob/gcsblob/gcsblob.go index 795335a732..00be9086e1 100644 --- a/blob/gcsblob/gcsblob.go +++ b/blob/gcsblob/gcsblob.go @@ -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" @@ -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("")