xds: use UpstreamTlsContext from attrs (#6533)

This commit is contained in:
sanjaypujare 2019-12-18 09:40:23 -08:00 committed by GitHub
parent 06d529669a
commit ead36d152a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View File

@ -37,7 +37,7 @@ public final class XdsChannelBuilder extends ForwardingChannelBuilder<XdsChannel
private final NettyChannelBuilder delegate; private final NettyChannelBuilder delegate;
// TODO (sanjaypujare) integrate with xDS client to get upstreamTlsContext from CDS // TODO (sanjaypujare) remove once we get this from CDS & don't need for testing
@Nullable private UpstreamTlsContext upstreamTlsContext; @Nullable private UpstreamTlsContext upstreamTlsContext;
private XdsChannelBuilder(NettyChannelBuilder delegate) { private XdsChannelBuilder(NettyChannelBuilder delegate) {

View File

@ -29,6 +29,7 @@ import io.grpc.netty.InternalProtocolNegotiator;
import io.grpc.netty.InternalProtocolNegotiator.ProtocolNegotiator; import io.grpc.netty.InternalProtocolNegotiator.ProtocolNegotiator;
import io.grpc.netty.InternalProtocolNegotiators; import io.grpc.netty.InternalProtocolNegotiators;
import io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.NettyChannelBuilder;
import io.grpc.xds.XdsAttributes;
import io.grpc.xds.sds.SslContextProvider; import io.grpc.xds.sds.SslContextProvider;
import io.grpc.xds.sds.TlsContextManager; import io.grpc.xds.sds.TlsContextManager;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
@ -109,7 +110,7 @@ public final class SdsProtocolNegotiators {
@VisibleForTesting @VisibleForTesting
static final class ClientSdsProtocolNegotiator implements ProtocolNegotiator { static final class ClientSdsProtocolNegotiator implements ProtocolNegotiator {
// TODO (sanjaypujare) integrate with xDS client to get upstreamTlsContext from CDS // TODO (sanjaypujare) remove once we get this from CDS & don't need for testing
UpstreamTlsContext upstreamTlsContext; UpstreamTlsContext upstreamTlsContext;
ClientSdsProtocolNegotiator(UpstreamTlsContext upstreamTlsContext) { ClientSdsProtocolNegotiator(UpstreamTlsContext upstreamTlsContext) {
@ -123,12 +124,16 @@ public final class SdsProtocolNegotiators {
@Override @Override
public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) { public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) {
// once CDS is implemented we will retrieve upstreamTlsContext as follows: // check if UpstreamTlsContext was passed via attributes
// grpcHandler.getEagAttributes().get(XdsAttributes.ATTR_UPSTREAM_TLS_CONTEXT); UpstreamTlsContext localUpstreamTlsContext =
if (isTlsContextEmpty(upstreamTlsContext)) { grpcHandler.getEagAttributes().get(XdsAttributes.ATTR_UPSTREAM_TLS_CONTEXT);
if (localUpstreamTlsContext == null) {
localUpstreamTlsContext = upstreamTlsContext;
}
if (isTlsContextEmpty(localUpstreamTlsContext)) {
return InternalProtocolNegotiators.plaintext().newHandler(grpcHandler); return InternalProtocolNegotiators.plaintext().newHandler(grpcHandler);
} }
return new ClientSdsHandler(grpcHandler, upstreamTlsContext); return new ClientSdsHandler(grpcHandler, localUpstreamTlsContext);
} }
private static boolean isTlsContextEmpty(UpstreamTlsContext upstreamTlsContext) { private static boolean isTlsContextEmpty(UpstreamTlsContext upstreamTlsContext) {