Skip to content

Commit 12addfe

Browse files
zhihanneozwu
authored andcommitted
Automated g4 rollback of changelist 121305912.
*** Reason for rollback *** We have our json key files checked in keystore and it takes a while to update them. None of them have project_ids. The test environment started crashing this morning. See b/28550569 Tested: 1) testing/helium/devicemaster/scripts/initialize_dev_machine.sh --inhouse testing/helium/devicemaster/scripts/run_local.sh --device_type=PHYSICAL --inhouse 2) testing/helium/devicemaster/scripts/initialize_dev_machine.sh testing/helium/devicemaster/scripts/run_local.sh --device_type=PHYSICAL *** Original change description *** Allow ProjectId to be read from Service Account Configuration. For Firebase, we are using the Service Account configuration file parsed by GoogleCredential to set many of the values needed. We wish to pull the ProjectId from the GoogleCredential, rather than requiring that developers supply it separately. *** ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=121379203
1 parent a0c42a4 commit 12addfe

File tree

2 files changed

+2
-80
lines changed

2 files changed

+2
-80
lines changed

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

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,6 @@ public static GoogleCredential fromStream(InputStream credentialStream, HttpTran
271271
*/
272272
private String serviceAccountId;
273273

274-
/**
275-
* Service account Project ID or {@code null} if not using the service account flow.
276-
*/
277-
private String serviceAccountProjectId;
278-
279274
/**
280275
* Collection of OAuth scopes to use with the service account flow or {@code null} if not
281276
* using the service account flow.
@@ -323,7 +318,6 @@ protected GoogleCredential(Builder builder) {
323318
&& builder.serviceAccountScopes == null && builder.serviceAccountUser == null);
324319
} else {
325320
serviceAccountId = Preconditions.checkNotNull(builder.serviceAccountId);
326-
serviceAccountProjectId = builder.serviceAccountProjectId;
327321
serviceAccountScopes = Collections.unmodifiableCollection(builder.serviceAccountScopes);
328322
serviceAccountPrivateKey = builder.serviceAccountPrivateKey;
329323
serviceAccountPrivateKeyId = builder.serviceAccountPrivateKeyId;
@@ -403,13 +397,6 @@ public final String getServiceAccountId() {
403397
return serviceAccountId;
404398
}
405399

406-
/**
407-
* Returns the service account Project ID or {@code null} if not using the service account flow.
408-
*/
409-
public final String getServiceAccountProjectId() {
410-
return serviceAccountProjectId;
411-
}
412-
413400
/**
414401
* Returns a collection of OAuth scopes to use with the service account flow or {@code null}
415402
* if not using the service account flow.
@@ -513,9 +500,6 @@ public static class Builder extends Credential.Builder {
513500
/** Id of the private key to use with the service account flow or {@code null} for none. */
514501
String serviceAccountPrivateKeyId;
515502

516-
/** Project Id associated with the Service Account */
517-
String serviceAccountProjectId;
518-
519503
/**
520504
* Email address of the user the application is trying to impersonate in the service account
521505
* flow or {@code null} for none.
@@ -598,26 +582,6 @@ public Builder setServiceAccountId(String serviceAccountId) {
598582
return this;
599583
}
600584

601-
/**
602-
* Returns the service account Project ID or {@code null} for none.
603-
*/
604-
public final String getServiceAccountProjectId() {
605-
return serviceAccountProjectId;
606-
}
607-
608-
/**
609-
* Sets the service account Project ID or {@code null} for none.
610-
*
611-
* <p>
612-
* Overriding is only supported for the purpose of calling the super implementation and changing
613-
* the return type, but nothing else.
614-
* </p>
615-
*/
616-
public Builder setServiceAccountProjectId(String serviceAccountProjectId) {
617-
this.serviceAccountProjectId = serviceAccountProjectId;
618-
return this;
619-
}
620-
621585
/**
622586
* Returns a collection of OAuth scopes to use with the service account flow or {@code null}
623587
* for none.
@@ -813,15 +777,12 @@ private static GoogleCredential fromStreamUser(GenericJson fileContents, HttpTra
813777
private static GoogleCredential fromStreamServiceAccount(GenericJson fileContents,
814778
HttpTransport transport, JsonFactory jsonFactory) throws IOException {
815779
String clientId = (String) fileContents.get("client_id");
816-
String projectId = (String) fileContents.get("project_id");
817780
String clientEmail = (String) fileContents.get("client_email");
818781
String privateKeyPem = (String) fileContents.get("private_key");
819782
String privateKeyId = (String) fileContents.get("private_key_id");
820-
if (clientId == null || projectId == null || clientEmail == null || privateKeyPem == null
821-
|| privateKeyId == null) {
783+
if (clientId == null || clientEmail == null || privateKeyPem == null || privateKeyId == null) {
822784
throw new IOException("Error reading service account credential from stream, "
823-
+ "expecting 'client_id', 'project_id', 'client_email', 'private_key' and "
824-
+ "'private_key_id'.");
785+
+ "expecting 'client_id', 'client_email', 'private_key' and 'private_key_id'.");
825786
}
826787

827788
PrivateKey privateKey = privateKeyFromPkcs8(privateKeyPem);

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

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ public void testFromStreamServiceAccount() throws IOException {
186186
"36680232662-vrd7ji19qe3nelgchd0ah2csanun6bnr.apps.googleusercontent.com";
187187
final String serviceAccountEmail =
188188
"36680232662-vrd7ji19qgchd0ah2csanun6bnr@developer.gserviceaccount.com";
189-
final String projectId = "36680232662-vrd7ji19qe3nelgchd0ah2csanun6bnr";
190189

191190
MockTokenServerTransport transport = new MockTokenServerTransport();
192191
transport.addServiceAccount(serviceAccountEmail, accessToken);
@@ -198,7 +197,6 @@ public void testFromStreamServiceAccount() throws IOException {
198197
serviceAccountContents.put("client_email", serviceAccountEmail);
199198
serviceAccountContents.put("private_key", SA_KEY_TEXT);
200199
serviceAccountContents.put("private_key_id", SA_KEY_ID);
201-
serviceAccountContents.put("project_id", projectId);
202200
serviceAccountContents.put("type", GoogleCredential.SERVICE_ACCOUNT_FILE_TYPE);
203201
String json = serviceAccountContents.toPrettyString();
204202
InputStream serviceAccountStream = new ByteArrayInputStream(json.getBytes());
@@ -218,7 +216,6 @@ public void testFromStreamServiceAccountAlternateTokenUri() throws IOException {
218216
"36680232662-vrd7ji19qe3nelgchd0ah2csanun6bnr.apps.googleusercontent.com";
219217
final String serviceAccountEmail =
220218
"36680232662-vrd7ji19qgchd0ah2csanun6bnr@developer.gserviceaccount.com";
221-
final String projectId = "36680232662-vrd7ji19qe3nelgchd0ah2csanun6bnr";
222219

223220
final String tokenServerUrl = "http://another.auth.com/token";
224221
MockTokenServerTransport transport = new MockTokenServerTransport(tokenServerUrl);
@@ -231,7 +228,6 @@ public void testFromStreamServiceAccountAlternateTokenUri() throws IOException {
231228
serviceAccountContents.put("client_email", serviceAccountEmail);
232229
serviceAccountContents.put("private_key", SA_KEY_TEXT);
233230
serviceAccountContents.put("private_key_id", SA_KEY_ID);
234-
serviceAccountContents.put("project_id", projectId);
235231
serviceAccountContents.put("type", GoogleCredential.SERVICE_ACCOUNT_FILE_TYPE);
236232
serviceAccountContents.put("token_uri", tokenServerUrl);
237233
String json = serviceAccountContents.toPrettyString();
@@ -251,7 +247,6 @@ public void testFromStreamServiceAccountAlternateTokenUri() throws IOException {
251247
public void testFromStreamServiceAccountMissingClientIdThrows() throws IOException {
252248
final String serviceAccountEmail =
253249
"36680232662-vrd7ji19qgchd0ah2csanun6bnr@developer.gserviceaccount.com";
254-
final String projectId = "36680232662-vrd7ji19qe3nelgchd0ah2csanun6bnr";
255250

256251
MockHttpTransport transport = new MockTokenServerTransport();
257252

@@ -261,7 +256,6 @@ public void testFromStreamServiceAccountMissingClientIdThrows() throws IOExcepti
261256
serviceAccountContents.put("client_email", serviceAccountEmail);
262257
serviceAccountContents.put("private_key", SA_KEY_TEXT);
263258
serviceAccountContents.put("private_key_id", SA_KEY_ID);
264-
serviceAccountContents.put("project_id", projectId);
265259
serviceAccountContents.put("type", GoogleCredential.SERVICE_ACCOUNT_FILE_TYPE);
266260
String json = serviceAccountContents.toPrettyString();
267261
InputStream serviceAccountStream = new ByteArrayInputStream(json.getBytes());
@@ -277,7 +271,6 @@ public void testFromStreamServiceAccountMissingClientIdThrows() throws IOExcepti
277271
public void testFromStreamServiceAccountMissingClientEmailThrows() throws IOException {
278272
final String serviceAccountId =
279273
"36680232662-vrd7ji19qe3nelgchd0ah2csanun6bnr.apps.googleusercontent.com";
280-
final String projectId = "36680232662-vrd7ji19qe3nelgchd0ah2csanun6bnr";
281274

282275
MockHttpTransport transport = new MockTokenServerTransport();
283276

@@ -287,7 +280,6 @@ public void testFromStreamServiceAccountMissingClientEmailThrows() throws IOExce
287280
serviceAccountContents.put("client_id", serviceAccountId);
288281
serviceAccountContents.put("private_key", SA_KEY_TEXT);
289282
serviceAccountContents.put("private_key_id", SA_KEY_ID);
290-
serviceAccountContents.put("project_id", projectId);
291283
serviceAccountContents.put("type", GoogleCredential.SERVICE_ACCOUNT_FILE_TYPE);
292284
String json = serviceAccountContents.toPrettyString();
293285
InputStream serviceAccountStream = new ByteArrayInputStream(json.getBytes());
@@ -305,7 +297,6 @@ public void testFromStreamServiceAccountMissingPrivateKeyThrows() throws IOExcep
305297
"36680232662-vrd7ji19qe3nelgchd0ah2csanun6bnr.apps.googleusercontent.com";
306298
final String serviceAccountEmail =
307299
"36680232662-vrd7ji19qgchd0ah2csanun6bnr@developer.gserviceaccount.com";
308-
final String projectId = "36680232662-vrd7ji19qe3nelgchd0ah2csanun6bnr";
309300

310301
MockHttpTransport transport = new MockTokenServerTransport();
311302

@@ -315,7 +306,6 @@ public void testFromStreamServiceAccountMissingPrivateKeyThrows() throws IOExcep
315306
serviceAccountContents.put("client_id", serviceAccountId);
316307
serviceAccountContents.put("client_email", serviceAccountEmail);
317308
serviceAccountContents.put("private_key_id", SA_KEY_ID);
318-
serviceAccountContents.put("project_id", projectId);
319309
serviceAccountContents.put("type", GoogleCredential.SERVICE_ACCOUNT_FILE_TYPE);
320310
String json = serviceAccountContents.toPrettyString();
321311
InputStream serviceAccountStream = new ByteArrayInputStream(json.getBytes());
@@ -333,7 +323,6 @@ public void testFromStreamServiceAccountMissingPrivateKeyIdThrows() throws IOExc
333323
"36680232662-vrd7ji19qe3nelgchd0ah2csanun6bnr.apps.googleusercontent.com";
334324
final String serviceAccountEmail =
335325
"36680232662-vrd7ji19qgchd0ah2csanun6bnr@developer.gserviceaccount.com";
336-
final String projectId = "36680232662-vrd7ji19qe3nelgchd0ah2csanun6bnr";
337326

338327
MockHttpTransport transport = new MockTokenServerTransport();
339328

@@ -343,7 +332,6 @@ public void testFromStreamServiceAccountMissingPrivateKeyIdThrows() throws IOExc
343332
serviceAccountContents.put("client_id", serviceAccountId);
344333
serviceAccountContents.put("client_email", serviceAccountEmail);
345334
serviceAccountContents.put("private_key", SA_KEY_TEXT);
346-
serviceAccountContents.put("project_id", projectId);
347335
serviceAccountContents.put("type", GoogleCredential.SERVICE_ACCOUNT_FILE_TYPE);
348336
String json = serviceAccountContents.toPrettyString();
349337
InputStream serviceAccountStream = new ByteArrayInputStream(json.getBytes());
@@ -356,33 +344,6 @@ public void testFromStreamServiceAccountMissingPrivateKeyIdThrows() throws IOExc
356344
}
357345
}
358346

359-
public void testFromStreamServiceAccountMissingProjectIdThrows() throws IOException {
360-
final String serviceAccountId =
361-
"36680232662-vrd7ji19qe3nelgchd0ah2csanun6bnr.apps.googleusercontent.com";
362-
final String serviceAccountEmail =
363-
"36680232662-vrd7ji19qgchd0ah2csanun6bnr@developer.gserviceaccount.com";
364-
365-
MockHttpTransport transport = new MockTokenServerTransport();
366-
367-
// Write out user file
368-
GenericJson serviceAccountContents = new GenericJson();
369-
serviceAccountContents.setFactory(JSON_FACTORY);
370-
serviceAccountContents.put("client_id", serviceAccountId);
371-
serviceAccountContents.put("client_email", serviceAccountEmail);
372-
serviceAccountContents.put("private_key", SA_KEY_TEXT);
373-
serviceAccountContents.put("private_key_id", SA_KEY_ID);
374-
serviceAccountContents.put("type", GoogleCredential.SERVICE_ACCOUNT_FILE_TYPE);
375-
String json = serviceAccountContents.toPrettyString();
376-
InputStream serviceAccountStream = new ByteArrayInputStream(json.getBytes());
377-
378-
try {
379-
GoogleCredential.fromStream(serviceAccountStream, transport, JSON_FACTORY);
380-
fail();
381-
} catch (IOException expected) {
382-
assertTrue(expected.getMessage().contains("project_id"));
383-
}
384-
}
385-
386347
public void testFromStreamUser() throws IOException {
387348
final String accessToken = "1/MkSJoj1xsli0AccessToken_NKPY2";
388349
final String clientSecret = "jakuaL9YyieakhECKL2SwZcu";

0 commit comments

Comments
 (0)