googleapis / googleapis/google-cloud-java

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

Ouverte
#12,600 1 commentaire 0 réactions 1 personne assignée Réclamée par @TimurSadykov Voir sur GitHub
type: feature request
Langage dominant
Java
Étoiles
2.1k
Forks
1.2k
Merge moyen
1 j 23 h
PR mergées (30 j)
154

Description

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.

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.