Skip to content

Commit 2a0d461

Browse files
authored
Use SDK constant to check if default auth cannot be configured (#2977)
## Changes The SDK bump in #2920 required rewriting an error equivalence check to perform string matching because the constant was removed. It was brought back in databricks/databricks-sdk-go#1226. ## Tests Ran tests under `cmd/root`.
1 parent 8db2e7b commit 2a0d461

File tree

2 files changed

+3
-18
lines changed

2 files changed

+3
-18
lines changed

cmd/labs/project/entrypoint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func (e *Entrypoint) validLogin(cmd *cobra.Command) (*config.Config, error) {
251251
isACC := cfg.IsAccountClient()
252252
if e.IsAccountLevel && cfg.Profile == "" {
253253
if !cmdio.IsPromptSupported(ctx) {
254-
return nil, root.ErrCannotConfigureAuth
254+
return nil, config.ErrCannotConfigureDefault
255255
}
256256
replaceCfg, err := e.envAwareConfig(ctx)
257257
if err != nil {

cmd/root/auth.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"errors"
66
"fmt"
77
"net/http"
8-
"strings"
98

109
"github.com/databricks/cli/libs/auth"
1110
"github.com/databricks/cli/libs/cmdctx"
@@ -34,20 +33,6 @@ func (e ErrNoAccountProfiles) Error() string {
3433
return e.path + " does not contain account profiles"
3534
}
3635

37-
func isCannotConfigureAuth(err error) bool {
38-
// As of SDK v0.70.0, this constant was removed.
39-
//
40-
// return errors.Is(err, config.ErrCannotConfigureAuth)
41-
//
42-
// The prefix check is based on this:
43-
//
44-
// https://github.com/databricks/databricks-sdk-go/commit/ef3a65c6ee8f0de253ce6f554e6d905d6a5fdc85#diff-83d1fd7f94efd3481cd11ebab8065cc81e18ef0d8776097c29b8a183a20df52fR86
45-
return strings.Contains(err.Error(), "cannot configure default credentials, ")
46-
}
47-
48-
// Referenced by cmd/labs/project/entrypoint.go.
49-
var ErrCannotConfigureAuth = errors.New("cannot configure default credentials, please check https://docs.databricks.com/en/dev-tools/auth.html#databricks-client-unified-authentication to configure credentials for your preferred authentication method")
50-
5136
func initProfileFlag(cmd *cobra.Command) {
5237
cmd.PersistentFlags().StringP("profile", "p", "", "~/.databrickscfg profile")
5338
cmd.RegisterFlagCompletionFunc("profile", profile.ProfileCompletion)
@@ -74,7 +59,7 @@ func accountClientOrPrompt(ctx context.Context, cfg *config.Config, allowPrompt
7459
// Prompt to select a profile if the current configuration is not an account client.
7560
prompt = prompt || errors.Is(err, databricks.ErrNotAccountClient)
7661
// Prompt to select a profile if the current configuration doesn't resolve to a credential provider.
77-
prompt = prompt || isCannotConfigureAuth(err)
62+
prompt = prompt || errors.Is(err, config.ErrCannotConfigureDefault)
7863
}
7964

8065
if !prompt {
@@ -174,7 +159,7 @@ func workspaceClientOrPrompt(ctx context.Context, cfg *config.Config, allowPromp
174159
// Prompt to select a profile if the current configuration is not a workspace client.
175160
prompt = prompt || errors.Is(err, databricks.ErrNotWorkspaceClient)
176161
// Prompt to select a profile if the current configuration doesn't resolve to a credential provider.
177-
prompt = prompt || isCannotConfigureAuth(err)
162+
prompt = prompt || errors.Is(err, config.ErrCannotConfigureDefault)
178163
}
179164

180165
if !prompt {

0 commit comments

Comments
 (0)