Skip to content

Commit

Permalink
refactor: support ADC
Browse files Browse the repository at this point in the history
  • Loading branch information
renlulu committed Sep 10, 2024
1 parent f4309b9 commit 2209476
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion das/google_cloud_storage_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,15 @@ type GoogleCloudStorageService struct {
}

func NewGoogleCloudStorageService(config GoogleCloudStorageServiceConfig) (StorageService, error) {
client, err := googlestorage.NewClient(context.Background(), option.WithCredentialsJSON([]byte(config.AccessToken)))
var client *googlestorage.Client
var err error
// Note that if the credentials are not specified, the client library will find credentials using ADC(Application Default Credentials)
// https://cloud.google.com/docs/authentication/provide-credentials-adc.
if config.AccessToken == "" {
client, err = googlestorage.NewClient(context.Background())
} else {
client, err = googlestorage.NewClient(context.Background(), option.WithCredentialsJSON([]byte(config.AccessToken)))
}
if err != nil {
return nil, fmt.Errorf("error creating Google Cloud Storage client: %v", err)
}
Expand Down

0 comments on commit 2209476

Please sign in to comment.