Skip to content

Commit ac7c30b

Browse files
authored
fix(spanner): moved mTLSContext configurator from builder to construtor (#3605)
* fix(spanner): moved mTLSContext configurator from builder to construtor * builder configurator properties retained when not null
1 parent 3e27251 commit ac7c30b

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java

+14-10
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,20 @@ protected SpannerOptions(Builder builder) {
741741

742742
transportChannelExecutorThreadNameFormat = builder.transportChannelExecutorThreadNameFormat;
743743
channelProvider = builder.channelProvider;
744-
channelConfigurator = builder.channelConfigurator;
744+
if (builder.mTLSContext != null) {
745+
channelConfigurator =
746+
channelBuilder -> {
747+
if (builder.channelConfigurator != null) {
748+
channelBuilder = builder.channelConfigurator.apply(channelBuilder);
749+
}
750+
if (channelBuilder instanceof NettyChannelBuilder) {
751+
((NettyChannelBuilder) channelBuilder).sslContext(builder.mTLSContext);
752+
}
753+
return channelBuilder;
754+
};
755+
} else {
756+
channelConfigurator = builder.channelConfigurator;
757+
}
745758
interceptorProvider = builder.interceptorProvider;
746759
sessionPoolOptions =
747760
builder.sessionPoolOptions != null
@@ -1620,15 +1633,6 @@ public SpannerOptions build() {
16201633
// As we are using plain text, we should never send any credentials.
16211634
this.setCredentials(NoCredentials.getInstance());
16221635
}
1623-
if (mTLSContext != null) {
1624-
this.setChannelConfigurator(
1625-
builder -> {
1626-
if (builder instanceof NettyChannelBuilder) {
1627-
((NettyChannelBuilder) builder).sslContext(mTLSContext);
1628-
}
1629-
return builder;
1630-
});
1631-
}
16321636
if (this.numChannels == null) {
16331637
this.numChannels =
16341638
this.grpcGcpExtensionEnabled ? GRPC_GCP_ENABLED_DEFAULT_CHANNELS : DEFAULT_CHANNELS;

0 commit comments

Comments
 (0)