Enable NettyChannelBuilder to set default call credentials
I spoke with @ejona86 regarding this issue. Currently, there's no straightforward way to set a default call credentials using io.grpc.netty.NettyChannelBuilder to allow all calls using this channel to have a default credential. Right now one approach is to pass an interceptor, such as ClientAuthInterceptor, to ChannelBuilder. (here's an example: https://github.com/googleapis/gax-java/blob/master/src/main/java/com/google/api/gax/grpc/InstantiatingChannelProvider.java#L116)
However, ClientAuthInterceptor is deprecated. Therefore, it would be great if ChannelBuilder could provide a method, say "callCredentials", such that one can do something like NettyChannelBuilder.forAddress(addr, port).callCredentials(creds).build()
Default call credentials on the channel is something the other languages support.
Note: We will be switching gax-java to use ManagedChannelBuilder instead, so of course this functionality would need to be surfaced there also.
@ejona86 is there any non-deprecated/non-experimental way to set call credentials? Since default call credentials are not supported, I guess the question boils down to whether there is a way to do it per-call. CallOptions.withCallCredentials appears to be experimental: https://github.com/grpc/grpc-java/blob/master/core/src/main/java/io/grpc/CallOptions.java#L106
Yes, if this is done (I'm a supporter, but there is disagreement), then it should be done on ManagedChannelBuilder. But it will be marked experimental for at least one release. You can make your own interceptor though.
class CallCredsInterceptor implements ClientInterceptor {
private final CallCredentials callCreds;
public CallCredsInterceptor(CallCredentials callCreds) {
this.callCreds = callCreds;
}
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
// Note that this overrides the call creds. You may want to check if there are creds
// already set on the options.
return next.newCall(method, callOptions.withCallCredentials(callCreds));
}
}
@garrettjonesgoogle, well, CallCredentials itself is experimental. I can agree that's a problem, but discussing that should happen in #1914.
Passing CallCredentials to a channel during construction is available when using CompositeChannelCredentials, introduced in #7294.