googleapis / googleapis/google-cloud-java
[google-auth-library-java] Add support for reading GOOGLE_APPLICATION_CREDENTIALS as a property
- 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
Đánh giá
Issue này chưa được đánh giá.