diff --git a/oss/gcsblob/gcs.go b/oss/gcsblob/gcs.go index 43a8eb4..08e7be6 100644 --- a/oss/gcsblob/gcs.go +++ b/oss/gcsblob/gcs.go @@ -29,13 +29,22 @@ func NewGoogleCloudStorage(args oss.OSSArgs) (oss.OSS, error) { ctx := context.Background() bucket := args.GoogleCloudStorage.Bucket credentialsB64 := args.GoogleCloudStorage.CredentialsB64 - credentials, err := base64.StdEncoding.DecodeString(credentialsB64) - if err != nil { - return nil, oss.ErrProviderInit.WithError(err).WithDetail("credentials must be a base64 encoded string") - } - client, err := storage.NewClient(ctx, option.WithCredentialsJSON(credentials)) - if err != nil { - return nil, oss.ErrProviderInit.WithError(err) + + var client *storage.Client + if credentialsB64 == "" { + client, err = storage.NewClient(ctx) + if err != nil { + return nil, oss.ErrProviderInit.WithError(err).WithDetail("failed to initialize GCS client with ADC") + } + } else { + credentials, err := base64.StdEncoding.DecodeString(credentialsB64) + if err != nil { + return nil, oss.ErrProviderInit.WithError(err).WithDetail("credentials must be a base64 encoded string") + } + client, err = storage.NewClient(ctx, option.WithCredentialsJSON(credentials)) + if err != nil { + return nil, oss.ErrProviderInit.WithError(err) + } } return &GoogleCloudStorage{ bucket: bucket, diff --git a/oss/oss.go b/oss/oss.go index c7aaa80..376cd20 100644 --- a/oss/oss.go +++ b/oss/oss.go @@ -143,8 +143,8 @@ type GoogleCloudStorage struct { } func (g *GoogleCloudStorage) Validate() error { - if g.Bucket == "" || g.CredentialsB64 == "" { - msg := fmt.Sprintf("bucket and credentials cannot be empty.") + if g.Bucket == "" { + msg := fmt.Sprintf("bucket cannot be empty.") return ErrArgumentInvalid.WithDetail(msg) } return nil