diff --git a/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java b/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java index fd7260534..2e0c321d1 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java @@ -657,6 +657,12 @@ public Builder setUniverseDomain(String universeDomain) { return this; } + @CanIgnoreReturnValue + public Builder setQuotaProjectId(String quotaProjectId) { + super.quotaProjectId = quotaProjectId; + return this; + } + public HttpTransportFactory getHttpTransportFactory() { return transportFactory; } diff --git a/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java b/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java index a49cf9b2f..54d708103 100644 --- a/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java @@ -481,7 +481,9 @@ protected Builder() {} protected Builder(GoogleCredentials credentials) { super(credentials); this.quotaProjectId = credentials.quotaProjectId; - this.universeDomain = credentials.universeDomain; + if (credentials.isExplicitUniverseDomain) { + this.universeDomain = credentials.universeDomain; + } } protected Builder(GoogleCredentials.Builder builder) { diff --git a/oauth2_http/javatests/com/google/auth/oauth2/ComputeEngineCredentialsTest.java b/oauth2_http/javatests/com/google/auth/oauth2/ComputeEngineCredentialsTest.java index 80268bb1e..dc307d518 100644 --- a/oauth2_http/javatests/com/google/auth/oauth2/ComputeEngineCredentialsTest.java +++ b/oauth2_http/javatests/com/google/auth/oauth2/ComputeEngineCredentialsTest.java @@ -60,6 +60,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.Queue; @@ -361,6 +362,19 @@ public void hashCode_equals() throws IOException { assertEquals(credentials.hashCode(), otherCredentials.hashCode()); } + @Test + public void toBuilder() { + ComputeEngineCredentials credentials = + ComputeEngineCredentials.newBuilder() + .setHttpTransportFactory(new MockMetadataServerTransportFactory()) + .setQuotaProjectId("quota-project") + .build(); + + ComputeEngineCredentials secondCredentials = credentials.toBuilder().build(); + + assertEquals(credentials, secondCredentials); + } + @Test public void serialize() throws IOException, ClassNotFoundException { MockMetadataServerTransportFactory serverTransportFactory =