googleapis / googleapis/google-cloud-java

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

未关闭
#12,600 1 条评论 0 个 reaction 已指派 1 人 已被 @TimurSadykov 认领 在 GitHub 查看
type: feature request
主要语言
Java
星标
2.1k
派生
1.2k
平均合并
1 天 23 小时
30 天内合并 PR
154

描述

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.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。