-
Notifications
You must be signed in to change notification settings - Fork 168
Honor [__settings__].default_profile in api, bundle, and auth token #5214
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
89c86fd
Honor [__settings__].default_profile in api, bundle, and auth token
janniklasrose 2111378
Address Cursor review: clarify changelog and use .test TLD in fixture
janniklasrose 9243426
Add regression test for bundle workspace.profile vs default_profile
janniklasrose 6ed2973
Move workspace.profile regression test from unit to acceptance
janniklasrose 81d9297
Fix acceptance sethome to export an absolute HOME
janniklasrose f893006
Regenerate acceptance outputs after sethome HOME fix
janniklasrose adb452f
Fix acceptance sethome USERPROFILE on Git Bash (Windows)
janniklasrose c0760c1
Revert sethome absolute-path fix and regenerated outputs
janniklasrose 9934998
Merge branch 'main' into janniklasrose/auth-default-profile
janniklasrose File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| bundle: | ||
| name: test-default-profile | ||
|
|
||
| # No workspace.host on purpose: this is the surface where | ||
| # [__settings__].default_profile should be applied. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
|
|
||
| === Bundle without workspace.host: default_profile is honored | ||
|
|
||
| >>> [CLI] bundle validate -o json | ||
| { | ||
| "host": null, | ||
| "profile": "default-target" | ||
| } | ||
|
|
||
| === --profile overrides default_profile (negative case) | ||
|
|
||
| >>> errcode [CLI] bundle validate -p other -o json | ||
| Warn: [hostmetadata] failed to fetch host metadata for https://other.test, will skip for 1m0s | ||
| Error: Get "https://other.test/api/2.0/preview/scim/v2/Me": (redacted) | ||
|
|
||
|
|
||
| Exit code: 1 | ||
| { | ||
| "host": null, | ||
| "profile": "other" | ||
| } | ||
|
|
||
| === Bundle with workspace.host: default_profile is NOT applied | ||
|
|
||
| >>> errcode [CLI] bundle validate -o json | ||
| Error: failed during request visitor: default auth: 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. Config: host=[DATABRICKS_URL], workspace_id=[NUMID], databricks_cli_path=[CLI]. Env: DATABRICKS_CLI_PATH | ||
|
|
||
|
|
||
| Exit code: 1 | ||
| { | ||
| "host": "[DATABRICKS_URL]", | ||
| "profile": null | ||
| } | ||
|
|
||
| === Bundle with workspace.profile: pinned profile wins over default_profile | ||
|
|
||
| >>> errcode [CLI] bundle validate -o json | ||
| Error: failed during request visitor: default auth: 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. Config: profile=other, databricks_cli_path=[CLI]. Env: DATABRICKS_CLI_PATH | ||
|
|
||
|
|
||
| Exit code: 1 | ||
| { | ||
| "host": null, | ||
| "profile": "other" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| sethome "./home" | ||
|
|
||
| # Save the test server host so we can pin a bundle-with-host variant below. | ||
| host_value="$DATABRICKS_HOST" | ||
|
|
||
| cat > "./home/.databrickscfg" <<EOF | ||
| [default-target] | ||
| host = $DATABRICKS_HOST | ||
| token = $DATABRICKS_TOKEN | ||
|
|
||
| [other] | ||
| host = https://other.test | ||
| token = other-token | ||
|
|
||
| [__settings__] | ||
| default_profile = default-target | ||
| EOF | ||
|
|
||
| unset DATABRICKS_HOST | ||
| unset DATABRICKS_TOKEN | ||
| unset DATABRICKS_CONFIG_PROFILE | ||
|
|
||
| title "Bundle without workspace.host: default_profile is honored\n" | ||
| trace $CLI bundle validate -o json | jq '{host: .workspace.host, profile: .workspace.profile}' | ||
|
|
||
| title "--profile overrides default_profile (negative case)\n" | ||
| trace errcode $CLI bundle validate -p other -o json | jq '{host: .workspace.host, profile: .workspace.profile}' | ||
|
|
||
| # Switch to a bundle that pins workspace.host. The default_profile guard in | ||
| # configureProfile must NOT apply default_profile here, because that would | ||
| # silently route the user to a profile pointing at a different host than the | ||
| # bundle declares. | ||
| mkdir -p ./bundle-with-host | ||
| cat > ./bundle-with-host/databricks.yml <<EOF | ||
| bundle: | ||
| name: bundle-with-host | ||
|
|
||
| workspace: | ||
| host: $host_value | ||
| EOF | ||
|
|
||
| title "Bundle with workspace.host: default_profile is NOT applied\n" | ||
| (cd ./bundle-with-host && trace errcode $CLI bundle validate -o json | jq '{host: .workspace.host, profile: .workspace.profile}') | ||
|
|
||
| # Switch to a bundle that pins workspace.profile but no host. The pinned | ||
| # profile must win over default_profile — configureProfile's guard skips | ||
| # default_profile when workspace.profile is already set. | ||
| mkdir -p ./bundle-with-profile | ||
| cat > ./bundle-with-profile/databricks.yml <<EOF | ||
| bundle: | ||
| name: bundle-with-profile | ||
|
|
||
| workspace: | ||
| profile: other | ||
| EOF | ||
|
|
||
| title "Bundle with workspace.profile: pinned profile wins over default_profile\n" | ||
| (cd ./bundle-with-profile && trace errcode $CLI bundle validate -o json | jq '{host: .workspace.host, profile: .workspace.profile}') | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| Ignore = [ | ||
| "home", | ||
| ".databricks", | ||
| "bundle-with-host", | ||
| "bundle-with-profile", | ||
| ] | ||
|
|
||
| # Negative case: -p other tries to reach a non-existing host. Redact the | ||
| # OS-/network-dependent suffix so the test is stable across runners. | ||
| [[Repls]] | ||
| Old = 'Get "https://other.test/api/2.0/preview/scim/v2/Me": .*' | ||
| New = 'Get "https://other.test/api/2.0/preview/scim/v2/Me": (redacted)' |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
|
|
||
| === default_profile is used when no --profile flag and no DATABRICKS_CONFIG_PROFILE | ||
|
|
||
| >>> [CLI] api get /api/2.0/clusters/list | ||
| {} | ||
|
|
||
| >>> print_requests.py --get //api/2.0/clusters/list | ||
| { | ||
| "headers": { | ||
| "Authorization": [ | ||
| "Bearer [DATABRICKS_TOKEN]" | ||
| ], | ||
| "User-Agent": [ | ||
| "cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_get cmd-exec-id/[UUID] interactive/none auth/pat" | ||
| ], | ||
| "X-Databricks-Org-Id": [ | ||
| "[NUMID]" | ||
| ] | ||
| }, | ||
| "method": "GET", | ||
| "path": "/api/2.0/clusters/list" | ||
| } | ||
|
|
||
| === --profile overrides default_profile (negative case) | ||
| Warn: [hostmetadata] failed to fetch host metadata for https://other.test, will skip for 1m0s | ||
| Error: Get "https://other.test/api/2.0/clusters/list": (redacted) | ||
|
|
||
| Exit code: 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| sethome "./home" | ||
|
|
||
| # Two profiles plus an explicit default_profile pointing at the test server. | ||
| # The 'other' profile points at an RFC 2606 reserved host so we can assert | ||
| # that --profile overrides default_profile without making a real request. | ||
| cat > "./home/.databrickscfg" <<EOF | ||
| [default-target] | ||
| host = $DATABRICKS_HOST | ||
| token = $DATABRICKS_TOKEN | ||
|
|
||
| [other] | ||
| host = https://other.test | ||
| token = other-token | ||
|
|
||
| [__settings__] | ||
| default_profile = default-target | ||
| EOF | ||
|
|
||
| unset DATABRICKS_HOST | ||
| unset DATABRICKS_TOKEN | ||
| unset DATABRICKS_CONFIG_PROFILE | ||
|
|
||
| title "default_profile is used when no --profile flag and no DATABRICKS_CONFIG_PROFILE\n" | ||
| MSYS_NO_PATHCONV=1 trace $CLI api get /api/2.0/clusters/list | ||
| trace print_requests.py --get //api/2.0/clusters/list | contains.py "X-Databricks-Org-Id" | ||
|
|
||
| title "--profile overrides default_profile (negative case)\n" | ||
| MSYS_NO_PATHCONV=1 errcode $CLI api get /api/2.0/clusters/list -p other 2>&1 | contains.py "other.test" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| Ignore = [ | ||
| "home", | ||
| ] | ||
|
|
||
| # Redact the OS- and network-dependent suffix on the failed lookup so the | ||
| # negative case (--profile overrides default_profile) is stable across | ||
| # runners. We still assert the requested host appears in output. | ||
| [[Repls]] | ||
| Old = 'Get "https://other.test/api/2.0/clusters/list": .*' | ||
| New = 'Get "https://other.test/api/2.0/clusters/list": (redacted)' |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
| === default_profile is honored when no args, --profile, or env var | ||
|
|
||
| >>> errcode [CLI] auth token | ||
| Warn: [hostmetadata] failed to fetch host metadata for https://myworkspace.test, will skip for 1m0s | ||
| Error: cache: databricks OAuth is not configured for this host. Try logging in again with `databricks auth login --profile myprofile` 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 | ||
|
|
||
| === default_profile pointing at a missing profile falls through to picker | ||
|
|
||
| >>> errcode [CLI] auth token | ||
| Error: no profile specified. Use --profile <name> to specify which profile to use | ||
|
|
||
| Exit code: 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| sethome "./home" | ||
|
|
||
| unset DATABRICKS_HOST | ||
| unset DATABRICKS_TOKEN | ||
| unset DATABRICKS_CONFIG_PROFILE | ||
|
|
||
| # default_profile points at "myprofile". Without it, `auth token` would fall | ||
| # through to the non-interactive error "no profile specified". | ||
| cat > "./home/.databrickscfg" <<'ENDCFG' | ||
| [myprofile] | ||
| host = https://myworkspace.test | ||
| auth_type = databricks-cli | ||
|
|
||
| [other] | ||
| host = https://other.test | ||
| auth_type = databricks-cli | ||
|
|
||
| [__settings__] | ||
| default_profile = myprofile | ||
| ENDCFG | ||
|
|
||
| title "default_profile is honored when no args, --profile, or env var\n" | ||
| trace errcode $CLI auth token | ||
|
|
||
| title "default_profile pointing at a missing profile falls through to picker\n" | ||
| cat > "./home/.databrickscfg" <<'ENDCFG' | ||
| [myprofile] | ||
| host = https://myworkspace.test | ||
| auth_type = databricks-cli | ||
|
|
||
| [__settings__] | ||
| default_profile = does-not-exist | ||
| ENDCFG | ||
| trace errcode $CLI auth token |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re: #5266
I now see why it fails. But I think these shouldn't be inlined but be
databricks.yml.ZZZ.tmplfiles withenvsubstor even different tests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, will split
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in #5270