From a9aee5f839841c96c3f118575fd0bcb35d83120d Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Sat, 7 Sep 2024 20:21:01 +0800 Subject: [PATCH] refactor: support ADC --- das/google_cloud_storage_service.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/das/google_cloud_storage_service.go b/das/google_cloud_storage_service.go index e66cc1cef88..e9104f13341 100644 --- a/das/google_cloud_storage_service.go +++ b/das/google_cloud_storage_service.go @@ -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) }