Skip to content

Commit 6a0ef01

Browse files
committed
api: Add Application to Default Credentials naming and remove descriptions of incomplete integration features.
https://codereview.appspot.com/101640044/
1 parent 2a29924 commit 6a0ef01

File tree

3 files changed

+29
-31
lines changed

3 files changed

+29
-31
lines changed

google-api-client/src/main/java/com/google/api/client/googleapis/auth/oauth2/DefaultCredentialProvider.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@
4242
@Beta
4343
class DefaultCredentialProvider {
4444

45-
static final String CREDENTIAL_ENV_VAR = "GOOGLE_CREDENTIALS_DEFAULT";
45+
static final String CREDENTIAL_ENV_VAR = "GOOGLE_APPLICATION_CREDENTIALS";
4646

47-
static final String WELL_KNOWN_CREDENTIALS_FILE = "credentials_default.json";
47+
static final String WELL_KNOWN_CREDENTIALS_FILE = "application_default_credentials.json";
4848

4949
static final String CLOUDSDK_CONFIG_DIRECTORY = "gcloud";
5050

5151
static final String HELP_PERMALINK =
52-
"https://developers.google.com/accounts/docs/default-credentials";
52+
"https://developers.google.com/accounts/docs/application-default-credentials";
5353

5454
static final String APP_ENGINE_CREDENTIAL_CLASS =
5555
"com.google.api.client.googleapis.extensions.appengine.auth.oauth2"
@@ -64,12 +64,12 @@ class DefaultCredentialProvider {
6464

6565
/**
6666
* {@link Beta} <br/>
67-
* Returns a default credential for the application.
67+
* Returns the Application Default Credentials.
6868
*
69-
* <p>Returns the built-in service account's credential for the application if running on
70-
* Google App Engine or Google Compute Engine, or returns the credential pointed to by the
71-
* environment variable GOOGLE_CREDENTIALS_DEFAULT.
72-
* </p>
69+
* <p>Returns the Application Default Credentials which are credentials that identify and
70+
* authorize the whole application. This is the built-in service account if running on Google
71+
* Compute Engine or the credentials file from the path in the environment variable
72+
* GOOGLE_APPLICATION_CREDENTIALS.</p>
7373
*
7474
* @param transport the transport for Http calls.
7575
* @param jsonFactory the factory for Json parsing and formatting.
@@ -88,11 +88,9 @@ final GoogleCredential getDefaultCredential(HttpTransport transport, JsonFactory
8888
}
8989

9090
throw new IOException(String.format(
91-
"The Default Credentials are not available. They are available if running"
92-
+ " in Google App Engine or Google Compute Engine. They are also available if using"
93-
+ " the Google Cloud SDK and running 'gcloud auth login'. Otherwise, the environment"
94-
+ " variable %s must be defined pointing to a file defining the credentials."
95-
+ " See %s for details.",
91+
"The Application Default Credentials are not available. They are available if running"
92+
+ " in Google Compute Engine. Otherwise, the environment variable %s must be defined"
93+
+ " pointing to a file defining the credentials. See %s for more information.",
9694
CREDENTIAL_ENV_VAR,
9795
HELP_PERMALINK));
9896
}

google-api-client/src/main/java/com/google/api/client/googleapis/auth/oauth2/GoogleCredential.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,38 +176,38 @@ public class GoogleCredential extends Credential {
176176

177177
/**
178178
* {@link Beta} <br/>
179-
* Returns a default credential for the application.
179+
* Returns the Application Default Credentials.
180180
*
181-
* <p>Returns the built-in service account's credential for the application if running on
182-
* Google App Engine or Google Compute Engine, or returns the credential pointed to by the
183-
* environment variable GOOGLE_CREDENTIALS_DEFAULT.
184-
* </p>
181+
* <p>Returns the Application Default Credentials which are credentials that identify and
182+
* authorize the whole application. This is the built-in service account if running on Google
183+
* Compute Engine or the credentials file from the path in the environment variable
184+
* GOOGLE_APPLICATION_CREDENTIALS.</p>
185185
*
186186
* @return the credential instance.
187187
* @throws IOException if the credential cannot be created in the current environment.
188188
*/
189189
@Beta
190-
public static GoogleCredential getDefault() throws IOException {
191-
return getDefault(Utils.getDefaultTransport(), Utils.getDefaultJsonFactory());
190+
public static GoogleCredential getApplicationDefault() throws IOException {
191+
return getApplicationDefault(Utils.getDefaultTransport(), Utils.getDefaultJsonFactory());
192192
}
193193

194194
/**
195195
* {@link Beta} <br/>
196-
* Returns a default credential for the application.
196+
* Returns the Application Default Credentials.
197197
*
198-
* <p>Returns the built-in service account's credential for the application if running on
199-
* Google App Engine or Google Compute Engine, or returns the credential pointed to by the
200-
* environment variable GOOGLE_CREDENTIALS_DEFAULT.
201-
* </p>
198+
* <p>Returns the Application Default Credentials which are credentials that identify and
199+
* authorize the whole application. This is the built-in service account if running on Google
200+
* Compute Engine or the credentials file from the path in the environment variable
201+
* GOOGLE_APPLICATION_CREDENTIALS.</p>
202202
*
203203
* @param transport the transport for Http calls.
204204
* @param jsonFactory the factory for Json parsing and formatting.
205205
* @return the credential instance.
206206
* @throws IOException if the credential cannot be created in the current environment.
207207
*/
208208
@Beta
209-
public static GoogleCredential getDefault(HttpTransport transport, JsonFactory jsonFactory)
210-
throws IOException {
209+
public static GoogleCredential getApplicationDefault(
210+
HttpTransport transport, JsonFactory jsonFactory) throws IOException {
211211
Preconditions.checkNotNull(transport);
212212
Preconditions.checkNotNull(jsonFactory);
213213
return defaultCredentialProvider.getDefaultCredential(transport, jsonFactory);

google-api-client/src/test/java/com/google/api/client/googleapis/auth/oauth2/GoogleCredentialTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,18 @@ public void testCreateScoped() throws Exception {
135135
scopedCredential.getServiceAccountPrivateKey());
136136
}
137137

138-
public void testGetDefaultNullTransportThrows() throws IOException {
138+
public void testGetApplicationDefaultNullTransportThrows() throws IOException {
139139
try {
140-
GoogleCredential.getDefault(null, JSON_FACTORY);
140+
GoogleCredential.getApplicationDefault(null, JSON_FACTORY);
141141
fail();
142142
} catch (NullPointerException expected) {
143143
}
144144
}
145145

146-
public void testGetDefaultNullJsonFactoryThrows() throws IOException {
146+
public void testGetApplicationDefaultNullJsonFactoryThrows() throws IOException {
147147
HttpTransport transport = new MockHttpTransport();
148148
try {
149-
GoogleCredential.getDefault(transport, null);
149+
GoogleCredential.getApplicationDefault(transport, null);
150150
fail();
151151
} catch (NullPointerException expected) {
152152
}

0 commit comments

Comments
 (0)