feat(gcs): add application default credentials fallback support (#8161)

* feat(gcs): add application default credentials fallback support

* refactor

* Update weed/remote_storage/gcs/gcs_storage_client.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Chris Lu <chris.lu@gmail.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Peter Dodd
2026-01-29 17:57:49 +00:00
committed by GitHub
parent c52d3d1229
commit 4d513a2b3d

View File

@@ -38,26 +38,26 @@ func (s gcsRemoteStorageMaker) Make(conf *remote_pb.RemoteConf) (remote_storage.
googleApplicationCredentials := conf.GcsGoogleApplicationCredentials googleApplicationCredentials := conf.GcsGoogleApplicationCredentials
if googleApplicationCredentials == "" { if googleApplicationCredentials == "" {
found := false if creds, found := os.LookupEnv("GOOGLE_APPLICATION_CREDENTIALS"); found {
googleApplicationCredentials, found = os.LookupEnv("GOOGLE_APPLICATION_CREDENTIALS") googleApplicationCredentials = creds
if !found { } else {
return nil, fmt.Errorf("need to specific GOOGLE_APPLICATION_CREDENTIALS env variable") glog.Warningf("no GOOGLE_APPLICATION_CREDENTIALS env variable found, falling back to Application Default Credentials")
} }
} }
projectID := conf.GcsProjectId projectID := conf.GcsProjectId
if projectID == "" { if projectID == "" {
found := false if pid, found := os.LookupEnv("GOOGLE_CLOUD_PROJECT"); found {
projectID, found = os.LookupEnv("GOOGLE_CLOUD_PROJECT") projectID = pid
if !found { } else {
glog.Warningf("need to specific GOOGLE_CLOUD_PROJECT env variable") glog.Warningf("need to specify GOOGLE_CLOUD_PROJECT env variable")
} }
} }
googleApplicationCredentials = util.ResolvePath(googleApplicationCredentials)
var clientOpts []option.ClientOption var clientOpts []option.ClientOption
if googleApplicationCredentials != "" { if googleApplicationCredentials != "" {
googleApplicationCredentials = util.ResolvePath(googleApplicationCredentials)
var data []byte var data []byte
var err error var err error
if strings.HasPrefix(googleApplicationCredentials, "{") { if strings.HasPrefix(googleApplicationCredentials, "{") {