Skip to content

Commit

Permalink
[Fix] DatabricksConfig: newWithWorkspaceHost should retain authType (#…
Browse files Browse the repository at this point in the history
…338)

## Changes
* New DatabricksConfig() object should retain auth type as its reusing
the existing authentication mechanism. This is how its done in the Py
and Go SDK

## Tests
* Added unit test
  • Loading branch information
satviksr-db committed Aug 30, 2024
1 parent e00d328 commit 248d0bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,6 @@ public DatabricksConfig newWithWorkspaceHost(String host) {
// For cloud-native OAuth, we need to reauthenticate as the audience has changed, so
// don't cache the
// header factory.
"authType",
"headerFactory"));
DatabricksConfig newConfig = new DatabricksConfig();
for (Field f : DatabricksConfig.class.getDeclaredFields()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,24 @@ public void testDiscoveryEndpoint() throws IOException {
assertEquals(oidcEndpoints.getTokenEndpoint(), "https://test.auth.endpoint/oidc/v1/token");
}
}

@Test
public void testNewWithWorkspaceHost() {
DatabricksConfig config =
new DatabricksConfig()
.setAuthType("oauth-m2m")
.setClientId("my-client-id")
.setClientSecret("my-client-secret")
.setAccountId("account-id")
.setHost("https://account.cloud.databricks.com");
String workspaceHost = "https://workspace.cloud.databricks.com";

DatabricksConfig newWorkspaceConfig = config.newWithWorkspaceHost(workspaceHost).resolve();

assert newWorkspaceConfig.getHost().equals(workspaceHost);
assert newWorkspaceConfig.getAuthType().equals("oauth-m2m");
assert newWorkspaceConfig.getClientId().equals("my-client-id");
assert newWorkspaceConfig.getClientSecret().equals("my-client-secret");
assert newWorkspaceConfig.getAccountId() == null;
}
}

0 comments on commit 248d0bb

Please sign in to comment.