@@ -123,6 +123,7 @@ public final class InstantiatingGrpcChannelProvider implements TransportChannelP
123
123
private final HeaderProvider headerProvider ;
124
124
private final boolean useS2A ;
125
125
private final String endpoint ;
126
+ private final String mtlsEndpoint ;
126
127
// TODO: remove. envProvider currently provides DirectPath environment variable, and is only used
127
128
// during initial rollout for DirectPath. This provider will be removed once the DirectPath
128
129
// environment is not used.
@@ -153,6 +154,7 @@ private InstantiatingGrpcChannelProvider(Builder builder) {
153
154
this .headerProvider = builder .headerProvider ;
154
155
this .useS2A = builder .useS2A ;
155
156
this .endpoint = builder .endpoint ;
157
+ this .mtlsEndpoint = builder .mtlsEndpoint ;
156
158
this .mtlsProvider = builder .mtlsProvider ;
157
159
this .s2aConfigProvider = builder .s2aConfigProvider ;
158
160
this .envProvider = builder .envProvider ;
@@ -229,6 +231,11 @@ public boolean needsEndpoint() {
229
231
return endpoint == null ;
230
232
}
231
233
234
+ @ Override
235
+ public boolean needsMtlsEndpoint () {
236
+ return mtlsEndpoint == null ;
237
+ }
238
+
232
239
/**
233
240
* Specify the endpoint the channel should connect to.
234
241
*
@@ -243,6 +250,21 @@ public TransportChannelProvider withEndpoint(String endpoint) {
243
250
return toBuilder ().setEndpoint (endpoint ).build ();
244
251
}
245
252
253
+ /**
254
+ * Specify the mtlsEndpoint the channel should connect to.
255
+ *
256
+ * <p>The value of {@code mtlsEndpoint} must be of the form {@code host:port}.
257
+ *
258
+ * @param mtlsEndpoint The mtlsEndpoint to connect to
259
+ * @return A new {@link InstantiatingGrpcChannelProvider} with the specified mtlsEndpoint
260
+ * configured
261
+ */
262
+ @ Override
263
+ public TransportChannelProvider withMtlsEndpoint (String mtlsEndpoint ) {
264
+ validateEndpoint (mtlsEndpoint );
265
+ return toBuilder ().setMtlsEndpoint (mtlsEndpoint ).build ();
266
+ }
267
+
246
268
/**
247
269
* Specify whether or not to use S2A.
248
270
*
@@ -623,8 +645,7 @@ private ManagedChannel createSingleChannel() throws IOException {
623
645
}
624
646
if (channelCredentials != null ) {
625
647
// Create the channel using S2A-secured channel credentials.
626
- // {@code endpoint} is set to mtlsEndpoint in {@link EndpointContext} when useS2A is true.
627
- builder = Grpc .newChannelBuilder (endpoint , channelCredentials );
648
+ builder = Grpc .newChannelBuilder (mtlsEndpoint , channelCredentials );
628
649
} else {
629
650
// Use default if we cannot initialize channel credentials via DCA or S2A.
630
651
builder = ManagedChannelBuilder .forAddress (serviceAddress , port );
@@ -777,6 +798,7 @@ public static final class Builder {
777
798
private Executor executor ;
778
799
private HeaderProvider headerProvider ;
779
800
private String endpoint ;
801
+ private String mtlsEndpoint ;
780
802
private boolean useS2A ;
781
803
private EnvironmentProvider envProvider ;
782
804
private SecureSessionAgent s2aConfigProvider = SecureSessionAgent .create ();
@@ -807,6 +829,7 @@ private Builder(InstantiatingGrpcChannelProvider provider) {
807
829
this .executor = provider .executor ;
808
830
this .headerProvider = provider .headerProvider ;
809
831
this .endpoint = provider .endpoint ;
832
+ this .mtlsEndpoint = provider .mtlsEndpoint ;
810
833
this .useS2A = provider .useS2A ;
811
834
this .envProvider = provider .envProvider ;
812
835
this .interceptorProvider = provider .interceptorProvider ;
@@ -877,11 +900,22 @@ public Builder setEndpoint(String endpoint) {
877
900
return this ;
878
901
}
879
902
903
+ /** Sets the mtlsEndpoint used to reach the service, eg "localhost:8080". */
904
+ public Builder setMtlsEndpoint (String mtlsEndpoint ) {
905
+ validateEndpoint (mtlsEndpoint );
906
+ this .mtlsEndpoint = mtlsEndpoint ;
907
+ return this ;
908
+ }
909
+
880
910
Builder setUseS2A (boolean useS2A ) {
881
911
this .useS2A = useS2A ;
882
912
return this ;
883
913
}
884
914
915
+ public String getMtlsEndpoint () {
916
+ return mtlsEndpoint ;
917
+ }
918
+
885
919
@ VisibleForTesting
886
920
Builder setMtlsProvider (MtlsProvider mtlsProvider ) {
887
921
this .mtlsProvider = mtlsProvider ;
0 commit comments