diff --git a/alts/src/main/java/io/grpc/alts/GoogleDefaultChannelBuilder.java b/alts/src/main/java/io/grpc/alts/GoogleDefaultChannelBuilder.java index 8a5ece69a2..0c66b99af1 100644 --- a/alts/src/main/java/io/grpc/alts/GoogleDefaultChannelBuilder.java +++ b/alts/src/main/java/io/grpc/alts/GoogleDefaultChannelBuilder.java @@ -60,6 +60,17 @@ public final class GoogleDefaultChannelBuilder delegate = NettyChannelBuilder.forTarget(target); InternalNettyChannelBuilder.setProtocolNegotiatorFactory( delegate(), new ProtocolNegotiatorFactory()); + @Nullable CallCredentials credentials = null; + Status status = Status.OK; + try { + credentials = MoreCallCredentials.from(GoogleCredentials.getApplicationDefault()); + } catch (IOException e) { + status = + Status.UNAUTHENTICATED + .withDescription("Failed to get Google default credentials") + .withCause(e); + } + delegate().intercept(new GoogleDefaultInterceptor(credentials, status)); } /** "Overrides" the static method in {@link ManagedChannelBuilder}. */ @@ -77,21 +88,6 @@ public final class GoogleDefaultChannelBuilder return delegate; } - @Override - public ManagedChannel build() { - @Nullable CallCredentials credentials = null; - Status status = Status.OK; - try { - credentials = MoreCallCredentials.from(GoogleCredentials.getApplicationDefault()); - } catch (IOException e) { - status = - Status.UNAUTHENTICATED - .withDescription("Failed to get Google default credentials") - .withCause(e); - } - return delegate().intercept(new GoogleDefaultInterceptor(credentials, status)).build(); - } - @VisibleForTesting GoogleDefaultProtocolNegotiator getProtocolNegotiatorForTest() { return negotiatorForTest;