Skip to content

Commit a0f3ea1

Browse files
authored
chore: Use Java Auth's GDU constant (#2340)
1 parent 355f80a commit a0f3ea1

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

gax-java/gax/src/main/java/com/google/api/gax/rpc/EndpointContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import com.google.api.core.InternalApi;
3333
import com.google.api.gax.rpc.mtls.MtlsProvider;
34+
import com.google.auth.Credentials;
3435
import com.google.auto.value.AutoValue;
3536
import com.google.common.annotations.VisibleForTesting;
3637
import com.google.common.base.Strings;
@@ -41,7 +42,6 @@
4142
@InternalApi
4243
@AutoValue
4344
public abstract class EndpointContext {
44-
static final String GOOGLE_DEFAULT_UNIVERSE = "googleapis.com";
4545

4646
/**
4747
* ServiceName is host URI for Google Cloud Services. It follows the format of
@@ -162,14 +162,14 @@ private String determineUniverseDomain() {
162162
throw new IllegalArgumentException(
163163
"Universe domain configuration is incompatible with GDC-H");
164164
}
165-
return GOOGLE_DEFAULT_UNIVERSE;
165+
return Credentials.GOOGLE_DEFAULT_UNIVERSE;
166166
}
167167
// Check for "" (empty string)
168168
if (universeDomain() != null && universeDomain().isEmpty()) {
169169
throw new IllegalArgumentException("The universe domain value cannot be empty.");
170170
}
171171
// Override with user set universe domain if provided
172-
return universeDomain() != null ? universeDomain() : GOOGLE_DEFAULT_UNIVERSE;
172+
return universeDomain() != null ? universeDomain() : Credentials.GOOGLE_DEFAULT_UNIVERSE;
173173
}
174174

175175
/** Determines the fully resolved endpoint and universe domain values */
@@ -200,7 +200,7 @@ private String determineEndpoint() throws IOException {
200200

201201
// Check if mTLS is configured with non-GDU
202202
if (endpoint.equals(mtlsEndpoint())
203-
&& !resolvedUniverseDomain().equals(GOOGLE_DEFAULT_UNIVERSE)) {
203+
&& !resolvedUniverseDomain().equals(Credentials.GOOGLE_DEFAULT_UNIVERSE)) {
204204
throw new IllegalArgumentException(
205205
"mTLS is not supported in any universe other than googleapis.com");
206206
}

gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import com.google.api.gax.rpc.mtls.MtlsProvider;
3535
import com.google.api.gax.rpc.testing.FakeMtlsProvider;
36+
import com.google.auth.Credentials;
3637
import com.google.common.truth.Truth;
3738
import java.io.IOException;
3839
import org.junit.Before;
@@ -51,7 +52,7 @@ public void setUp() throws IOException {
5152
defaultEndpointContextBuilder =
5253
EndpointContext.newBuilder()
5354
.setServiceName("test")
54-
.setUniverseDomain(EndpointContext.GOOGLE_DEFAULT_UNIVERSE)
55+
.setUniverseDomain(Credentials.GOOGLE_DEFAULT_UNIVERSE)
5556
.setClientSettingsEndpoint(DEFAULT_ENDPOINT)
5657
.setMtlsEndpoint(DEFAULT_MTLS_ENDPOINT);
5758
}
@@ -177,7 +178,7 @@ public void endpointContextBuild_noUniverseDomain_usesClientSettingsEndpoint()
177178
defaultEndpointContextBuilder.setClientSettingsEndpoint(DEFAULT_ENDPOINT).build();
178179
Truth.assertThat(endpointContext.resolvedEndpoint()).isEqualTo(DEFAULT_ENDPOINT);
179180
Truth.assertThat(endpointContext.resolvedUniverseDomain())
180-
.isEqualTo(EndpointContext.GOOGLE_DEFAULT_UNIVERSE);
181+
.isEqualTo(Credentials.GOOGLE_DEFAULT_UNIVERSE);
181182
}
182183

183184
@Test
@@ -192,7 +193,7 @@ public void endpointContextBuild_noUniverseDomain_usesTransportChannelProviderEn
192193
Truth.assertThat(endpointContext.resolvedEndpoint())
193194
.isEqualTo(transportChannelProviderEndpoint);
194195
Truth.assertThat(endpointContext.resolvedUniverseDomain())
195-
.isEqualTo(EndpointContext.GOOGLE_DEFAULT_UNIVERSE);
196+
.isEqualTo(Credentials.GOOGLE_DEFAULT_UNIVERSE);
196197
}
197198

198199
@Test
@@ -207,7 +208,7 @@ public void endpointContextBuild_noUniverseDomain_overrideUsesTransportChannelPr
207208
Truth.assertThat(endpointContext.resolvedEndpoint())
208209
.isEqualTo(transportChannelProviderEndpoint);
209210
Truth.assertThat(endpointContext.resolvedUniverseDomain())
210-
.isEqualTo(EndpointContext.GOOGLE_DEFAULT_UNIVERSE);
211+
.isEqualTo(Credentials.GOOGLE_DEFAULT_UNIVERSE);
211212
}
212213

213214
@Test
@@ -225,7 +226,7 @@ public void endpointContextBuild_GDUUniverseDomain() throws IOException {
225226
EndpointContext endpointContext = defaultEndpointContextBuilder.build();
226227
Truth.assertThat(endpointContext.resolvedEndpoint()).isEqualTo(DEFAULT_ENDPOINT);
227228
Truth.assertThat(endpointContext.resolvedUniverseDomain())
228-
.isEqualTo(EndpointContext.GOOGLE_DEFAULT_UNIVERSE);
229+
.isEqualTo(Credentials.GOOGLE_DEFAULT_UNIVERSE);
229230
}
230231

231232
@Test
@@ -248,7 +249,7 @@ public void endpointContextBuild_noUniverseDomain_noEndpoints() throws IOExcepti
248249
.build();
249250
Truth.assertThat(endpointContext.resolvedEndpoint()).isEqualTo(expectedEndpoint);
250251
Truth.assertThat(endpointContext.resolvedUniverseDomain())
251-
.isEqualTo(EndpointContext.GOOGLE_DEFAULT_UNIVERSE);
252+
.isEqualTo(Credentials.GOOGLE_DEFAULT_UNIVERSE);
252253
}
253254

254255
@Test
@@ -269,7 +270,7 @@ public void endpointContextBuild_mtlsConfigured_GDU() throws IOException {
269270
.build();
270271
Truth.assertThat(endpointContext.resolvedEndpoint()).isEqualTo(DEFAULT_MTLS_ENDPOINT);
271272
Truth.assertThat(endpointContext.resolvedUniverseDomain())
272-
.isEqualTo(EndpointContext.GOOGLE_DEFAULT_UNIVERSE);
273+
.isEqualTo(Credentials.GOOGLE_DEFAULT_UNIVERSE);
273274
}
274275

275276
@Test
@@ -315,7 +316,7 @@ public void endpointContextBuild_gdchFlow_noUniverseDomain_noCustomEndpoint() th
315316
.build();
316317
Truth.assertThat(endpointContext.resolvedEndpoint()).isEqualTo(DEFAULT_ENDPOINT);
317318
Truth.assertThat(endpointContext.resolvedUniverseDomain())
318-
.isEqualTo(EndpointContext.GOOGLE_DEFAULT_UNIVERSE);
319+
.isEqualTo(Credentials.GOOGLE_DEFAULT_UNIVERSE);
319320
}
320321

321322
@Test
@@ -329,6 +330,6 @@ public void endpointContextBuild_gdchFlow_noUniverseDomain_customEndpoint() thro
329330
.build();
330331
Truth.assertThat(endpointContext.resolvedEndpoint()).isEqualTo(clientSettingsEndpoint);
331332
Truth.assertThat(endpointContext.resolvedUniverseDomain())
332-
.isEqualTo(EndpointContext.GOOGLE_DEFAULT_UNIVERSE);
333+
.isEqualTo(Credentials.GOOGLE_DEFAULT_UNIVERSE);
333334
}
334335
}

0 commit comments

Comments
 (0)