Skip to content

Commit 2b9394b

Browse files
[Internal] Add example for workspace unified authentication (#320)
## Changes This PR adds an extremely simple example to show how to use workspace unified authentication. This example is meant to be used by external CI scripts that rely on examples to run integration tests.
1 parent c04f58a commit 2b9394b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.databricks.example;
2+
3+
import com.databricks.sdk.WorkspaceClient;
4+
import com.databricks.sdk.core.DatabricksConfig;
5+
import com.databricks.sdk.service.compute.ClusterDetails;
6+
import com.databricks.sdk.service.compute.ListClustersRequest;
7+
8+
/**
9+
Example for authenticating with Databricks Workspace through Databricks' Unified Authentication. Unified
10+
Authentication takes care of inspecting your environment to determine the best way to authenticate.
11+
12+
<p>
13+
For more details, please see <a href="https://docs.databricks.com/en/dev-tools/sdk-java.html#authenticate-the-databricks-sdk-for-java-with-your-databricks-account-or-workspace">Authenticate with Databricks SDK for Java</a>.
14+
*/
15+
public class UnifiedAuthWorkspace {
16+
/**
17+
Authenticate and retrieve the list of clusters from the workspace
18+
*/
19+
public static void main(String[] args) {
20+
DatabricksConfig config = new DatabricksConfig();
21+
22+
WorkspaceClient workspace = new WorkspaceClient(config);
23+
for (ClusterDetails c : workspace.clusters().list(new ListClustersRequest())) {
24+
System.out.println(c.getClusterName());
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)