Skip to content

Commit 5375382

Browse files
Move usage of config struct in auth login (#4310)
## Changes Refactors the `auth login` command to make it clear that the config struct is only needed for making a request to configure clusters when a `--configure-clusters` flag is passed. The request itself is changed from using `databricks-cli` auth type which creates a child CLI process to using the newly minted token directly in a custom auth type. ## Why Reduce confusion about what part of the SDK is used by the CLI in the auth login command. This is being done as a part of an effort to make the `databricks-cli` auth type consistent across the SDKs by having the Go SDK also rely on the CLI's `auth token` command like the Java and Python SDKs. ## Tests - Existing tests for auth login pass. - Added new acceptance tests, generating their outputs by running on main. - Manually tested that passing `--configure-cluster` flag works <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. --> --- NO_CHANGELOG=true --------- Co-authored-by: Renaud Hartert <renaud.hartert@databricks.com>
1 parent bbac3c9 commit 5375382

File tree

16 files changed

+211
-28
lines changed

16 files changed

+211
-28
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified.
2+
[DEFAULT]
3+
4+
[custom-test]
5+
host = [DATABRICKS_URL]
6+
auth_type = databricks-cli

acceptance/cmd/auth/login/custom-config-file/out.test.toml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
=== Initial custom config file (with old host)
3+
[custom-test]
4+
host = https://old-host.cloud.databricks.com
5+
auth_type = pat
6+
token = old-token-123
7+
8+
=== Login with new host (should override old host)
9+
>>> [CLI] auth login --host [DATABRICKS_URL] --profile custom-test
10+
Profile custom-test was successfully saved
11+
12+
=== Default config file should NOT exist
13+
OK: Default .databrickscfg does not exist
14+
15+
=== Custom config file after login (old host should be replaced)
16+
; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified.
17+
[DEFAULT]
18+
19+
[custom-test]
20+
host = [DATABRICKS_URL]
21+
auth_type = databricks-cli
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
sethome "./home"
2+
3+
# Use a fake browser that performs a GET on the authorization URL
4+
# and follows the redirect back to localhost.
5+
export BROWSER="browser.py"
6+
7+
# Set custom config file location via env var
8+
export DATABRICKS_CONFIG_FILE="./home/custom.databrickscfg"
9+
10+
# Create an existing custom config file with a DIFFERENT host.
11+
# The login command should use the host from --host argument, NOT from this file.
12+
# If the wrong host (from the config file) were used, the OAuth flow would fail
13+
# because the mock server only responds for $DATABRICKS_HOST.
14+
cat > "./home/custom.databrickscfg" <<EOF
15+
[custom-test]
16+
host = https://old-host.cloud.databricks.com
17+
auth_type = pat
18+
token = old-token-123
19+
EOF
20+
21+
title "Initial custom config file (with old host)\n"
22+
cat "./home/custom.databrickscfg"
23+
24+
title "Login with new host (should override old host)"
25+
trace $CLI auth login --host $DATABRICKS_HOST --profile custom-test
26+
27+
title "Default config file should NOT exist\n"
28+
if [ -f "./home/.databrickscfg" ]; then
29+
echo "ERROR: Default .databrickscfg exists but should not"
30+
cat "./home/.databrickscfg"
31+
else
32+
echo "OK: Default .databrickscfg does not exist"
33+
fi
34+
35+
title "Custom config file after login (old host should be replaced)\n"
36+
cat "./home/custom.databrickscfg"
37+
38+
# Track the custom config file to surface changes
39+
mv "./home/custom.databrickscfg" "./out.databrickscfg"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Ignore = [
2+
"home"
3+
]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified.
2+
[DEFAULT]
3+
4+
[override-test]
5+
host = [DATABRICKS_URL]
6+
auth_type = databricks-cli

acceptance/cmd/auth/login/host-arg-overrides-profile/out.test.toml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
=== Initial profile with old host
3+
[override-test]
4+
host = https://old-host.cloud.databricks.com
5+
6+
=== Login with positional host argument (should override profile)
7+
>>> [CLI] auth login [DATABRICKS_URL] --profile override-test
8+
Profile override-test was successfully saved
9+
10+
=== Profile after login (host should be updated)
11+
; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified.
12+
[DEFAULT]
13+
14+
[override-test]
15+
host = [DATABRICKS_URL]
16+
auth_type = databricks-cli
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
sethome "./home"
2+
3+
# Create an existing profile with a DIFFERENT host
4+
cat > "./home/.databrickscfg" <<EOF
5+
[override-test]
6+
host = https://old-host.cloud.databricks.com
7+
EOF
8+
9+
title "Initial profile with old host\n"
10+
cat "./home/.databrickscfg"
11+
12+
# Use a fake browser that performs a GET on the authorization URL
13+
# and follows the redirect back to localhost.
14+
export BROWSER="browser.py"
15+
16+
# Login with profile but provide a different host as positional argument
17+
# The positional argument should override the profile's host
18+
title "Login with positional host argument (should override profile)"
19+
trace $CLI auth login $DATABRICKS_HOST --profile override-test
20+
21+
title "Profile after login (host should be updated)\n"
22+
cat "./home/.databrickscfg"
23+
24+
# Track the .databrickscfg file that was created to surface changes.
25+
mv "./home/.databrickscfg" "./out.databrickscfg"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Ignore = [
2+
"home"
3+
]

0 commit comments

Comments
 (0)