Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,7 @@ public String authType() {
List<String> buildHostArgs(String cliPath, DatabricksConfig config) {
List<String> cmd =
new ArrayList<>(Arrays.asList(cliPath, "auth", "token", "--host", config.getHost()));
if (config.getExperimentalIsUnifiedHost() != null && config.getExperimentalIsUnifiedHost()) {
// For unified hosts, pass account_id, workspace_id, and experimental flag
cmd.add("--experimental-is-unified-host");
if (config.getAccountId() != null) {
cmd.add("--account-id");
cmd.add(config.getAccountId());
}
if (config.getWorkspaceId() != null) {
cmd.add("--workspace-id");
cmd.add(config.getWorkspaceId());
}
} else if (config.getClientType() == ClientType.ACCOUNT) {
if (config.getClientType() == ClientType.ACCOUNT) {
cmd.add("--account-id");
cmd.add(config.getAccountId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,6 @@ public synchronized Map<String, String> authenticate() throws DatabricksExceptio
}
Map<String, String> headers = new HashMap<>(headerFactory.headers());

// For unified hosts with workspace operations, add the X-Databricks-Org-Id header
if (getHostType() == HostType.UNIFIED && workspaceId != null && !workspaceId.isEmpty()) {
headers.put("X-Databricks-Org-Id", workspaceId);
}

return headers;
} catch (DatabricksException e) {
String msg = String.format("%s auth: %s", credentialsProvider.authType(), e.getMessage());
Expand Down Expand Up @@ -732,23 +727,14 @@ public boolean isAws() {
}

public boolean isAccountClient() {
if (getHostType() == HostType.UNIFIED) {
throw new DatabricksException(
"Cannot determine account client status for unified hosts. "
+ "Use getHostType() or getClientType() instead. "
+ "For unified hosts, client type depends on whether workspaceId is set.");
}
if (host == null) {
return false;
}
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 the host URL pattern. */
public HostType getHostType() {
if (experimentalIsUnifiedHost != null && experimentalIsUnifiedHost) {
return HostType.UNIFIED;
}
if (host == null) {
return HostType.WORKSPACE;
}
Expand All @@ -758,15 +744,10 @@ public HostType getHostType() {
return HostType.WORKSPACE;
}

/** Returns the client type based on host type and workspace ID configuration. */
/** Returns the client type based on host type. */
public ClientType getClientType() {
HostType hostType = getHostType();
switch (hostType) {
case UNIFIED:
// For unified hosts, client type depends on whether workspaceId is set
return (workspaceId != null && !workspaceId.isEmpty())
? ClientType.WORKSPACE
: ClientType.ACCOUNT;
case ACCOUNTS:
return ClientType.ACCOUNT;
case WORKSPACE:
Expand Down Expand Up @@ -903,24 +884,11 @@ private OpenIDConnectEndpoints fetchOidcEndpointsFromDiscovery() {
return null;
}

private OpenIDConnectEndpoints getUnifiedOidcEndpoints(String accountId) throws IOException {
if (accountId == null || accountId.isEmpty()) {
throw new DatabricksException(
"account_id is required for unified host OIDC endpoint discovery");
}
String prefix = getHost() + "/oidc/accounts/" + accountId;
return new OpenIDConnectEndpoints(prefix + "/v1/token", prefix + "/v1/authorize");
}

private OpenIDConnectEndpoints fetchDefaultOidcEndpoints() throws IOException {
if (getHost() == null) {
return null;
}

// For unified hosts, use account-based OIDC endpoints
if (getHostType() == HostType.UNIFIED) {
return getUnifiedOidcEndpoints(getAccountId());
}
if (isAccountClient() && getAccountId() != null) {
String prefix = getHost() + "/oidc/accounts/" + getAccountId();
return new OpenIDConnectEndpoints(prefix + "/v1/token", prefix + "/v1/authorize");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ public enum HostType {
WORKSPACE,

/** Traditional accounts host. */
ACCOUNTS,

/** Unified host supporting both workspace and account operations. */
UNIFIED
ACCOUNTS
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static org.junit.jupiter.api.Assertions.*;

import com.databricks.sdk.core.ClientType;
import com.databricks.sdk.core.DatabricksConfig;
import com.databricks.sdk.core.HostType;
import com.databricks.sdk.service.provisioning.Workspace;
Expand Down Expand Up @@ -49,28 +48,14 @@ public void testGetWorkspaceClientForUnifiedHost() {

WorkspaceClient workspaceClient = accountClient.getWorkspaceClient(workspace);

// Should have the same host
// Should have the same host (unified hosts reuse the same host)
assertEquals(unifiedHost, workspaceClient.config().getHost());

// Should have workspace ID set
assertEquals("123456", workspaceClient.config().getWorkspaceId());

// Should be workspace client type (on unified host)
assertEquals(ClientType.WORKSPACE, workspaceClient.config().getClientType());

// Host type should still be unified
assertEquals(HostType.UNIFIED, workspaceClient.config().getHostType());
}

@Test
public void testGetWorkspaceClientForUnifiedHostType() {
// Verify unified host type is correctly detected
DatabricksConfig config =
new DatabricksConfig()
.setHost("https://unified.databricks.com")
.setExperimentalIsUnifiedHost(true);

assertEquals(HostType.UNIFIED, config.getHostType());
// Host type is WORKSPACE (determined from URL pattern, not unified flag)
assertEquals(HostType.WORKSPACE, workspaceClient.config().getHostType());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class DatabricksCliCredentialsProviderTest {
private static final String CLI_PATH = "/usr/local/bin/databricks";
private static final String HOST = "https://my-workspace.cloud.databricks.com";
private static final String ACCOUNT_HOST = "https://accounts.cloud.databricks.com";
private static final String UNIFIED_HOST = "https://unified.databricks.com";
private static final String ACCOUNT_ID = "test-account-123";
private static final String WORKSPACE_ID = "987654321";

private final DatabricksCliCredentialsProvider provider = new DatabricksCliCredentialsProvider();

Expand All @@ -39,104 +37,12 @@ void testBuildHostArgs_AccountHost() {
}

@Test
void testBuildHostArgs_UnifiedHost_WithAccountIdAndWorkspaceId() {
DatabricksConfig config =
new DatabricksConfig()
.setHost(UNIFIED_HOST)
.setExperimentalIsUnifiedHost(true)
.setAccountId(ACCOUNT_ID)
.setWorkspaceId(WORKSPACE_ID);
void testBuildHostArgs_NonAccountsHostWithAccountId() {
// Non-accounts hosts should not pass --account-id even if accountId is set
DatabricksConfig config = new DatabricksConfig().setHost(HOST).setAccountId(ACCOUNT_ID);

List<String> cmd = provider.buildHostArgs(CLI_PATH, config);

assertEquals(
Arrays.asList(
CLI_PATH,
"auth",
"token",
"--host",
UNIFIED_HOST,
"--experimental-is-unified-host",
"--account-id",
ACCOUNT_ID,
"--workspace-id",
WORKSPACE_ID),
cmd);
}

@Test
void testBuildHostArgs_UnifiedHost_WithAccountIdOnly() {
DatabricksConfig config =
new DatabricksConfig()
.setHost(UNIFIED_HOST)
.setExperimentalIsUnifiedHost(true)
.setAccountId(ACCOUNT_ID);

List<String> cmd = provider.buildHostArgs(CLI_PATH, config);

assertEquals(
Arrays.asList(
CLI_PATH,
"auth",
"token",
"--host",
UNIFIED_HOST,
"--experimental-is-unified-host",
"--account-id",
ACCOUNT_ID),
cmd);
}

@Test
void testBuildHostArgs_UnifiedHost_WithWorkspaceIdOnly() {
DatabricksConfig config =
new DatabricksConfig()
.setHost(UNIFIED_HOST)
.setExperimentalIsUnifiedHost(true)
.setWorkspaceId(WORKSPACE_ID);

List<String> cmd = provider.buildHostArgs(CLI_PATH, config);

assertEquals(
Arrays.asList(
CLI_PATH,
"auth",
"token",
"--host",
UNIFIED_HOST,
"--experimental-is-unified-host",
"--workspace-id",
WORKSPACE_ID),
cmd);
}

@Test
void testBuildHostArgs_UnifiedHost_WithNoAccountIdOrWorkspaceId() {
DatabricksConfig config =
new DatabricksConfig().setHost(UNIFIED_HOST).setExperimentalIsUnifiedHost(true);

List<String> cmd = provider.buildHostArgs(CLI_PATH, config);

assertEquals(
Arrays.asList(
CLI_PATH, "auth", "token", "--host", UNIFIED_HOST, "--experimental-is-unified-host"),
cmd);
}

@Test
void testBuildHostArgs_UnifiedHostFalse_WithAccountHost() {
// When experimentalIsUnifiedHost is explicitly false, should fall back to account-id logic
DatabricksConfig config =
new DatabricksConfig()
.setHost(ACCOUNT_HOST)
.setExperimentalIsUnifiedHost(false)
.setAccountId(ACCOUNT_ID);

List<String> cmd = provider.buildHostArgs(CLI_PATH, config);

assertEquals(
Arrays.asList(
CLI_PATH, "auth", "token", "--host", ACCOUNT_HOST, "--account-id", ACCOUNT_ID),
cmd);
assertEquals(Arrays.asList(CLI_PATH, "auth", "token", "--host", HOST), cmd);
}
}
Loading
Loading