-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Full Endpoint Resolution from EndpointContext #2313
Changes from all commits
bdbaab1
bf878b9
13aa12e
1857882
15d510e
653db8e
3d3d7a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,9 @@ public abstract class ClientContext { | |
@Nullable | ||
abstract String getServiceName(); | ||
|
||
@Nullable | ||
public abstract String getUniverseDomain(); | ||
|
||
@Nullable | ||
public abstract String getEndpoint(); | ||
|
||
|
@@ -157,15 +160,28 @@ public static ClientContext create(StubSettings settings) throws IOException { | |
final ScheduledExecutorService backgroundExecutor = backgroundExecutorProvider.getExecutor(); | ||
|
||
Credentials credentials = settings.getCredentialsProvider().getCredentials(); | ||
boolean usingGDCH = credentials instanceof GdchCredentials; | ||
EndpointContext endpointContext = | ||
EndpointContext.newBuilder() | ||
.setServiceName(settings.getServiceName()) | ||
.setUniverseDomain(settings.getUniverseDomain()) | ||
.setClientSettingsEndpoint(settings.getEndpoint()) | ||
.setTransportChannelProviderEndpoint( | ||
settings.getTransportChannelProvider().getEndpoint()) | ||
.setMtlsEndpoint(settings.getMtlsEndpoint()) | ||
.setSwitchToMtlsEndpointAllowed(settings.getSwitchToMtlsEndpointAllowed()) | ||
.setUsingGDCH(usingGDCH) | ||
.build(); | ||
String endpoint = endpointContext.resolvedEndpoint(); | ||
|
||
String settingsGdchApiAudience = settings.getGdchApiAudience(); | ||
if (credentials instanceof GdchCredentials) { | ||
if (usingGDCH) { | ||
// We recompute the GdchCredentials with the audience | ||
String audienceString; | ||
if (!Strings.isNullOrEmpty(settingsGdchApiAudience)) { | ||
audienceString = settingsGdchApiAudience; | ||
} else if (!Strings.isNullOrEmpty(settings.getEndpoint())) { | ||
audienceString = settings.getEndpoint(); | ||
} else if (!Strings.isNullOrEmpty(endpoint)) { | ||
audienceString = endpoint; | ||
Comment on lines
+183
to
+184
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirm this behavior is correct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The GDC-H audienceString's endpoint should match with endpoint set inside the TransportChannelProvider. The logic is that for a GDC-H flow, the resolved endpoint will be either the clientsettings endpoint or transportchannel endpoint if set. This matches the behavior below as either the clientSettings or transportchannel's endpoint. ClientSettings will only be set to the Transportchannel if it doesn't have an endpoint already set by the user. EndpointContext's resolvedEndpoint already takes this into consideration. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The else block is kept as the custom endpoint could be set as "" (empty string). |
||
} else { | ||
throw new IllegalArgumentException("Could not infer GDCH api audience from settings"); | ||
} | ||
|
@@ -204,16 +220,6 @@ public static ClientContext create(StubSettings settings) throws IOException { | |
if (transportChannelProvider.needsCredentials() && credentials != null) { | ||
transportChannelProvider = transportChannelProvider.withCredentials(credentials); | ||
} | ||
EndpointContext endpointContext = | ||
EndpointContext.newBuilder() | ||
.setServiceName(settings.getServiceName()) | ||
.setClientSettingsEndpoint(settings.getEndpoint()) | ||
.setTransportChannelProviderEndpoint( | ||
settings.getTransportChannelProvider().getEndpoint()) | ||
.setMtlsEndpoint(settings.getMtlsEndpoint()) | ||
.setSwitchToMtlsEndpointAllowed(settings.getSwitchToMtlsEndpointAllowed()) | ||
.build(); | ||
String endpoint = endpointContext.getResolvedEndpoint(); | ||
if (transportChannelProvider.needsEndpoint()) { | ||
transportChannelProvider = transportChannelProvider.withEndpoint(endpoint); | ||
} | ||
|
@@ -264,6 +270,7 @@ public static ClientContext create(StubSettings settings) throws IOException { | |
.setClock(clock) | ||
.setDefaultCallContext(defaultCallContext) | ||
.setServiceName(settings.getServiceName()) | ||
.setUniverseDomain(settings.getUniverseDomain()) | ||
.setEndpoint(settings.getEndpoint()) | ||
.setQuotaProjectId(settings.getQuotaProjectId()) | ||
.setStreamWatchdog(watchdog) | ||
|
@@ -332,6 +339,8 @@ public abstract static class Builder { | |
// Package-Private scope for internal use only. Shared between StubSettings and ClientContext | ||
abstract Builder setServiceName(String serviceName); | ||
|
||
public abstract Builder setUniverseDomain(String universeDomain); | ||
|
||
public abstract Builder setEndpoint(String endpoint); | ||
|
||
public abstract Builder setQuotaProjectId(String QuotaProjectId); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to expose a getter for universe domain? I guess it is for
StubSettings
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for the for logic that connects ClientContext <-> StubSettings. I believe it was added a while back for reasons and this getter is (ideally) only for StubSettings usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, for every new
ClientSettings
, it seems that we have to duplicate it inStubSettings
as well.