Skip to content

Commit a74dd57

Browse files
committed
fix(mtls): Fix EndpointContext's determineEndpoint logic to respect env var
1 parent 473e1a6 commit a74dd57

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

gax-java/gax/src/main/java/com/google/api/gax/rpc/EndpointContext.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,22 @@ private String determineEndpoint() throws IOException {
292292
? CertificateBasedAccess.createWithSystemEnv()
293293
: certificateBasedAccess();
294294
MtlsProvider mtlsProvider = mtlsProvider();
295-
if (mtlsProvider == null) {
296-
try {
297-
mtlsProvider = DefaultMtlsProviderFactory.create();
298-
} catch (CertificateSourceUnavailableException e) {
299-
// This is okay. Leave mtlsProvider as null;
300-
} catch (IOException e) {
301-
LOG.log(
302-
Level.WARNING,
303-
"DefaultMtlsProviderFactory encountered unexpected IOException: " + e.getMessage());
295+
296+
// Only attempt to create a default MtlsProvider if client certificate usage is enabled.
297+
if (certificateBasedAccess.useMtlsClientCertificate()) {
298+
if (mtlsProvider == null) {
299+
try {
300+
mtlsProvider = DefaultMtlsProviderFactory.create();
301+
} catch (CertificateSourceUnavailableException e) {
302+
// This is okay. Leave mtlsProvider as null;
303+
} catch (IOException e) {
304+
LOG.log(
305+
Level.WARNING,
306+
"DefaultMtlsProviderFactory encountered unexpected IOException: " + e.getMessage());
307+
}
304308
}
305309
}
310+
306311
// TransportChannelProvider's endpoint will override the ClientSettings' endpoint
307312
String customEndpoint =
308313
transportChannelProviderEndpoint() == null

0 commit comments

Comments
 (0)