Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions oss/gcsblob/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions oss/oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down