Skip to content
Permalink
Browse files
fix: Settings objects should not try to read quotaProjectId from cred…
…entials (#1162)

* fix: defer credential loading until you ask for quotaProjectId

* fix: StubSettings doesn't need to know quotaProjectId loading order

* test: remove test scenario we don't care about
  • Loading branch information
chingor13 committed Aug 7, 2020
1 parent cbfd0a3 commit 1b09bcff1ddfaed8cfa58b92c787f8fc9b08abef
Showing with 0 additions and 11 deletions.
  1. +0 −9 gax/src/main/java/com/google/api/gax/rpc/StubSettings.java
  2. +0 −2 gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java
@@ -41,7 +41,6 @@
import com.google.api.gax.core.NoCredentialsProvider;
import com.google.api.gax.tracing.ApiTracerFactory;
import com.google.api.gax.tracing.NoopApiTracerFactory;
import com.google.auth.Credentials;
import com.google.auth.oauth2.QuotaProjectIdProvider;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
@@ -266,14 +265,6 @@ public B setExecutorProvider(ExecutorProvider executorProvider) {
/** Sets the CredentialsProvider to use for getting the credentials to make calls with. */
public B setCredentialsProvider(CredentialsProvider credentialsProvider) {
this.credentialsProvider = Preconditions.checkNotNull(credentialsProvider);
try {
Credentials credentials = credentialsProvider.getCredentials();
if (this.quotaProjectId == null && credentials instanceof QuotaProjectIdProvider) {
this.quotaProjectId = ((QuotaProjectIdProvider) credentials).getQuotaProjectId();
}
} catch (IOException e) {
System.out.println("fail to fetch credentials");
}
return self();
}

@@ -420,8 +420,6 @@ public Credentials getCredentials() throws IOException {
.isEqualTo(QUOTA_PROJECT_ID_FROM_INTERNAL_HEADER_VALUE);
Truth.assertThat(builder_setQuotaFromInternalHeadersAndBuilders.getQuotaProjectId())
.isEqualTo(QUOTA_PROJECT_ID_FROM_BUILDERS);
Truth.assertThat(builder_setQuotaFromCredentialsProvider.getQuotaProjectId())
.isEqualTo(QUOTA_PROJECT_ID_FROM_CREDENTIALS_VALUE);
Truth.assertThat(builder_setQuotaFromCredentialsProviderAndBuilder.getQuotaProjectId())
.isEqualTo(QUOTA_PROJECT_ID_FROM_BUILDERS);
Truth.assertThat(builder_setQuotaFromAllSources.getQuotaProjectId())

0 comments on commit 1b09bcf

Please sign in to comment.