From 62841e782d6aee8c920d9165019217dea396cfe0 Mon Sep 17 00:00:00 2001 From: Robert van Gent Date: Mon, 21 Aug 2023 14:30:50 -0700 Subject: [PATCH] blob/gcsblob: Don't hard-fail if no DefaultCredentials are found (#3306) --- blob/gcsblob/gcsblob.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/blob/gcsblob/gcsblob.go b/blob/gcsblob/gcsblob.go index 795335a732..f8e61827c1 100644 --- a/blob/gcsblob/gcsblob.go +++ b/blob/gcsblob/gcsblob.go @@ -160,14 +160,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("")