Skip to content

Commit e2de93b

Browse files
authored
fix: Verify Universe Domain's DirectPath Compatibility after Endpoint Resolution (#2412)
* fix: Verify Universe Domain's DirectPath Compatibility after Endpoint Resolution * chore: Address PR comments * chore: Remove DirectPath logging statement
1 parent 909bdf9 commit e2de93b

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,6 @@ private void logDirectPathMisconfig() {
295295
Level.WARNING,
296296
"DirectPath is misconfigured. DirectPath is only available in a GCE environment.");
297297
}
298-
if (!canUseDirectPathWithUniverseDomain()) {
299-
LOG.log(
300-
Level.WARNING, "DirectPath will only work in the the googleapis.com Universe Domain");
301-
}
302298
}
303299
}
304300
}
@@ -334,8 +330,10 @@ static boolean isOnComputeEngine() {
334330
return false;
335331
}
336332

337-
private boolean canUseDirectPathWithUniverseDomain() {
338-
return endpoint.contains("googleapis.com");
333+
// Universe Domain configuration is currently only supported in the GDU
334+
@VisibleForTesting
335+
boolean canUseDirectPathWithUniverseDomain() {
336+
return endpoint.contains(Credentials.GOOGLE_DEFAULT_UNIVERSE);
339337
}
340338

341339
@VisibleForTesting

gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java

+22-16
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,28 @@ public void testDirectPathDisallowNullCredentials() throws IOException {
292292
assertThat(provider.isCredentialDirectPathCompatible()).isFalse();
293293
}
294294

295+
@Test
296+
public void testDirectPathWithGDUEndpoint() {
297+
InstantiatingGrpcChannelProvider provider =
298+
InstantiatingGrpcChannelProvider.newBuilder()
299+
.setAttemptDirectPath(true)
300+
.setAttemptDirectPathXds()
301+
.setEndpoint("test.googleapis.com:443")
302+
.build();
303+
assertThat(provider.canUseDirectPathWithUniverseDomain()).isTrue();
304+
}
305+
306+
@Test
307+
public void testDirectPathWithNonGDUEndpoint() {
308+
InstantiatingGrpcChannelProvider provider =
309+
InstantiatingGrpcChannelProvider.newBuilder()
310+
.setAttemptDirectPath(true)
311+
.setAttemptDirectPathXds()
312+
.setEndpoint("test.random.com:443")
313+
.build();
314+
assertThat(provider.canUseDirectPathWithUniverseDomain()).isFalse();
315+
}
316+
295317
@Test
296318
public void testDirectPathXdsEnabled() throws IOException {
297319
InstantiatingGrpcChannelProvider provider =
@@ -565,22 +587,6 @@ public void testLogDirectPathMisconfigNotOnGCE() {
565587
InstantiatingGrpcChannelProvider.LOG.removeHandler(logHandler);
566588
}
567589

568-
@Test
569-
public void testLogDirectPathMisconfigNotInGDU() {
570-
FakeLogHandler logHandler = new FakeLogHandler();
571-
InstantiatingGrpcChannelProvider.LOG.addHandler(logHandler);
572-
InstantiatingGrpcChannelProvider provider =
573-
InstantiatingGrpcChannelProvider.newBuilder()
574-
.setAttemptDirectPathXds()
575-
.setAttemptDirectPath(true)
576-
.setAllowNonDefaultServiceAccount(true)
577-
.setEndpoint("test.random.endpoint.com:443")
578-
.build();
579-
assertThat(logHandler.getAllMessages())
580-
.contains("DirectPath will only work in the the googleapis.com Universe Domain");
581-
InstantiatingGrpcChannelProvider.LOG.removeHandler(logHandler);
582-
}
583-
584590
private static class FakeLogHandler extends Handler {
585591
List<LogRecord> records = new ArrayList<>();
586592

0 commit comments

Comments
 (0)