mirror of https://github.com/grpc/grpc-java.git
alts: Eagerly add interceptor in GoogleDefaultChannelBuilder
This allows calling build() multiple times as well as prevents other interceptors from being able to detect that we've implemented CallCredential attachment via an interceptor. (Previously they could have set their own CallCredentials which would have overridden the default creds.)
This commit is contained in:
parent
dbc9a89e26
commit
03300cb2de
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue