googleapis / googleapis/google-cloud-java

[google-auth-library-java] Add support for reading GOOGLE_APPLICATION_CREDENTIALS as a property

Đang mở
#12,600 1 bình luận 0 reaction 1 người được giao Được @TimurSadykov nhận Xem trên GitHub
type: feature request
Ngôn ngữ chính
Java
Star
2.1k
Fork
1.2k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
154

Mô tả

In Java, we can have "system properties" as well as "environment variables" that keep our map between keys and string values.
We access system properties using the method **System.getProperty** while to access the environment variables we use **System.getenv**.
Different systems may use different approaches to pass configurations. For instance, Amazon Elastibewnsatck passes our variables to **Tomcat** as properties that will have to be accessed using System.getProperty (see link [here](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environments-cfg-softwaresettings.html)).

Currently, **DefaultCredentialsProvider** reads GOOGLE_APPLICATION_CREDENTIALS only using System.getenv (apart from using getWellKnownCredentialsFile).
It would be nice if it could also try to read the credentials from properties.

I was unable to send a pull request (permission denied), so here goes the draft code I think would easily fix the issue:
New method for DefaultCredentialsProvider:
```
String getEnvOrProperty(String name) {
String envValue = getEnv(name);
if (envValue == null || envValue.length() == 0) {
envValue = getProperty(name, "");
}
return envValue;
}
```
Change line 135 of DefaultCredentialsProvider#getDefaultCredentialsUnsynchronized from:
`String credentialsPath = getEnv(CREDENTIAL_ENV_VAR);`
to:
`String credentialsPath = getEnvOrProperty(CREDENTIAL_ENV_VAR);`

Another approach would be to modify **GoogleAuthUtils#getWellKnownCredentialsFile** to add a new clause based on getProperty and the default CREDENTIAL_ENV_VAR.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.