Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### CLI

* Fix "cache: token not found" for auth token command ([#3447](https://github.com/databricks/cli/pull/3447))

### Bundles
* Add support for Lakebase database instances in DABs ([#3283](https://github.com/databricks/cli/pull/3283))
* Improve error message for SDK/API errors ([#3379](https://github.com/databricks/cli/pull/3379))
Expand Down
5 changes: 5 additions & 0 deletions acceptance/cmd/auth/token/out.test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Local = true
Cloud = false

[EnvMatrix]
DATABRICKS_CLI_DEPLOYMENT = ["terraform", "direct-exp"]
5 changes: 5 additions & 0 deletions acceptance/cmd/auth/token/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

>>> [CLI] auth token --host [DATABRICKS_URL]
Error: cache: databricks OAuth is not configured for this host. Try logging in again with `databricks auth login --host [DATABRICKS_URL]` before retrying. If this fails, please report this issue to the Databricks CLI maintainers at https://github.com/databricks/cli/issues/new

Exit code: 1
13 changes: 13 additions & 0 deletions acceptance/cmd/auth/token/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mkdir -p home
export HOME="$PWD/home"

export DATABRICKS_HOST_ORIG="$DATABRICKS_HOST"
export DATABRICKS_TOKEN_ORIG="$DATABRICKS_TOKEN"

unset DATABRICKS_HOST
unset DATABRICKS_TOKEN

# This is expected to fail because there is no token cache.
# We need to assert that the returned error message does not change,
# because older SDK versions check for a particular substring.
trace $CLI auth token --host $DATABRICKS_HOST_ORIG
3 changes: 3 additions & 0 deletions acceptance/cmd/auth/token/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Ignore = [
"home"
]
13 changes: 13 additions & 0 deletions cmd/auth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/databricks/cli/libs/auth"
"github.com/databricks/cli/libs/databrickscfg/profile"
"github.com/databricks/databricks-sdk-go/credentials/u2m"
"github.com/databricks/databricks-sdk-go/credentials/u2m/cache"
"github.com/spf13/cobra"
"golang.org/x/oauth2"
)
Expand Down Expand Up @@ -116,6 +117,18 @@ func loadToken(ctx context.Context, args loadTokenArgs) (*oauth2.Token, error) {
}
t, err := persistentAuth.Token()
if err != nil {
if errors.Is(err, cache.ErrNotFound) {
// The error returned by the SDK when the token cache doesn't exist or doesn't contain a token
// for the given host changed in SDK v0.77.0: https://github.com/databricks/databricks-sdk-go/pull/1250.
// This was released as part of CLI v0.264.0.
//
// Older SDK versions check for a particular substring to determine if
// the OAuth authentication type can fall through or if it is a real error.
// This means we need to keep this error message constant for backwards compatibility.
//
// This is captured in an acceptance test under "cmd/auth/token".
err = errors.New("cache: databricks OAuth is not configured for this host")
}
if err, ok := auth.RewriteAuthError(ctx, args.authArguments.Host, args.authArguments.AccountID, args.profileName, err); ok {
return nil, err
}
Expand Down
Loading