Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix azure databricks + docs #15

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ to work with only specified workspaces and their respective tokens. You can
provide multiple tokens by separating them with a comma. This method requires
admin access to each workspace you want to sync.

# Using Azure Databricks

To work with Azure Databricks, you need to provide the hostname flag.

```bash
baton-databricks --hostname "azuredatabricks.net"
```

# Getting Started

## brew
Expand Down Expand Up @@ -113,13 +121,15 @@ Available Commands:
help Help about any command

Flags:
--account-hostname string The hostname used to connect to the Databricks account API ($BATON_ACCOUNT_HOSTNAME)
--account-id string required: The Databricks account ID used to connect to the Databricks Account and Workspace API ($BATON_ACCOUNT_ID)
--client-id string The client ID used to authenticate with ConductorOne ($BATON_CLIENT_ID)
--client-secret string The client secret used to authenticate with ConductorOne ($BATON_CLIENT_SECRET)
--databricks-client-id string The Databricks service principal's client ID used to connect to the Databricks Account and Workspace API ($BATON_DATABRICKS_CLIENT_ID)
--databricks-client-secret string The Databricks service principal's client secret used to connect to the Databricks Account and Workspace API ($BATON_DATABRICKS_CLIENT_SECRET)
-f, --file string The path to the c1z file to sync with ($BATON_FILE) (default "sync.c1z")
-h, --help help for baton-databricks
--hostname string The Databricks hostname used to connect to the Databricks API ($BATON_HOSTNAME) (default "cloud.databricks.com")
--log-format string The output format for logs: json, console ($BATON_LOG_FORMAT) (default "json")
--log-level string The log level: debug, info, warn, error ($BATON_LOG_LEVEL) (default "info")
--password string The Databricks password used to connect to the Databricks API ($BATON_PASSWORD)
Expand Down
7 changes: 4 additions & 3 deletions cmd/baton-databricks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func prepareClientAuth(ctx context.Context, cfg *viper.Viper) databricks.Auth {
password := cfg.GetString(config.PasswordField.FieldName)
workspaces := cfg.GetStringSlice(config.WorkspacesField.FieldName)
tokens := cfg.GetStringSlice(config.TokensField.FieldName)
accountHostname := databricks.GetAccountHostname(cfg)

switch {
case username != "" && password != "":
Expand All @@ -81,6 +82,7 @@ func prepareClientAuth(ctx context.Context, cfg *viper.Viper) databricks.Auth {
accountID,
databricksClientId,
databricksClientSecret,
accountHostname,
)
return cAuth
case AreTokensSet(workspaces, tokens):
Expand All @@ -106,9 +108,8 @@ func getConnector(ctx context.Context, cfg *viper.Viper) (types.ConnectorServer,
return nil, err
}

hostname := cfg.GetString(config.HostnameField.FieldName)
accountHostname := cfg.GetString(config.AccountHostnameField.FieldName)

hostname := databricks.GetHostname(cfg)
accountHostname := databricks.GetAccountHostname(cfg)
auth := prepareClientAuth(ctx, cfg)
cb, err := connector.New(
ctx,
Expand Down
1 change: 0 additions & 1 deletion pkg/config/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var (
AccountHostnameField = field.StringField(
"account-hostname",
field.WithDescription("The hostname used to connect to the Databricks account API"),
field.WithDefaultValue("accounts.cloud.databricks.com"),
)
AccountIdField = field.StringField(
"account-id",
Expand Down
4 changes: 2 additions & 2 deletions pkg/databricks/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ type OAuth2 struct {
cfg *clientcredentials.Config
}

func NewOAuth2(accId, clientId, clientSecret string) *OAuth2 {
func NewOAuth2(accId, clientId, clientSecret, accountHostname string) *OAuth2 {
return &OAuth2{
cfg: &clientcredentials.Config{
ClientID: clientId,
ClientSecret: clientSecret,
TokenURL: fmt.Sprintf("https://accounts.cloud.databricks.com/oidc/accounts/%s/v1/token", accId),
TokenURL: fmt.Sprintf("https://%s/oidc/accounts/%s/v1/token", accountHostname, accId),
Scopes: []string{"all-apis"},
},
}
Expand Down
23 changes: 16 additions & 7 deletions pkg/databricks/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"net/http"
"net/url"

"github.com/conductorone/baton-databricks/pkg/config"
v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
"github.com/conductorone/baton-sdk/pkg/uhttp"
"github.com/spf13/viper"
)

const (
Expand Down Expand Up @@ -42,18 +44,25 @@ type Client struct {
isWSAPIAvailable bool
}

func NewClient(ctx context.Context, httpClient *http.Client, hostname, accountHostname, accountID string, auth Auth) (*Client, error) {
if hostname == "" {
hostname = defaultHost
func GetHostname(cfg *viper.Viper) string {
if cfg.GetString(config.HostnameField.FieldName) == "" {
return defaultHost
}
return cfg.GetString(config.HostnameField.FieldName)
}

func GetAccountHostname(cfg *viper.Viper) string {
if cfg.GetString(config.AccountHostnameField.FieldName) == "" {
return "accounts." + GetHostname(cfg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work for Azure or GCP, as the hostname provided will be something like 8757561887652360.0.gcp.databricks.com or adb-5555555555555555.19.azuredatabricks.net, but the account hostnames for those need to be accounts.gcp.databricks.com and accounts.azuredatabricks.net respectively. Prepending "accounts" to the hostnames will result in accounts.8757561887652360.0.gcp.databricks.com and accounts.adb-5555555555555555.19.azuredatabricks.net, which isn't correct.

Copy link
Contributor

@btipling btipling Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ggreer Isn't that solved by just using account-hostname ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but we should change the behavior to detect GCP and Azure hostnames and return correct account hostnames for them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ggreer I made this change 7de4791

}
return cfg.GetString(config.AccountHostnameField.FieldName)
}

func NewClient(ctx context.Context, httpClient *http.Client, hostname, accountHostname, accountID string, auth Auth) (*Client, error) {
baseUrl := &url.URL{
Scheme: "https",
Host: hostname,
}

if accountHostname == "" {
accountHostname = "accounts." + defaultHost
}
accountBaseUrl := &url.URL{
Scheme: "https",
Host: accountHostname,
Expand Down
Loading