Skip to content

Commit 0153bc0

Browse files
committed
simplify, fix
1 parent 15f0649 commit 0153bc0

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

temporal-serviceclient/src/main/java/io/temporal/serviceclient/ServiceStubsOptions.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,8 @@ public String toString() {
418418
public static class Builder<T extends Builder<T>> {
419419
private ManagedChannel channel;
420420
private SslContext sslContext;
421-
private Boolean enableHttps;
421+
private boolean enableHttps;
422+
private boolean enableHttpsExplicitlySet;
422423
private String target;
423424
private Consumer<ManagedChannelBuilder<?>> channelInitializer;
424425
private Duration healthCheckAttemptTimeout;
@@ -435,6 +436,7 @@ public static class Builder<T extends Builder<T>> {
435436
private Collection<GrpcMetadataProvider> grpcMetadataProviders;
436437
private Collection<ClientInterceptor> grpcClientInterceptors;
437438
private Scope metricsScope;
439+
private boolean apiKeyProvided;
438440

439441
protected Builder() {}
440442

@@ -443,6 +445,7 @@ protected Builder(ServiceStubsOptions options) {
443445
this.target = options.target;
444446
this.channelInitializer = options.channelInitializer;
445447
this.enableHttps = options.enableHttps;
448+
this.enableHttpsExplicitlySet = true;
446449
this.sslContext = options.sslContext;
447450
this.healthCheckAttemptTimeout = options.healthCheckAttemptTimeout;
448451
this.healthCheckTimeout = options.healthCheckTimeout;
@@ -542,6 +545,7 @@ public T setSslContext(SslContext sslContext) {
542545
*/
543546
public T setEnableHttps(boolean enableHttps) {
544547
this.enableHttps = enableHttps;
548+
this.enableHttpsExplicitlySet = true;
545549
return self();
546550
}
547551

@@ -613,6 +617,7 @@ public T addGrpcMetadataProvider(GrpcMetadataProvider grpcMetadataProvider) {
613617
* @return {@code this}
614618
*/
615619
public T addApiKey(AuthorizationTokenSupplier apiKey) {
620+
this.apiKeyProvided = true;
616621
addGrpcMetadataProvider(
617622
new AuthorizationGrpcMetadataProvider(() -> "Bearer " + apiKey.supply()));
618623
return self();
@@ -852,15 +857,11 @@ public ServiceStubsOptions validateAndBuildWithDefaults() {
852857
MoreObjects.firstNonNull(this.grpcClientInterceptors, Collections.emptyList());
853858

854859
// Auto-enable TLS when API key is provided and TLS is not explicitly set
855-
boolean enableHttps = this.enableHttps != null ? this.enableHttps : false;
856-
if (this.enableHttps == null && this.sslContext == null) {
857-
// Check if an API key provider was added
858-
boolean hasApiKey =
859-
grpcMetadataProviders.stream()
860-
.anyMatch(provider -> provider instanceof AuthorizationGrpcMetadataProvider);
861-
if (hasApiKey) {
862-
enableHttps = true;
863-
}
860+
boolean enableHttps;
861+
if (this.enableHttpsExplicitlySet) {
862+
enableHttps = this.enableHttps;
863+
} else {
864+
enableHttps = this.apiKeyProvided;
864865
}
865866

866867
Scope metricsScope = this.metricsScope != null ? this.metricsScope : new NoopScope();

temporal-serviceclient/src/test/java/io/temporal/serviceclient/ServiceStubsOptionsTest.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ public class ServiceStubsOptionsTest {
88

99
@Test
1010
public void testTLSEnabledByDefaultWhenAPIKeyProvided() {
11-
// Test that TLS is enabled by default when API key is provided and TLS is not configured
1211
ServiceStubsOptions options =
1312
WorkflowServiceStubsOptions.newBuilder()
1413
.setTarget("localhost:7233")
@@ -21,7 +20,6 @@ public void testTLSEnabledByDefaultWhenAPIKeyProvided() {
2120

2221
@Test
2322
public void testTLSCanBeExplicitlyDisabledWithAPIKey() {
24-
// Test that TLS can be explicitly disabled even when API key is provided
2523
ServiceStubsOptions options =
2624
WorkflowServiceStubsOptions.newBuilder()
2725
.setTarget("localhost:7233")
@@ -33,18 +31,6 @@ public void testTLSCanBeExplicitlyDisabledWithAPIKey() {
3331
assertFalse(options.getEnableHttps());
3432
}
3533

36-
@Test
37-
public void testTLSDisabledByDefaultWithoutAPIKey() {
38-
// Test that TLS is disabled by default when no API key is provided
39-
ServiceStubsOptions options =
40-
WorkflowServiceStubsOptions.newBuilder()
41-
.setTarget("localhost:7233")
42-
.validateAndBuildWithDefaults();
43-
44-
// TLS should remain disabled when no api_key is provided
45-
assertFalse(options.getEnableHttps());
46-
}
47-
4834
@Test
4935
public void testExplicitTLSConfigPreservedWithAPIKey() {
5036
// Test that explicit TLS configuration is preserved when API key is provided

0 commit comments

Comments
 (0)