diff --git a/acceptance/auth/bundle_default_profile/databricks.yml b/acceptance/auth/bundle_default_profile/databricks.yml.no-host.tmpl similarity index 100% rename from acceptance/auth/bundle_default_profile/databricks.yml rename to acceptance/auth/bundle_default_profile/databricks.yml.no-host.tmpl diff --git a/acceptance/auth/bundle_default_profile/databricks.yml.with-host.tmpl b/acceptance/auth/bundle_default_profile/databricks.yml.with-host.tmpl new file mode 100644 index 00000000000..4c2f0748389 --- /dev/null +++ b/acceptance/auth/bundle_default_profile/databricks.yml.with-host.tmpl @@ -0,0 +1,5 @@ +bundle: + name: bundle-with-host + +workspace: + host: $DATABRICKS_HOST diff --git a/acceptance/auth/bundle_default_profile/databricks.yml.with-profile.tmpl b/acceptance/auth/bundle_default_profile/databricks.yml.with-profile.tmpl new file mode 100644 index 00000000000..18e719f0ea8 --- /dev/null +++ b/acceptance/auth/bundle_default_profile/databricks.yml.with-profile.tmpl @@ -0,0 +1,5 @@ +bundle: + name: bundle-with-profile + +workspace: + profile: other diff --git a/acceptance/auth/bundle_default_profile/output.txt b/acceptance/auth/bundle_default_profile/output.txt index 8a2e034f240..f8e8a3c0062 100644 --- a/acceptance/auth/bundle_default_profile/output.txt +++ b/acceptance/auth/bundle_default_profile/output.txt @@ -23,10 +23,6 @@ Exit code: 1 === 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 @@ -35,7 +31,7 @@ Exit code: 1 === 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 +Error: Get "https://other.test/api/2.0/preview/scim/v2/Me": (redacted) Exit code: 1 diff --git a/acceptance/auth/bundle_default_profile/script b/acceptance/auth/bundle_default_profile/script index 6c54b13c78f..793176c4b52 100644 --- a/acceptance/auth/bundle_default_profile/script +++ b/acceptance/auth/bundle_default_profile/script @@ -20,9 +20,11 @@ unset DATABRICKS_HOST unset DATABRICKS_TOKEN unset DATABRICKS_CONFIG_PROFILE +cp databricks.yml.no-host.tmpl databricks.yml title "Bundle without workspace.host: default_profile is honored\n" trace $CLI bundle validate -o json | jq '{host: .workspace.host, profile: .workspace.profile}' +cp databricks.yml.no-host.tmpl databricks.yml title "--profile overrides default_profile (negative case)\n" trace errcode $CLI bundle validate -p other -o json | jq '{host: .workspace.host, profile: .workspace.profile}' @@ -30,29 +32,13 @@ trace errcode $CLI bundle validate -p other -o json | jq '{host: .workspace.host # 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 < databricks.yml 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}') +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 <>> [CLI] auth describe --profile u2m-profile Warn: [hostmetadata] failed to fetch host metadata for https://u2m-profile.databricks.test, will skip for 1m0s Unable to authenticate: error getting token: cache: token not found -Token storage: plaintext, ~/.databricks/token-cache.json (from auth_storage in [__settings__] section of home/.databrickscfg) +Token storage: plaintext, ~/.databricks/token-cache.json (from auth_storage in [__settings__] section of [TEST_TMP_DIR]/home/.databrickscfg) ----- Current configuration: - ✓ host: https://u2m-profile.databricks.test (from ./home/.databrickscfg config file) + ✓ host: https://u2m-profile.databricks.test (from [TEST_TMP_DIR]/home/.databrickscfg config file) ✓ profile: u2m-profile (from --profile flag) ✓ databricks_cli_path: [CLI] - ✓ auth_type: databricks-cli (from ./home/.databrickscfg config file) + ✓ auth_type: databricks-cli (from [TEST_TMP_DIR]/home/.databrickscfg config file) ✓ rate_limit: [NUMID] (from DATABRICKS_RATE_LIMIT environment variable) diff --git a/acceptance/cmd/auth/describe/u2m-plaintext-default/output.txt b/acceptance/cmd/auth/describe/u2m-plaintext-default/output.txt index 981244ff8d9..004cc787aaa 100644 --- a/acceptance/cmd/auth/describe/u2m-plaintext-default/output.txt +++ b/acceptance/cmd/auth/describe/u2m-plaintext-default/output.txt @@ -5,8 +5,8 @@ Unable to authenticate: error getting token: cache: token not found Token storage: plaintext, ~/.databricks/token-cache.json (from default) ----- Current configuration: - ✓ host: https://u2m-profile.databricks.test (from ./home/.databrickscfg config file) + ✓ host: https://u2m-profile.databricks.test (from [TEST_TMP_DIR]/home/.databrickscfg config file) ✓ profile: u2m-profile (from --profile flag) ✓ databricks_cli_path: [CLI] - ✓ auth_type: databricks-cli (from ./home/.databrickscfg config file) + ✓ auth_type: databricks-cli (from [TEST_TMP_DIR]/home/.databrickscfg config file) ✓ rate_limit: [NUMID] (from DATABRICKS_RATE_LIMIT environment variable) diff --git a/acceptance/cmd/auth/describe/u2m-plaintext-env/output.txt b/acceptance/cmd/auth/describe/u2m-plaintext-env/output.txt index ff36f25245d..edfdc0a1939 100644 --- a/acceptance/cmd/auth/describe/u2m-plaintext-env/output.txt +++ b/acceptance/cmd/auth/describe/u2m-plaintext-env/output.txt @@ -5,8 +5,8 @@ Unable to authenticate: error getting token: cache: token not found Token storage: plaintext, ~/.databricks/token-cache.json (from DATABRICKS_AUTH_STORAGE environment variable) ----- Current configuration: - ✓ host: https://u2m-profile.databricks.test (from ./home/.databrickscfg config file) + ✓ host: https://u2m-profile.databricks.test (from [TEST_TMP_DIR]/home/.databrickscfg config file) ✓ profile: u2m-profile (from --profile flag) ✓ databricks_cli_path: [CLI] - ✓ auth_type: databricks-cli (from ./home/.databrickscfg config file) + ✓ auth_type: databricks-cli (from [TEST_TMP_DIR]/home/.databrickscfg config file) ✓ rate_limit: [NUMID] (from DATABRICKS_RATE_LIMIT environment variable) diff --git a/acceptance/cmd/completion/output.txt b/acceptance/cmd/completion/output.txt index 17ed0f61eb0..d9e58987459 100644 --- a/acceptance/cmd/completion/output.txt +++ b/acceptance/cmd/completion/output.txt @@ -1,34 +1,34 @@ >>> [CLI] completion install --shell zsh --auto-approve Databricks CLI completions installed for zsh. -Restart your shell or run 'source home/.zshrc' to activate. +Restart your shell or run 'source [HOME]/.zshrc' to activate. Warning: zsh completions require the completion system to be initialized. -Add the following to your home/.zshrc: +Add the following to your [HOME]/.zshrc: autoload -U compinit && compinit >>> [CLI] completion status --shell zsh Shell: zsh -File: home/.zshrc +File: [HOME]/.zshrc Status: installed Warning: zsh completions require the completion system to be initialized. -Add the following to your home/.zshrc: +Add the following to your [HOME]/.zshrc: autoload -U compinit && compinit >>> [CLI] completion install --shell zsh --auto-approve -Databricks CLI completions are already installed for zsh in home/.zshrc. +Databricks CLI completions are already installed for zsh in [HOME]/.zshrc. Warning: zsh completions require the completion system to be initialized. -Add the following to your home/.zshrc: +Add the following to your [HOME]/.zshrc: autoload -U compinit && compinit >>> [CLI] completion uninstall --shell zsh --auto-approve -Databricks CLI completions removed for zsh from home/.zshrc. +Databricks CLI completions removed for zsh from [HOME]/.zshrc. >>> [CLI] completion status --shell zsh Shell: zsh -File: home/.zshrc +File: [HOME]/.zshrc Status: not installed # bash completion V2 for databricks -*- shell-script -*- #compdef databricks diff --git a/acceptance/script.prepare b/acceptance/script.prepare index b158ca3c74e..a8ea942bb46 100644 --- a/acceptance/script.prepare +++ b/acceptance/script.prepare @@ -101,6 +101,25 @@ sethome() { local home="$1" mkdir -p "$home" + # Resolve to an absolute path so HOME (and USERPROFILE) keep pointing at + # the same directory after the test cd's elsewhere. The SDK expands + # `~/.databrickscfg` against $HOME at lookup time; with a relative path + # the cfg silently disappears once the cwd changes, and helpers like + # databrickscfg.GetConfiguredDefaultProfile return "" instead of + # erroring. + # + # On Git Bash (MSYS), plain `pwd` returns Unix-style /c/... paths that + # the native Windows Go binary can't open; `pwd -W` returns the mixed + # C:/... form instead. Use the same form for both HOME and USERPROFILE + # so tests that compare a `$HOME`-based placeholder against the CLI's + # `os.UserHomeDir()` output (which reads USERPROFILE on Windows) find + # a match. + if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then + home="$(cd "$home" && pwd -W)" + else + home="$(cd "$home" && pwd)" + fi + # For macOS and Linux, use HOME. export HOME="$home"