Skip to content

Commit

Permalink
feat: Remove TransportChannelProvider logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lqiu96 committed Dec 6, 2023
1 parent ce5255a commit a6eeda8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public static ClientContext create(StubSettings settings) throws IOException {
.setMtlsEndpoint(settings.getMtlsEndpoint())
.setSwitchToMtlsEndpointAllowed(settings.getSwitchToMtlsEndpointAllowed())
.build();
String endpoint = endpointContext.resolveEndpoint();
String endpoint = endpointContext.getResolvedEndpoint();
if (transportChannelProvider.needsEndpoint()) {
transportChannelProvider = transportChannelProvider.withEndpoint(endpoint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ public abstract class EndpointContext {
@Nullable
public abstract String clientSettingsEndpoint();

@Nullable
public abstract String transportChannelEndpoint();

@Nullable
public abstract String mtlsEndpoint();

Expand All @@ -65,11 +62,9 @@ public static Builder newBuilder() {
@VisibleForTesting
void determineEndpoint() throws IOException {
MtlsProvider mtlsProvider = mtlsProvider() == null ? new MtlsProvider() : mtlsProvider();
String customEndpoint =
transportChannelEndpoint() != null ? transportChannelEndpoint() : clientSettingsEndpoint();
resolvedEndpoint =
mtlsEndpointResolver(
customEndpoint, mtlsEndpoint(), switchToMtlsEndpointAllowed(), mtlsProvider);
clientSettingsEndpoint(), mtlsEndpoint(), switchToMtlsEndpointAllowed(), mtlsProvider);
}

// This takes in parameters because determineEndpoint()'s logic will be updated
Expand Down Expand Up @@ -98,29 +93,30 @@ String mtlsEndpointResolver(
return endpoint;
}

public String resolveEndpoint() throws IOException {
if (isEndpointUnresolved()) {
determineEndpoint();
}
public String getResolvedEndpoint() {
return resolvedEndpoint;
}

private boolean isEndpointUnresolved() {
return resolvedEndpoint == null;
}

@AutoValue.Builder
public abstract static class Builder {
public abstract Builder setClientSettingsEndpoint(String clientSettingsEndpoint);

public abstract Builder setTransportChannelEndpoint(String transportChannelEndpoint);

public abstract Builder setMtlsEndpoint(String mtlsEndpoint);

public abstract Builder setSwitchToMtlsEndpointAllowed(boolean switchToMtlsEndpointAllowed);

public abstract Builder setMtlsProvider(MtlsProvider mtlsProvider);

public abstract EndpointContext build();
abstract EndpointContext autoBuild();

public EndpointContext build() {
try {
EndpointContext endpointContext = autoBuild();
endpointContext.determineEndpoint();
return endpointContext;
} catch (IOException e) {
throw new RuntimeException("Unable to determine the endpoint: " + e.getMessage());
}
}
}
}

0 comments on commit a6eeda8

Please sign in to comment.