Skip to content

Commit 85cf695

Browse files
committed
Add cloud field to HostMetadata
Port of Go SDK #1512. Adds a `cloud` field (String, `@JsonProperty("cloud")`) to the HostMetadata class, with getter and updated constructor. Includes deserialization and constructor tests. Co-authored-by: Isaac
1 parent 834c15d commit 85cf695

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)