Skip to content

Commit 63bb1c0

Browse files
committed
remove clientType mutation from config
1 parent e2a76fe commit 63bb1c0

8 files changed

Lines changed: 26 additions & 40 deletions

File tree

account_client.go

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

client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010
"golang.org/x/oauth2"
1111
)
1212

13-
func New(cfg *config.Config) (*DatabricksClient, error) {
13+
func New(cfg *config.Config, isWorkspaceClient bool) (*DatabricksClient, error) {
1414
err := cfg.EnsureResolved()
1515
if err != nil {
1616
return nil, err
1717
}
18-
clientCfg, err := config.HTTPClientConfigFromConfig(cfg)
18+
clientCfg, err := config.HTTPClientConfigFromConfig(cfg, isWorkspaceClient)
1919
if err != nil {
2020
return nil, err
2121
}

config/api_client.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,21 @@ import (
1818
// with the workspace ID to all requests made by workspace clients
1919
func workspaceOrgIdVisitor(cfg *Config) func(r *http.Request) error {
2020
return func(r *http.Request) error {
21-
if cfg.GetClientType() == WorkspaceClient && cfg.WorkspaceId != "" {
21+
if cfg.WorkspaceId != "" {
2222
r.Header.Set("X-Databricks-Org-Id", cfg.WorkspaceId)
2323
}
2424
return nil
2525
}
2626
}
2727

28-
func HTTPClientConfigFromConfig(cfg *Config) (httpclient.ClientConfig, error) {
28+
// noopVisitor creates a visitor that does nothing
29+
func noopVisitor() func(r *http.Request) error {
30+
return func(r *http.Request) error {
31+
return nil
32+
}
33+
}
34+
35+
func HTTPClientConfigFromConfig(cfg *Config, isWorkspaceClient bool) (httpclient.ClientConfig, error) {
2936
if skippable, ok := cfg.HTTPTransport.(interface {
3037
SkipRetryOnIO() bool
3138
}); ok && skippable.SkipRetryOnIO() {
@@ -85,7 +92,12 @@ func HTTPClientConfigFromConfig(cfg *Config) (httpclient.ClientConfig, error) {
8592
*r = *r.WithContext(ctx) // replace request
8693
return nil
8794
},
88-
workspaceOrgIdVisitor(cfg),
95+
func() httpclient.RequestVisitor {
96+
if isWorkspaceClient {
97+
return workspaceOrgIdVisitor(cfg)
98+
}
99+
return noopVisitor()
100+
}(),
89101
},
90102
TransientErrors: []string{
91103
// This is temporary workaround for SCIM API returning 500.
@@ -119,8 +131,8 @@ func (noopAuth) Configure(context.Context, *Config) (credentials.CredentialsProv
119131
}
120132

121133
// Deprecated: use [HTTPClientConfigFromConfig] with [httpclient.NewApiClient].
122-
func (c *Config) NewApiClient() (*httpclient.ApiClient, error) {
123-
cfg, err := HTTPClientConfigFromConfig(c)
134+
func (c *Config) NewApiClient(isWorkspaceClient bool) (*httpclient.ApiClient, error) {
135+
cfg, err := HTTPClientConfigFromConfig(c, isWorkspaceClient)
124136
if err != nil {
125137
return nil, err
126138
}

config/auth_azure_msi.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ func (c AzureMsiCredentials) Configure(ctx context.Context, cfg *Config) (creden
3636
return nil, nil
3737
}
3838
env := cfg.Environment()
39-
if cfg.GetClientType() == WorkspaceClient {
40-
err := cfg.azureEnsureWorkspaceUrl(ctx, c)
41-
if err != nil {
42-
return nil, fmt.Errorf("resolve host: %w", err)
43-
}
39+
err := cfg.azureEnsureWorkspaceUrl(ctx, c)
40+
if err != nil {
41+
return nil, fmt.Errorf("resolve host: %w", err)
4442
}
4543
logger.Debugf(ctx, "Generating AAD token via Azure MSI")
4644
inner := azureReuseTokenSource(nil, c.tokenSourceFor(ctx, cfg, "", env.AzureApplicationID))

config/auth_gcp_google_id.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ func (c GoogleDefaultCredentials) Configure(ctx context.Context, cfg *Config) (c
2828
if err != nil {
2929
return nil, err
3030
}
31-
if cfg.GetClientType() == WorkspaceClient {
32-
logger.Infof(ctx, "Using Google Default Application Credentials for Workspace")
33-
visitor := refreshableVisitor(inner)
34-
return credentials.CredentialsProviderFn(visitor), nil
35-
}
3631
// source for generateAccessToken
3732
platform, err := impersonate.CredentialsTokenSource(ctx, impersonate.CredentialsConfig{
3833
TargetPrincipal: cfg.GoogleServiceAccount,
@@ -44,7 +39,7 @@ func (c GoogleDefaultCredentials) Configure(ctx context.Context, cfg *Config) (c
4439
if err != nil {
4540
return nil, err
4641
}
47-
logger.Infof(ctx, "Using Google Default Application Credentials for Accounts API")
42+
logger.Infof(ctx, "Using Google Default Application Credentials")
4843
visitor := serviceToServiceVisitor(inner, platform, "X-Databricks-GCP-SA-Access-Token")
4944
return credentials.NewOAuthCredentialsProvider(visitor, inner.Token), nil
5045
}

config/config.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ type Loader interface {
3939
Configure(*Config) error
4040
}
4141

42-
type ClientTypeEnum string
43-
44-
const WorkspaceClient ClientTypeEnum = `WORKSPACE_CLIENT`
45-
const AccountClient ClientTypeEnum = `ACCOUNT_CLIENT`
46-
4742
type HostTypeEnum string
4843

4944
const WorkspaceHost HostTypeEnum = `WORKSPACE_HOST`
@@ -309,18 +304,6 @@ func (c *Config) IsAws() bool {
309304
return c.Host != "" && !c.IsAzure() && !c.IsGcp()
310305
}
311306

312-
// GetClientType returns one of WORKSPACE_CLIENT or ACCOUNT_CLIENT
313-
func (c *Config) GetClientType() ClientTypeEnum {
314-
// TODO: Implement this so it relies on a flag in Config that we set when
315-
// we create the client
316-
return c.clientType
317-
}
318-
319-
// SetClientType sets the client type to one of WORKSPACE_CLIENT or ACCOUNT_CLIENT
320-
func (c *Config) SetClientType(clientType ClientTypeEnum) {
321-
c.clientType = clientType
322-
}
323-
324307
// GetHostType returns one of WORKSPACE_HOST, ACCOUNT_HOST, or UNIFIED HOST
325308
func (c *Config) GetHostType() HostTypeEnum {
326309
if c.isUnifiedHost {

config/oauth_visitors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
// serviceToServiceVisitor returns a visitor that sets the Authorization header
15-
// to the token from the auth token sourcevand the provided secondary header to
15+
// to the token from the auth token source and the provided secondary header to
1616
// the token from the secondary token source.
1717
func serviceToServiceVisitor(primary, secondary oauth2.TokenSource, secondaryHeader string) func(r *http.Request) error {
1818
refreshableAuth := auth.NewCachedTokenSource(authconv.AuthTokenSource(primary))

workspace_client.go

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

0 commit comments

Comments
 (0)