Skip to content

Commit c24277a

Browse files
Add cloud field to HostMetadata (#710)
## 🥞 Stacked PR - [**#710 Add cloud field to HostMetadata**](#710) [[Files](https://github.com/databricks/databricks-sdk-java/pull/710/files)] - [#711 Fix GetWorkspaceClient for unified account hosts](#711) [[Files](https://github.com/databricks/databricks-sdk-java/pull/711/files)] - [#712 Add test for GetWorkspaceClient with SPOG host](#712) [[Files](https://github.com/databricks/databricks-sdk-java/pull/712/files)] - [#713 Call resolveHostMetadata on Config init](#713) [[Files](https://github.com/databricks/databricks-sdk-java/pull/713/files)] - [#714 Resolve TokenAudience from host metadata for account hosts](#714) [[Files](https://github.com/databricks/databricks-sdk-java/pull/714/files)] - [#718 Make GCP SA token refresh non-blocking](#718) [[Files](https://github.com/databricks/databricks-sdk-java/pull/718/files)] - [#719 Add integration test for host metadata resolution](#719) [[Files](https://github.com/databricks/databricks-sdk-java/pull/719/files)] - [#720 Remove unified flag usage, rely on host metadata](#720) [[Files](https://github.com/databricks/databricks-sdk-java/pull/720/files)] --------- ## Summary Port of Go SDK [#1512](databricks/databricks-sdk-go#1512). Adds a `cloud` field to `HostMetadata` that is populated from the `/.well-known/databricks-config` discovery endpoint. **Why:** Today, `isAws()`, `isAzure()`, and `isGcp()` infer cloud type by suffix-matching the workspace hostname against a hardcoded list of known DNS zones. This works for standard deployments but fails for non-standard hostnames (custom vanity domains, unified hosts, etc.). The discovery endpoint is the authoritative source and already returns a `cloud` field, but the SDK was discarding it. **Changes:** - `HostMetadata`: new `cloud` field (`@JsonProperty("cloud")`), getter, and 4-arg constructor - `HostMetadataTest`: deserialization with/without cloud, constructor tests `NO_CHANGELOG=true` ## Test plan - [x] `HostMetadataTest`: 4 tests for cloud field deserialization and constructors
1 parent 834c15d commit c24277a

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/HostMetadata.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public class HostMetadata {
2020
@JsonProperty("workspace_id")
2121
private String workspaceId;
2222

23+
@JsonProperty("cloud")
24+
private String cloud;
25+
2326
public HostMetadata() {}
2427

2528
public HostMetadata(String oidcEndpoint, String accountId, String workspaceId) {
@@ -28,6 +31,13 @@ public HostMetadata(String oidcEndpoint, String accountId, String workspaceId) {
2831
this.workspaceId = workspaceId;
2932
}
3033

34+
public HostMetadata(String oidcEndpoint, String accountId, String workspaceId, String cloud) {
35+
this.oidcEndpoint = oidcEndpoint;
36+
this.accountId = accountId;
37+
this.workspaceId = workspaceId;
38+
this.cloud = cloud;
39+
}
40+
3141
public String getOidcEndpoint() {
3242
return oidcEndpoint;
3343
}
@@ -39,4 +49,8 @@ public String getAccountId() {
3949
public String getWorkspaceId() {
4050
return workspaceId;
4151
}
52+
53+
public String getCloud() {
54+
return cloud;
55+
}
4256
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.databricks.sdk.core.oauth;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import org.junit.jupiter.api.Test;
7+
8+
class HostMetadataTest {
9+
10+
private final ObjectMapper mapper = new ObjectMapper();
11+
12+
@Test
13+
void testDeserializeWithCloud() throws Exception {
14+
String json =
15+
"{\"oidc_endpoint\":\"https://example.com/oidc\","
16+
+ "\"account_id\":\"acc-123\","
17+
+ "\"workspace_id\":\"ws-456\","
18+
+ "\"cloud\":\"aws\"}";
19+
20+
HostMetadata meta = mapper.readValue(json, HostMetadata.class);
21+
22+
assertEquals("https://example.com/oidc", meta.getOidcEndpoint());
23+
assertEquals("acc-123", meta.getAccountId());
24+
assertEquals("ws-456", meta.getWorkspaceId());
25+
assertEquals("aws", meta.getCloud());
26+
}
27+
28+
@Test
29+
void testDeserializeWithoutCloud() throws Exception {
30+
String json =
31+
"{\"oidc_endpoint\":\"https://example.com/oidc\","
32+
+ "\"account_id\":\"acc-123\","
33+
+ "\"workspace_id\":\"ws-456\"}";
34+
35+
HostMetadata meta = mapper.readValue(json, HostMetadata.class);
36+
37+
assertEquals("https://example.com/oidc", meta.getOidcEndpoint());
38+
assertEquals("acc-123", meta.getAccountId());
39+
assertEquals("ws-456", meta.getWorkspaceId());
40+
assertNull(meta.getCloud());
41+
}
42+
43+
@Test
44+
void testConstructorWithCloud() {
45+
HostMetadata meta = new HostMetadata("https://example.com/oidc", "acc-123", "ws-456", "gcp");
46+
47+
assertEquals("https://example.com/oidc", meta.getOidcEndpoint());
48+
assertEquals("acc-123", meta.getAccountId());
49+
assertEquals("ws-456", meta.getWorkspaceId());
50+
assertEquals("gcp", meta.getCloud());
51+
}
52+
53+
@Test
54+
void testConstructorWithoutCloud() {
55+
HostMetadata meta = new HostMetadata("https://example.com/oidc", "acc-123", "ws-456");
56+
57+
assertEquals("https://example.com/oidc", meta.getOidcEndpoint());
58+
assertEquals("acc-123", meta.getAccountId());
59+
assertEquals("ws-456", meta.getWorkspaceId());
60+
assertNull(meta.getCloud());
61+
}
62+
}

0 commit comments

Comments
 (0)