From c879465a3284eefb19646907ba21aef97b7a6f33 Mon Sep 17 00:00:00 2001 From: Tanmay Rustagi Date: Mon, 30 Mar 2026 16:56:16 +0200 Subject: [PATCH 1/5] Add HostType to HostMetadata Signed-off-by: Tanmay Rustagi --- .../databricks/sdk/core/DatabricksConfig.java | 24 +++++ .../com/databricks/sdk/core/HostType.java | 22 ++++- .../sdk/core/oauth/HostMetadata.java | 7 ++ .../sdk/core/DatabricksConfigTest.java | 88 +++++++++++++++++++ .../com/databricks/sdk/core/HostTypeTest.java | 46 ++++++++++ 5 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 databricks-sdk-java/src/test/java/com/databricks/sdk/core/HostTypeTest.java diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java index 43c1f5136..35e93fd28 100644 --- a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java @@ -162,6 +162,12 @@ public class DatabricksConfig { private DatabricksEnvironment databricksEnvironment; + /** + * The host type resolved from the /.well-known/databricks-config discovery endpoint. When set, + * this takes priority over URL-based host type detection in {@link #getHostType()}. + */ + private HostType resolvedHostType; + /** * When using Workload Identity Federation, the audience to specify when fetching an ID token from * the ID token supplier. @@ -723,6 +729,17 @@ public DatabricksConfig setDisableOauthRefreshToken(boolean disable) { return this; } + /** Returns the host type resolved from host metadata, or {@code null} if not yet resolved. */ + HostType getResolvedHostType() { + return resolvedHostType; + } + + /** Sets the resolved host type. Package-private for testing. */ + DatabricksConfig setResolvedHostType(HostType resolvedHostType) { + this.resolvedHostType = resolvedHostType; + return this; + } + public boolean isAzure() { if (azureWorkspaceResourceId != null) { return true; @@ -889,6 +906,13 @@ void resolveHostMetadata() throws IOException { LOG.debug("Resolved workspace_id from host metadata: \"{}\"", meta.getWorkspaceId()); workspaceId = meta.getWorkspaceId(); } + if (resolvedHostType == null && meta.getHostType() != null) { + HostType ht = HostType.fromApiValue(meta.getHostType()); + if (ht != null) { + LOG.debug("Resolved host_type from host metadata: \"{}\"", ht); + resolvedHostType = ht; + } + } if (discoveryUrl == null) { if (meta.getOidcEndpoint() == null || meta.getOidcEndpoint().isEmpty()) { LOG.warn("Host metadata missing oidc_endpoint; skipping discovery URL resolution"); diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/HostType.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/HostType.java index 005807839..5976ae345 100644 --- a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/HostType.java +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/HostType.java @@ -12,5 +12,25 @@ public enum HostType { ACCOUNTS, /** Unified host supporting both workspace and account operations. */ - UNIFIED + UNIFIED; + + /** + * Converts an API-level host type string (e.g. "workspace", "account", "unified") to the + * corresponding enum value. Returns {@code null} for unknown or empty values. + */ + public static HostType fromApiValue(String value) { + if (value == null || value.isEmpty()) { + return null; + } + switch (value.toLowerCase()) { + case "workspace": + return WORKSPACE; + case "account": + return ACCOUNTS; + case "unified": + return UNIFIED; + default: + return null; + } + } } diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/HostMetadata.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/HostMetadata.java index 3962f75d9..dfbf91fa5 100644 --- a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/HostMetadata.java +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/HostMetadata.java @@ -23,6 +23,9 @@ public class HostMetadata { @JsonProperty("cloud") private String cloud; + @JsonProperty("host_type") + private String hostType; + public HostMetadata() {} public HostMetadata(String oidcEndpoint, String accountId, String workspaceId) { @@ -53,4 +56,8 @@ public String getWorkspaceId() { public String getCloud() { return cloud; } + + public String getHostType() { + return hostType; + } } diff --git a/databricks-sdk-java/src/test/java/com/databricks/sdk/core/DatabricksConfigTest.java b/databricks-sdk-java/src/test/java/com/databricks/sdk/core/DatabricksConfigTest.java index 0e86b4ef4..b2a83392f 100644 --- a/databricks-sdk-java/src/test/java/com/databricks/sdk/core/DatabricksConfigTest.java +++ b/databricks-sdk-java/src/test/java/com/databricks/sdk/core/DatabricksConfigTest.java @@ -712,6 +712,94 @@ public void testEnsureResolvedHostMetadataMissingAccountIdWithPlaceholderNonFata } } + // --- resolveHostMetadata host type tests --- + + @Test + public void testResolveHostMetadataPopulatesResolvedHostType() throws IOException { + String response = + "{\"oidc_endpoint\":\"https://ws.databricks.com/oidc\"," + + "\"account_id\":\"" + + DUMMY_ACCOUNT_ID + + "\"," + + "\"host_type\":\"workspace\"}"; + try (FixtureServer server = + new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) { + DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl()); + config.resolve(emptyEnv()); + config.resolveHostMetadata(); + assertEquals(HostType.WORKSPACE, config.getResolvedHostType()); + } + } + + @Test + public void testResolveHostMetadataDoesNotOverwriteExistingHostType() throws IOException { + String response = + "{\"oidc_endpoint\":\"https://ws.databricks.com/oidc\"," + + "\"account_id\":\"" + + DUMMY_ACCOUNT_ID + + "\"," + + "\"host_type\":\"workspace\"}"; + try (FixtureServer server = + new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) { + DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl()); + config.resolve(emptyEnv()); + config.setResolvedHostType(HostType.UNIFIED); + config.resolveHostMetadata(); + assertEquals(HostType.UNIFIED, config.getResolvedHostType()); + } + } + + @Test + public void testResolveHostMetadataUnknownHostTypeIgnored() throws IOException { + String response = + "{\"oidc_endpoint\":\"https://ws.databricks.com/oidc\"," + + "\"account_id\":\"" + + DUMMY_ACCOUNT_ID + + "\"," + + "\"host_type\":\"unknown_value\"}"; + try (FixtureServer server = + new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) { + DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl()); + config.resolve(emptyEnv()); + config.resolveHostMetadata(); + assertNull(config.getResolvedHostType()); + } + } + + @Test + public void testResolveHostMetadataHostTypeAccount() throws IOException { + String response = + "{\"oidc_endpoint\":\"https://ws.databricks.com/oidc\"," + + "\"account_id\":\"" + + DUMMY_ACCOUNT_ID + + "\"," + + "\"host_type\":\"account\"}"; + try (FixtureServer server = + new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) { + DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl()); + config.resolve(emptyEnv()); + config.resolveHostMetadata(); + assertEquals(HostType.ACCOUNTS, config.getResolvedHostType()); + } + } + + @Test + public void testResolveHostMetadataHostTypeUnified() throws IOException { + String response = + "{\"oidc_endpoint\":\"https://ws.databricks.com/oidc\"," + + "\"account_id\":\"" + + DUMMY_ACCOUNT_ID + + "\"," + + "\"host_type\":\"unified\"}"; + try (FixtureServer server = + new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) { + DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl()); + config.resolve(emptyEnv()); + config.resolveHostMetadata(); + assertEquals(HostType.UNIFIED, config.getResolvedHostType()); + } + } + // --- discoveryUrl / OIDC endpoint tests --- @Test diff --git a/databricks-sdk-java/src/test/java/com/databricks/sdk/core/HostTypeTest.java b/databricks-sdk-java/src/test/java/com/databricks/sdk/core/HostTypeTest.java new file mode 100644 index 000000000..63cd9b100 --- /dev/null +++ b/databricks-sdk-java/src/test/java/com/databricks/sdk/core/HostTypeTest.java @@ -0,0 +1,46 @@ +package com.databricks.sdk.core; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +public class HostTypeTest { + + @Test + public void testFromApiValueWorkspace() { + assertEquals(HostType.WORKSPACE, HostType.fromApiValue("workspace")); + } + + @Test + public void testFromApiValueAccount() { + assertEquals(HostType.ACCOUNTS, HostType.fromApiValue("account")); + } + + @Test + public void testFromApiValueUnified() { + assertEquals(HostType.UNIFIED, HostType.fromApiValue("unified")); + } + + @Test + public void testFromApiValueCaseInsensitive() { + assertEquals(HostType.WORKSPACE, HostType.fromApiValue("WORKSPACE")); + assertEquals(HostType.ACCOUNTS, HostType.fromApiValue("Account")); + assertEquals(HostType.UNIFIED, HostType.fromApiValue("UNIFIED")); + } + + @Test + public void testFromApiValueNull() { + assertNull(HostType.fromApiValue(null)); + } + + @Test + public void testFromApiValueEmpty() { + assertNull(HostType.fromApiValue("")); + } + + @Test + public void testFromApiValueUnknown() { + assertNull(HostType.fromApiValue("unknown")); + assertNull(HostType.fromApiValue("something_else")); + } +} From 2aec9e4c0fd69fdcc9489d70adaa9735beac0549 Mon Sep 17 00:00:00 2001 From: Tanmay Rustagi Date: Mon, 30 Mar 2026 18:42:28 +0200 Subject: [PATCH 2/5] Regenerate lockfile for commons-configuration2 2.13.0 Signed-off-by: Tanmay Rustagi --- databricks-sdk-java/lockfile.json | 62 +++++++++++++++---------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/databricks-sdk-java/lockfile.json b/databricks-sdk-java/lockfile.json index 8ba1d918d..d9ab2d94c 100644 --- a/databricks-sdk-java/lockfile.json +++ b/databricks-sdk-java/lockfile.json @@ -735,68 +735,68 @@ { "groupId": "org.apache.commons", "artifactId": "commons-configuration2", - "version": "2.11.0", + "version": "2.13.0", "checksumAlgorithm": "SHA-256", - "checksum": "48957fc3a0d9fbd221fe4f5ff6d0294ce6646ea139793c36706703da59402683", + "checksum": "7622799663317f95c81019b32b39e0c82e42b388f00abe6e5ab26489d90d9a6b", "scope": "compile", - "resolved": "https://repo.maven.apache.org/maven2/org/apache/commons/commons-configuration2/2.11.0/commons-configuration2-2.11.0.jar", - "selectedVersion": "2.11.0", + "resolved": "https://repo.maven.apache.org/maven2/org/apache/commons/commons-configuration2/2.13.0/commons-configuration2-2.13.0.jar", + "selectedVersion": "2.13.0", "included": true, - "id": "org.apache.commons:commons-configuration2:2.11.0", + "id": "org.apache.commons:commons-configuration2:2.13.0", "children": [ { "groupId": "commons-logging", "artifactId": "commons-logging", - "version": "1.3.2", + "version": "1.3.5", "checksumAlgorithm": "SHA-256", - "checksum": "6b858424f518015f32bfcd1183a373f4a827d72d026b6031da0c91cf0e8f3489", + "checksum": "6d7a744e4027649fbb50895df9497d109f98c766a637062fe8d2eabbb3140ba4", "scope": "compile", - "resolved": "https://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.3.2/commons-logging-1.3.2.jar", - "selectedVersion": "1.3.2", + "resolved": "https://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.3.5/commons-logging-1.3.5.jar", + "selectedVersion": "1.3.5", "included": true, - "id": "commons-logging:commons-logging:1.3.2", - "parent": "org.apache.commons:commons-configuration2:2.11.0", + "id": "commons-logging:commons-logging:1.3.5", + "parent": "org.apache.commons:commons-configuration2:2.13.0", "children": [] }, { "groupId": "org.apache.commons", "artifactId": "commons-lang3", - "version": "3.14.0", + "version": "3.20.0", "checksumAlgorithm": "SHA-256", - "checksum": "7b96bf3ee68949abb5bc465559ac270e0551596fa34523fddf890ec418dde13c", + "checksum": "69e5c9fa35da7a51a5fd2099dfe56a2d8d32cf233e2f6d770e796146440263f4", "scope": "compile", - "resolved": "https://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3/3.14.0/commons-lang3-3.14.0.jar", - "selectedVersion": "3.14.0", + "resolved": "https://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3/3.20.0/commons-lang3-3.20.0.jar", + "selectedVersion": "3.20.0", "included": true, - "id": "org.apache.commons:commons-lang3:3.14.0", - "parent": "org.apache.commons:commons-configuration2:2.11.0", + "id": "org.apache.commons:commons-lang3:3.20.0", + "parent": "org.apache.commons:commons-configuration2:2.13.0", "children": [] }, { "groupId": "org.apache.commons", "artifactId": "commons-text", - "version": "1.12.0", + "version": "1.14.0", "checksumAlgorithm": "SHA-256", - "checksum": "de023257ff166044a56bd1aa9124e843cd05dac5806cc705a9311f3556d5a15f", + "checksum": "121fce2282910c8f0c3ba793a5436b31beb710423cbe2d574a3fb7a73c508e92", "scope": "compile", - "resolved": "https://repo.maven.apache.org/maven2/org/apache/commons/commons-text/1.12.0/commons-text-1.12.0.jar", - "selectedVersion": "1.12.0", + "resolved": "https://repo.maven.apache.org/maven2/org/apache/commons/commons-text/1.14.0/commons-text-1.14.0.jar", + "selectedVersion": "1.14.0", "included": true, - "id": "org.apache.commons:commons-text:1.12.0", - "parent": "org.apache.commons:commons-configuration2:2.11.0", + "id": "org.apache.commons:commons-text:1.14.0", + "parent": "org.apache.commons:commons-configuration2:2.13.0", "children": [ { "groupId": "org.apache.commons", "artifactId": "commons-lang3", - "version": "3.14.0", + "version": "3.18.0", "checksumAlgorithm": "SHA-256", - "checksum": "7b96bf3ee68949abb5bc465559ac270e0551596fa34523fddf890ec418dde13c", + "checksum": "4eeeae8d20c078abb64b015ec158add383ac581571cddc45c68f0c9ae0230720", "scope": "compile", - "resolved": "https://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3/3.14.0/commons-lang3-3.14.0.jar", - "selectedVersion": "3.14.0", + "resolved": "https://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3/3.18.0/commons-lang3-3.18.0.jar", + "selectedVersion": "3.20.0", "included": false, - "id": "org.apache.commons:commons-lang3:3.14.0", - "parent": "org.apache.commons:commons-text:1.12.0", + "id": "org.apache.commons:commons-lang3:3.18.0", + "parent": "org.apache.commons:commons-text:1.14.0", "children": [] } ] @@ -837,7 +837,7 @@ "checksum": "daddea1ea0be0f56978ab3006b8ac92834afeefbd9b7e4e6316fca57df0fa636", "scope": "compile", "resolved": "https://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.2/commons-logging-1.2.jar", - "selectedVersion": "1.3.2", + "selectedVersion": "1.3.5", "included": false, "id": "commons-logging:commons-logging:1.2", "parent": "org.apache.httpcomponents:httpclient:4.5.14", @@ -1287,4 +1287,4 @@ "checksumAlgorithm": "SHA-256" } } -} \ No newline at end of file +} From dff706f0a48511e44fefdc8a46d6631c008b5dfb Mon Sep 17 00:00:00 2001 From: Tanmay Rustagi Date: Mon, 30 Mar 2026 18:59:53 +0200 Subject: [PATCH 3/5] Revert lockfile.json to main state Signed-off-by: Tanmay Rustagi --- databricks-sdk-java/lockfile.json | 62 +++++++++++++++---------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/databricks-sdk-java/lockfile.json b/databricks-sdk-java/lockfile.json index d9ab2d94c..8ba1d918d 100644 --- a/databricks-sdk-java/lockfile.json +++ b/databricks-sdk-java/lockfile.json @@ -735,68 +735,68 @@ { "groupId": "org.apache.commons", "artifactId": "commons-configuration2", - "version": "2.13.0", + "version": "2.11.0", "checksumAlgorithm": "SHA-256", - "checksum": "7622799663317f95c81019b32b39e0c82e42b388f00abe6e5ab26489d90d9a6b", + "checksum": "48957fc3a0d9fbd221fe4f5ff6d0294ce6646ea139793c36706703da59402683", "scope": "compile", - "resolved": "https://repo.maven.apache.org/maven2/org/apache/commons/commons-configuration2/2.13.0/commons-configuration2-2.13.0.jar", - "selectedVersion": "2.13.0", + "resolved": "https://repo.maven.apache.org/maven2/org/apache/commons/commons-configuration2/2.11.0/commons-configuration2-2.11.0.jar", + "selectedVersion": "2.11.0", "included": true, - "id": "org.apache.commons:commons-configuration2:2.13.0", + "id": "org.apache.commons:commons-configuration2:2.11.0", "children": [ { "groupId": "commons-logging", "artifactId": "commons-logging", - "version": "1.3.5", + "version": "1.3.2", "checksumAlgorithm": "SHA-256", - "checksum": "6d7a744e4027649fbb50895df9497d109f98c766a637062fe8d2eabbb3140ba4", + "checksum": "6b858424f518015f32bfcd1183a373f4a827d72d026b6031da0c91cf0e8f3489", "scope": "compile", - "resolved": "https://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.3.5/commons-logging-1.3.5.jar", - "selectedVersion": "1.3.5", + "resolved": "https://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.3.2/commons-logging-1.3.2.jar", + "selectedVersion": "1.3.2", "included": true, - "id": "commons-logging:commons-logging:1.3.5", - "parent": "org.apache.commons:commons-configuration2:2.13.0", + "id": "commons-logging:commons-logging:1.3.2", + "parent": "org.apache.commons:commons-configuration2:2.11.0", "children": [] }, { "groupId": "org.apache.commons", "artifactId": "commons-lang3", - "version": "3.20.0", + "version": "3.14.0", "checksumAlgorithm": "SHA-256", - "checksum": "69e5c9fa35da7a51a5fd2099dfe56a2d8d32cf233e2f6d770e796146440263f4", + "checksum": "7b96bf3ee68949abb5bc465559ac270e0551596fa34523fddf890ec418dde13c", "scope": "compile", - "resolved": "https://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3/3.20.0/commons-lang3-3.20.0.jar", - "selectedVersion": "3.20.0", + "resolved": "https://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3/3.14.0/commons-lang3-3.14.0.jar", + "selectedVersion": "3.14.0", "included": true, - "id": "org.apache.commons:commons-lang3:3.20.0", - "parent": "org.apache.commons:commons-configuration2:2.13.0", + "id": "org.apache.commons:commons-lang3:3.14.0", + "parent": "org.apache.commons:commons-configuration2:2.11.0", "children": [] }, { "groupId": "org.apache.commons", "artifactId": "commons-text", - "version": "1.14.0", + "version": "1.12.0", "checksumAlgorithm": "SHA-256", - "checksum": "121fce2282910c8f0c3ba793a5436b31beb710423cbe2d574a3fb7a73c508e92", + "checksum": "de023257ff166044a56bd1aa9124e843cd05dac5806cc705a9311f3556d5a15f", "scope": "compile", - "resolved": "https://repo.maven.apache.org/maven2/org/apache/commons/commons-text/1.14.0/commons-text-1.14.0.jar", - "selectedVersion": "1.14.0", + "resolved": "https://repo.maven.apache.org/maven2/org/apache/commons/commons-text/1.12.0/commons-text-1.12.0.jar", + "selectedVersion": "1.12.0", "included": true, - "id": "org.apache.commons:commons-text:1.14.0", - "parent": "org.apache.commons:commons-configuration2:2.13.0", + "id": "org.apache.commons:commons-text:1.12.0", + "parent": "org.apache.commons:commons-configuration2:2.11.0", "children": [ { "groupId": "org.apache.commons", "artifactId": "commons-lang3", - "version": "3.18.0", + "version": "3.14.0", "checksumAlgorithm": "SHA-256", - "checksum": "4eeeae8d20c078abb64b015ec158add383ac581571cddc45c68f0c9ae0230720", + "checksum": "7b96bf3ee68949abb5bc465559ac270e0551596fa34523fddf890ec418dde13c", "scope": "compile", - "resolved": "https://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3/3.18.0/commons-lang3-3.18.0.jar", - "selectedVersion": "3.20.0", + "resolved": "https://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3/3.14.0/commons-lang3-3.14.0.jar", + "selectedVersion": "3.14.0", "included": false, - "id": "org.apache.commons:commons-lang3:3.18.0", - "parent": "org.apache.commons:commons-text:1.14.0", + "id": "org.apache.commons:commons-lang3:3.14.0", + "parent": "org.apache.commons:commons-text:1.12.0", "children": [] } ] @@ -837,7 +837,7 @@ "checksum": "daddea1ea0be0f56978ab3006b8ac92834afeefbd9b7e4e6316fca57df0fa636", "scope": "compile", "resolved": "https://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.2/commons-logging-1.2.jar", - "selectedVersion": "1.3.5", + "selectedVersion": "1.3.2", "included": false, "id": "commons-logging:commons-logging:1.2", "parent": "org.apache.httpcomponents:httpclient:4.5.14", @@ -1287,4 +1287,4 @@ "checksumAlgorithm": "SHA-256" } } -} +} \ No newline at end of file From acb210f0ef7e22aa26904899d3c4fd755eeeebef Mon Sep 17 00:00:00 2001 From: Tanmay Rustagi Date: Mon, 30 Mar 2026 16:58:22 +0200 Subject: [PATCH 4/5] Resolve TokenAudience from default_oidc_audience in host metadata Signed-off-by: Tanmay Rustagi --- .../databricks/sdk/core/DatabricksConfig.java | 11 ++- .../sdk/core/oauth/HostMetadata.java | 7 ++ .../sdk/core/DatabricksConfigTest.java | 92 +++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java index 35e93fd28..a946373aa 100644 --- a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java @@ -931,8 +931,17 @@ void resolveHostMetadata() throws IOException { discoveryUrl = oidcUri.resolve(".well-known/oauth-authorization-server").toString(); LOG.debug("Resolved discovery_url from host metadata: \"{}\"", discoveryUrl); } - // For account hosts, use the accountId as the token audience if not already set. + if (tokenAudience == null + && meta.getDefaultOidcAudience() != null + && !meta.getDefaultOidcAudience().isEmpty()) { + LOG.debug( + "Resolved token_audience from host metadata default_oidc_audience: \"{}\"", + meta.getDefaultOidcAudience()); + tokenAudience = meta.getDefaultOidcAudience(); + } + // Fallback: for account hosts, use the accountId as the token audience if not already set. if (tokenAudience == null && getClientType() == ClientType.ACCOUNT && accountId != null) { + LOG.debug("Setting token_audience to account_id for account host: \"{}\"", accountId); tokenAudience = accountId; } } diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/HostMetadata.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/HostMetadata.java index dfbf91fa5..0fe5a15ef 100644 --- a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/HostMetadata.java +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/HostMetadata.java @@ -26,6 +26,9 @@ public class HostMetadata { @JsonProperty("host_type") private String hostType; + @JsonProperty("default_oidc_audience") + private String defaultOidcAudience; + public HostMetadata() {} public HostMetadata(String oidcEndpoint, String accountId, String workspaceId) { @@ -60,4 +63,8 @@ public String getCloud() { public String getHostType() { return hostType; } + + public String getDefaultOidcAudience() { + return defaultOidcAudience; + } } diff --git a/databricks-sdk-java/src/test/java/com/databricks/sdk/core/DatabricksConfigTest.java b/databricks-sdk-java/src/test/java/com/databricks/sdk/core/DatabricksConfigTest.java index b2a83392f..70081a790 100644 --- a/databricks-sdk-java/src/test/java/com/databricks/sdk/core/DatabricksConfigTest.java +++ b/databricks-sdk-java/src/test/java/com/databricks/sdk/core/DatabricksConfigTest.java @@ -800,6 +800,98 @@ public void testResolveHostMetadataHostTypeUnified() throws IOException { } } + // --- resolveHostMetadata default_oidc_audience tests --- + + @Test + public void testResolveHostMetadataSetsTokenAudienceFromDefaultOidcAudience() throws IOException { + String response = + "{\"oidc_endpoint\":\"https://ws.databricks.com/oidc\"," + + "\"account_id\":\"" + + DUMMY_ACCOUNT_ID + + "\"," + + "\"default_oidc_audience\":\"https://ws.databricks.com/oidc/v1/token\"}"; + try (FixtureServer server = + new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) { + DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl()); + config.resolve(emptyEnv()); + config.resolveHostMetadata(); + assertEquals("https://ws.databricks.com/oidc/v1/token", config.getTokenAudience()); + } + } + + @Test + public void testResolveHostMetadataDefaultOidcAudiencePriorityOverAccountIdFallback() + throws IOException { + // default_oidc_audience should take priority over the account_id fallback for account hosts + String response = + "{\"oidc_endpoint\":\"https://acc.databricks.com/oidc/accounts/{account_id}\"," + + "\"account_id\":\"" + + DUMMY_ACCOUNT_ID + + "\"," + + "\"default_oidc_audience\":\"custom-audience\"}"; + try (FixtureServer server = + new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) { + DatabricksConfig config = + new DatabricksConfig() + .setHost(server.getUrl()) + .setExperimentalIsUnifiedHost(true) + .setAccountId(DUMMY_ACCOUNT_ID); + // Note: need two fixtures — resolve() consumes first one (unified host triggers + // tryResolveHostMetadata) + // Instead, don't set unified — just test direct call + config = new DatabricksConfig().setHost(server.getUrl()).setAccountId(DUMMY_ACCOUNT_ID); + config.resolve(emptyEnv()); + config.resolveHostMetadata(); + // Should use default_oidc_audience, NOT account_id + assertEquals("custom-audience", config.getTokenAudience()); + } + } + + @Test + public void testResolveHostMetadataDoesNotOverrideExistingTokenAudienceWithOidcAudience() + throws IOException { + String response = + "{\"oidc_endpoint\":\"https://ws.databricks.com/oidc\"," + + "\"account_id\":\"" + + DUMMY_ACCOUNT_ID + + "\"," + + "\"default_oidc_audience\":\"metadata-audience\"}"; + try (FixtureServer server = + new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) { + DatabricksConfig config = + new DatabricksConfig().setHost(server.getUrl()).setTokenAudience("existing-audience"); + config.resolve(emptyEnv()); + config.resolveHostMetadata(); + assertEquals("existing-audience", config.getTokenAudience()); + } + } + + @Test + public void testResolveHostMetadataFallsBackToAccountIdWhenNoDefaultOidcAudience() + throws IOException { + // When no default_oidc_audience, should fall back to account_id for account hosts. + // Use unified host flag so getClientType() returns ACCOUNT (no workspaceId). + String response = + "{\"oidc_endpoint\":\"https://acc.databricks.com/oidc/accounts/{account_id}\"," + + "\"account_id\":\"" + + DUMMY_ACCOUNT_ID + + "\"}"; + try (FixtureServer server = + new FixtureServer() + .with("GET", "/.well-known/databricks-config", response, 200) + .with("GET", "/.well-known/databricks-config", response, 200)) { + DatabricksConfig config = + new DatabricksConfig() + .setHost(server.getUrl()) + .setAccountId(DUMMY_ACCOUNT_ID) + .setExperimentalIsUnifiedHost(true); + config.resolve(emptyEnv()); + // resolve() with unified flag triggers tryResolveHostMetadata() consuming first fixture. + // Now call again with second fixture to verify account_id fallback. + assertEquals(DUMMY_ACCOUNT_ID, config.getTokenAudience()); + } + } + // --- discoveryUrl / OIDC endpoint tests --- @Test From 6b1ed72b84fe5a6468972e7f05a34068ba66fa98 Mon Sep 17 00:00:00 2001 From: Tanmay Rustagi Date: Mon, 30 Mar 2026 16:59:49 +0200 Subject: [PATCH 5/5] Use resolved host type from host metadata in getHostType() Signed-off-by: Tanmay Rustagi --- .../databricks/sdk/core/DatabricksConfig.java | 9 ++- .../databricks/sdk/core/UnifiedHostTest.java | 67 +++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java index a946373aa..44d1dae64 100644 --- a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java @@ -775,8 +775,15 @@ public boolean isAccountClient() { return host.startsWith("https://accounts.") || host.startsWith("https://accounts-dod."); } - /** Returns the host type based on configuration settings and host URL. */ + /** + * Returns the host type based on configuration settings and host URL. When host metadata has been + * resolved (via /.well-known/databricks-config), the resolved host type is returned directly. + * Otherwise, the host type is inferred from URL patterns as a fallback. + */ public HostType getHostType() { + if (resolvedHostType != null) { + return resolvedHostType; + } if (experimentalIsUnifiedHost != null && experimentalIsUnifiedHost) { return HostType.UNIFIED; } diff --git a/databricks-sdk-java/src/test/java/com/databricks/sdk/core/UnifiedHostTest.java b/databricks-sdk-java/src/test/java/com/databricks/sdk/core/UnifiedHostTest.java index f282b51d8..caed880cd 100644 --- a/databricks-sdk-java/src/test/java/com/databricks/sdk/core/UnifiedHostTest.java +++ b/databricks-sdk-java/src/test/java/com/databricks/sdk/core/UnifiedHostTest.java @@ -231,4 +231,71 @@ public void testNoHeaderInjectionForTraditionalWorkspace() { assertEquals("Bearer test-token", headers.get("Authorization")); assertNull(headers.get("X-Databricks-Org-Id")); } + + // --- Resolved host type from metadata tests --- + + @Test + public void testMetadataWorkspaceOverridesAccountLikeUrl() { + DatabricksConfig config = + new DatabricksConfig() + .setHost("https://accounts.cloud.databricks.com") + .setResolvedHostType(HostType.WORKSPACE); + assertEquals(HostType.WORKSPACE, config.getHostType()); + } + + @Test + public void testMetadataAccountOverridesWorkspaceLikeUrl() { + DatabricksConfig config = + new DatabricksConfig() + .setHost("https://my-workspace.cloud.databricks.com") + .setResolvedHostType(HostType.ACCOUNTS); + assertEquals(HostType.ACCOUNTS, config.getHostType()); + } + + @Test + public void testMetadataUnifiedIsReturned() { + DatabricksConfig config = + new DatabricksConfig() + .setHost("https://my-workspace.cloud.databricks.com") + .setResolvedHostType(HostType.UNIFIED); + assertEquals(HostType.UNIFIED, config.getHostType()); + } + + @Test + public void testFallsBackToUrlMatchingWhenResolvedHostTypeNull() { + DatabricksConfig config = + new DatabricksConfig().setHost("https://accounts.cloud.databricks.com"); + // resolvedHostType is null by default + assertEquals(HostType.ACCOUNTS, config.getHostType()); + } + + @Test + public void testMetadataOverridesExperimentalFlag() { + DatabricksConfig config = + new DatabricksConfig() + .setHost("https://my-workspace.cloud.databricks.com") + .setExperimentalIsUnifiedHost(true) + .setResolvedHostType(HostType.ACCOUNTS); + // Resolved host type takes priority over experimental flag + assertEquals(HostType.ACCOUNTS, config.getHostType()); + } + + @Test + public void testEndToEndResolveToGetHostType() throws IOException { + String response = + "{\"oidc_endpoint\":\"https://ws.databricks.com/oidc\"," + + "\"account_id\":\"test-account\"," + + "\"host_type\":\"unified\"}"; + try (FixtureServer server = + new FixtureServer() + .with("GET", "/.well-known/databricks-config", response, 200) + .with("GET", "/.well-known/databricks-config", response, 200)) { + DatabricksConfig config = + new DatabricksConfig().setHost(server.getUrl()).setExperimentalIsUnifiedHost(true); + config.resolve( + new Environment(new HashMap<>(), new ArrayList<>(), System.getProperty("os.name"))); + // After resolve(), tryResolveHostMetadata() should have set resolvedHostType + assertEquals(HostType.UNIFIED, config.getHostType()); + } + } }