Skip to content

Commit 5f17e62

Browse files
authored
fix: Apiary Host returns user set host if set (#2455)
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.
1 parent ed21464 commit 5f17e62

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -851,17 +851,24 @@ public String getResolvedHost(String serviceName) {
851851
}
852852

853853
/**
854-
* Temporarily used for BigQuery and Storage Apiary Wrapped Libraries. To be removed in the future
855-
* when Apiary clients can resolve their endpoints. Returns the host to be used as the rootUrl.
854+
* Returns a host value to be used for BigQuery and Storage Apiary Wrapped Libraries. To be
855+
* removed in the future when Apiary clients can resolve their endpoints. Returns the host to be
856+
* used as the rootUrl.
856857
*
857858
* <p>The resolved host will be in `https://{serviceName}.{resolvedUniverseDomain}/` format. The
858859
* resolvedUniverseDomain will be set to `googleapis.com` if universeDomain is null.
859860
*
861+
* <p>The host value is set to DEFAULT_HOST if the user didn't configure a host. Returns the host
862+
* value the user set, otherwise constructs the host for the user.
863+
*
860864
* @see <a
861865
* 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>
862866
*/
863867
@InternalApi
864868
public String getResolvedApiaryHost(String serviceName) {
869+
if (!DEFAULT_HOST.equals(host)) {
870+
return host;
871+
}
865872
String resolvedUniverseDomain =
866873
universeDomain != null ? universeDomain : Credentials.GOOGLE_DEFAULT_UNIVERSE;
867874
return "https://" + serviceName + "." + resolvedUniverseDomain + "/";

java-core/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,10 @@ public void testGetResolvedApiaryHost_customUniverseDomain_customHost() {
566566
TestServiceOptions options =
567567
TestServiceOptions.newBuilder()
568568
.setUniverseDomain("test.com")
569-
.setHost("https://service.random.com")
569+
.setHost("https://service.random.com/")
570570
.setProjectId("project-id")
571571
.build();
572-
assertThat(options.getResolvedApiaryHost("service")).isEqualTo("https://service.test.com/");
572+
assertThat(options.getResolvedApiaryHost("service")).isEqualTo("https://service.random.com/");
573573
}
574574

575575
// No User Configuration = GDU, Default Credentials = GDU

0 commit comments

Comments
 (0)