Skip to content

Commit 81124ed

Browse files
committed
Refactor configuration
1 parent 192a771 commit 81124ed

File tree

4 files changed

+31
-94
lines changed

4 files changed

+31
-94
lines changed

conf.gen.go

Lines changed: 0 additions & 92 deletions
This file was deleted.

pkg/config/conf.gen.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/schema.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,58 @@ import (
88
)
99

1010
var (
11+
AccountHostnameField = field.StringField(
12+
"account-hostname",
13+
field.WithDescription("The hostname used to connect to the Databricks account API. If not set, it will be calculated from the hostname field."),
14+
field.WithDisplayName("Account Hostname"),
15+
)
1116
AccountIdField = field.StringField(
1217
"account-id",
1318
field.WithDescription("The Databricks account ID used to connect to the Databricks Account and Workspace API"),
1419
field.WithRequired(true),
20+
field.WithDisplayName("Account ID"),
1521
)
1622
HostnameField = field.StringField(
1723
"hostname",
1824
field.WithDescription("The Databricks hostname used to connect to the Databricks API"),
1925
field.WithDefaultValue("cloud.databricks.com"),
26+
field.WithDisplayName("Hostname"),
2027
)
2128
DatabricksClientIdField = field.StringField(
2229
"databricks-client-id",
2330
field.WithDescription("The Databricks service principal's client ID used to connect to the Databricks Account and Workspace API"),
31+
field.WithDisplayName("Databricks Client ID"),
2432
)
2533
DatabricksClientSecretField = field.StringField(
2634
"databricks-client-secret",
2735
field.WithDescription("The Databricks service principal's client secret used to connect to the Databricks Account and Workspace API"),
2836
field.WithIsSecret(true),
37+
field.WithDisplayName("Databricks Client Secret"),
2938
)
3039
UsernameField = field.StringField(
3140
"username",
3241
field.WithDescription("The Databricks username used to connect to the Databricks API"),
42+
field.WithDisplayName("Username"),
3343
)
3444
PasswordField = field.StringField(
3545
"password",
3646
field.WithDescription("The Databricks password used to connect to the Databricks API"),
3747
field.WithIsSecret(true),
48+
field.WithDisplayName("Password"),
3849
)
3950
WorkspacesField = field.StringSliceField(
4051
"workspaces",
4152
field.WithDescription("Limit syncing to the specified workspaces"),
53+
field.WithDisplayName("Workspaces"),
4254
)
4355
TokensField = field.StringSliceField(
4456
"workspace-tokens",
4557
field.WithDescription("The Databricks access tokens scoped to specific workspaces used to connect to the Databricks Workspace API"),
4658
field.WithIsSecret(true),
59+
field.WithDisplayName("Workspace Tokens"),
4760
)
4861
configFields = []field.SchemaField{
62+
AccountHostnameField,
4963
AccountIdField,
5064
DatabricksClientIdField,
5165
DatabricksClientSecretField,
@@ -90,6 +104,7 @@ var (
90104
DatabricksClientIdField,
91105
DatabricksClientSecretField,
92106
HostnameField,
107+
AccountHostnameField,
93108
},
94109
Default: true,
95110
},
@@ -102,6 +117,7 @@ var (
102117
TokensField,
103118
WorkspacesField,
104119
HostnameField,
120+
AccountHostnameField,
105121
},
106122
Default: false,
107123
},
@@ -114,6 +130,7 @@ var (
114130
UsernameField,
115131
PasswordField,
116132
HostnameField,
133+
AccountHostnameField,
117134
},
118135
Default: false,
119136
},
@@ -125,6 +142,9 @@ var Config = field.NewConfiguration(
125142
configFields,
126143
field.WithConstraints(fieldRelationships...),
127144
field.WithFieldGroups(fieldGroups),
145+
field.WithConnectorDisplayName("Databricks"),
146+
field.WithHelpUrl("/docs/baton/databricks"),
147+
field.WithIconUrl("/static/app-icons/databricks.svg"),
128148
)
129149

130150
// ValidateConfig - additional validations that cannot be encoded in relationships (yet!)

pkg/connector/connector.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func NewConnector(ctx context.Context, cfg *config.Databricks, opts *cli.Connect
224224
}
225225

226226
hostname := getHostname(cfg)
227-
accountHostname := databricks.GetAccountHostname(hostname)
227+
accountHostname := getAccountHostname(cfg, hostname)
228228
auth := prepareClientAuth(ctx, cfg, l)
229229

230230
cb, err := New(
@@ -256,7 +256,7 @@ func prepareClientAuth(_ context.Context, cfg *config.Databricks, l *zap.Logger)
256256
password := cfg.Password
257257
workspaces := cfg.Workspaces
258258
tokens := cfg.WorkspaceTokens
259-
accountHostname := databricks.GetAccountHostname(getHostname(cfg))
259+
accountHostname := getAccountHostname(cfg, getHostname(cfg))
260260

261261
switch {
262262
case username != "" && password != "":
@@ -311,3 +311,11 @@ func getHostname(cfg *config.Databricks) string {
311311
}
312312
return cfg.Hostname
313313
}
314+
315+
// getAccountHostname returns the account hostname from config if set, otherwise calculates it from hostname.
316+
func getAccountHostname(cfg *config.Databricks, hostname string) string {
317+
if cfg.AccountHostname != "" {
318+
return cfg.AccountHostname
319+
}
320+
return databricks.GetAccountHostname(hostname)
321+
}

0 commit comments

Comments
 (0)