Skip to content

Commit

Permalink
fix: Apiary Host returns user set host if set (#2455)
Browse files Browse the repository at this point in the history
Bug: googleapis/java-bigquery#3125 (Removing
`Fixes:` as I don't want to close the ticket until BigQuery is able to
pull in a new version of shared-deps).

Following guidance in doc for Apiary (ping me internally for link).

If the user configures the host to be the `DEFAULT_HOST` (a non-valid
endpoint for any service using java-core), then it should construct a
valid service endpoint back using the universe domain.
  • Loading branch information
lqiu96 authored and ddixit14 committed Feb 15, 2024
1 parent fc84ee9 commit dc4039a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -851,17 +851,24 @@ public String getResolvedHost(String serviceName) {
}

/**
* Temporarily used for BigQuery and Storage Apiary Wrapped Libraries. To be removed in the future
* when Apiary clients can resolve their endpoints. Returns the host to be used as the rootUrl.
* Returns a host value to be used for BigQuery and Storage Apiary Wrapped Libraries. To be
* removed in the future when Apiary clients can resolve their endpoints. Returns the host to be
* used as the rootUrl.
*
* <p>The resolved host will be in `https://{serviceName}.{resolvedUniverseDomain}/` format. The
* resolvedUniverseDomain will be set to `googleapis.com` if universeDomain is null.
*
* <p>The host value is set to DEFAULT_HOST if the user didn't configure a host. Returns the host
* value the user set, otherwise constructs the host for the user.
*
* @see <a
* href="https://github.com/googleapis/google-api-java-client/blob/76765d5f9689be9d266a7d62fa6ffb4cabf701f5/google-api-client/src/main/java/com/google/api/client/googleapis/services/AbstractGoogleClient.java#L49">rootUrl</a>
*/
@InternalApi
public String getResolvedApiaryHost(String serviceName) {
if (!DEFAULT_HOST.equals(host)) {
return host;
}
String resolvedUniverseDomain =
universeDomain != null ? universeDomain : Credentials.GOOGLE_DEFAULT_UNIVERSE;
return "https://" + serviceName + "." + resolvedUniverseDomain + "/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,10 @@ public void testGetResolvedApiaryHost_customUniverseDomain_customHost() {
TestServiceOptions options =
TestServiceOptions.newBuilder()
.setUniverseDomain("test.com")
.setHost("https://service.random.com")
.setHost("https://service.random.com/")
.setProjectId("project-id")
.build();
assertThat(options.getResolvedApiaryHost("service")).isEqualTo("https://service.test.com/");
assertThat(options.getResolvedApiaryHost("service")).isEqualTo("https://service.random.com/");
}

// No User Configuration = GDU, Default Credentials = GDU
Expand Down

0 comments on commit dc4039a

Please sign in to comment.