Skip to content

Commit 69a0215

Browse files
committed
Add example code
1 parent 5203e57 commit 69a0215

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.databricks.sdk.examples;
2+
3+
import com.databricks.sdk.core.DatabricksConfig;
4+
import com.databricks.sdk.service.workspace.WorkspaceClient;
5+
6+
/**
7+
* Example demonstrating how to use GitHub OIDC authentication with Databricks.
8+
*
9+
* This example assumes you have:
10+
* 1. A Databricks workspace
11+
* 2. A service principal configured with GitHub OIDC federation
12+
* 3. The following environment variables set:
13+
* - DATABRICKS_HOST: Your Databricks workspace URL
14+
* - DATABRICKS_CLIENT_ID: Your service principal's client ID
15+
* - ACTIONS_ID_TOKEN_REQUEST_URL: GitHub Actions token request URL
16+
* - ACTIONS_ID_TOKEN_REQUEST_TOKEN: GitHub Actions token request token
17+
*/
18+
public class GithubOIDCAuthExample {
19+
public static void main(String[] args) {
20+
// Create Databricks configuration with GitHub OIDC authentication
21+
DatabricksConfig config = new DatabricksConfig()
22+
.setAuthType("github-oidc");
23+
24+
// Create a workspace client
25+
WorkspaceClient workspace = new WorkspaceClient(config);
26+
27+
try {
28+
// Test the authentication by getting the current user
29+
var currentUser = workspace.currentUser().me();
30+
System.out.println("Successfully authenticated as: " + currentUser.getUserName());
31+
32+
// You can add more API calls here to test other functionality
33+
// For example:
34+
// var clusters = workspace.clusters().list();
35+
// System.out.println("Available clusters: " + clusters);
36+
37+
} catch (Exception e) {
38+
System.err.println("Authentication failed: " + e.getMessage());
39+
e.printStackTrace();
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)