Browse Source

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>
pull/8026/merge
Peter Dodd 2 days ago
committed by GitHub
parent
commit
4d513a2b3d
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 20
      weed/remote_storage/gcs/gcs_storage_client.go

20
weed/remote_storage/gcs/gcs_storage_client.go

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

Loading…
Cancel
Save