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: 1 addition & 1 deletion acceptance/cmd/auth/logout/default-profile/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ host = [DATABRICKS_URL]
auth_type = databricks-cli

=== Delete the DEFAULT profile
>>> [CLI] auth logout --profile DEFAULT --force --delete
>>> [CLI] auth logout --profile DEFAULT --auto-approve --delete
Logged out of and deleted profile "DEFAULT".

=== Backup file should exist
Expand Down
2 changes: 1 addition & 1 deletion acceptance/cmd/auth/logout/default-profile/script
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ title "Initial config\n"
cat "./home/.databrickscfg"

title "Delete the DEFAULT profile"
trace $CLI auth logout --profile DEFAULT --force --delete
trace $CLI auth logout --profile DEFAULT --auto-approve --delete

title "Backup file should exist\n"
assert_backup_exists
Expand Down
4 changes: 2 additions & 2 deletions acceptance/cmd/auth/logout/delete-clears-default/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
default_profile = workspace-a

=== Delete the default profile
>>> [CLI] auth logout --profile workspace-a --force --delete
>>> [CLI] auth logout --profile workspace-a --auto-approve --delete
Deleted profile "workspace-a" with no tokens to clear.

=== Settings after deleting default — default_profile should be cleared
[__settings__]

=== Delete a non-default profile
>>> [CLI] auth logout --profile workspace-b --force --delete
>>> [CLI] auth logout --profile workspace-b --auto-approve --delete
Deleted profile "workspace-b" with no tokens to clear.

=== Settings after deleting non-default — section should still be present but empty
Expand Down
4 changes: 2 additions & 2 deletions acceptance/cmd/auth/logout/delete-clears-default/script
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ title "Initial settings section\n"
cat "./home/.databrickscfg" | grep -A1 __settings__

title "Delete the default profile"
trace $CLI auth logout --profile workspace-a --force --delete
trace $CLI auth logout --profile workspace-a --auto-approve --delete

title "Settings after deleting default — default_profile should be cleared\n"
cat "./home/.databrickscfg" | grep -A1 __settings__

title "Delete a non-default profile"
trace $CLI auth logout --profile workspace-b --force --delete
trace $CLI auth logout --profile workspace-b --auto-approve --delete

title "Settings after deleting non-default — section should still be present but empty\n"
cat "./home/.databrickscfg" | grep -A1 __settings__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ host = https://dev.cloud.databricks.com
token = dev-pat-token

=== Logout without --delete — should report no changes for non-U2M profile
>>> [CLI] auth logout --profile dev --force
>>> [CLI] auth logout --profile dev --auto-approve
No tokens to clear for profile "dev". Use --delete to remove it from the config file.

=== Config after logout — profile should be unchanged
Expand All @@ -20,7 +20,7 @@ host = https://dev.cloud.databricks.com
token = dev-pat-token

=== Logout with --delete — should delete the profile
>>> [CLI] auth logout --profile dev --force --delete
>>> [CLI] auth logout --profile dev --auto-approve --delete
Deleted profile "dev" with no tokens to clear.

=== Backup file should exist
Expand Down
4 changes: 2 additions & 2 deletions acceptance/cmd/auth/logout/delete-pat-token-profile/script
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ title "Initial config\n"
cat "./home/.databrickscfg"

title "Logout without --delete — should report no changes for non-U2M profile"
trace $CLI auth logout --profile dev --force
trace $CLI auth logout --profile dev --auto-approve

title "Config after logout — profile should be unchanged\n"
cat "./home/.databrickscfg"

title "Logout with --delete — should delete the profile"
trace $CLI auth logout --profile dev --force --delete
trace $CLI auth logout --profile dev --auto-approve --delete

title "Backup file should exist\n"
assert_backup_exists
Expand Down
4 changes: 2 additions & 2 deletions acceptance/cmd/auth/logout/error-cases/script
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ auth_type = databricks-cli
EOF

title "Logout of non-existent profile\n"
errcode $CLI auth logout --profile nonexistent --force
errcode $CLI auth logout --profile nonexistent --auto-approve

title "Logout without --profile in non-interactive mode\n"
errcode $CLI auth logout --force
errcode $CLI auth logout --auto-approve
2 changes: 1 addition & 1 deletion acceptance/cmd/auth/logout/last-non-default/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ host = [DATABRICKS_URL]
auth_type = databricks-cli

=== Delete the only non-default profile
>>> [CLI] auth logout --profile only-profile --force --delete
>>> [CLI] auth logout --profile only-profile --auto-approve --delete
Logged out of and deleted profile "only-profile".

=== Backup file should exist
Expand Down
2 changes: 1 addition & 1 deletion acceptance/cmd/auth/logout/last-non-default/script
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ title "Initial config\n"
cat "./home/.databrickscfg"

title "Delete the only non-default profile"
trace $CLI auth logout --profile only-profile --force --delete
trace $CLI auth logout --profile only-profile --auto-approve --delete

title "Backup file should exist\n"
assert_backup_exists
Expand Down
4 changes: 2 additions & 2 deletions acceptance/cmd/auth/logout/ordering-preserved/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ account_id = account-id
auth_type = databricks-cli

=== Delete first non-default profile (alpha)
>>> [CLI] auth logout --profile alpha --force --delete
>>> [CLI] auth logout --profile alpha --auto-approve --delete
Logged out of and deleted profile "alpha".

=== Backup file should exist
Expand All @@ -46,7 +46,7 @@ account_id = account-id
auth_type = databricks-cli

=== Delete last profile (gamma)
>>> [CLI] auth logout --profile gamma --force --delete
>>> [CLI] auth logout --profile gamma --auto-approve --delete
Logged out of and deleted profile "gamma".

=== Config after deleting gamma
Expand Down
4 changes: 2 additions & 2 deletions acceptance/cmd/auth/logout/ordering-preserved/script
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ title "Initial config\n"
cat "./home/.databrickscfg"

title "Delete first non-default profile (alpha)"
trace $CLI auth logout --profile alpha --force --delete
trace $CLI auth logout --profile alpha --auto-approve --delete

title "Backup file should exist\n"
assert_backup_exists
Expand All @@ -36,7 +36,7 @@ title "Config after deleting alpha\n"
cat "./home/.databrickscfg"

title "Delete last profile (gamma)"
trace $CLI auth logout --profile gamma --force --delete
trace $CLI auth logout --profile gamma --auto-approve --delete

title "Config after deleting gamma\n"
cat "./home/.databrickscfg"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ logfood (Default) [DATABRICKS_URL] YES
]

=== Logout without --delete
>>> [CLI] auth logout --profile logfood --force
>>> [CLI] auth logout --profile logfood --auto-approve
Logged out of profile "logfood". Use --delete to also remove it from the config file.

=== Config after logout — profile should still exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ title "Token cache keys before logout\n"
jq -S '.tokens | keys' "./home/.databricks/token-cache.json"

title "Logout without --delete"
trace $CLI auth logout --profile logfood --force
trace $CLI auth logout --profile logfood --auto-approve

title "Config after logout — profile should still exist\n"
cat "./home/.databrickscfg"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
]

=== Logout dev without --delete
>>> [CLI] auth logout --profile dev --force
>>> [CLI] auth logout --profile dev --auto-approve
Logged out of profile "dev". Use --delete to also remove it from the config file.

=== Config after logout — both profiles should still exist
Expand Down
2 changes: 1 addition & 1 deletion acceptance/cmd/auth/logout/token-only-shared-host/script
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ title "Token cache keys before logout\n"
jq -S '.tokens | keys' "./home/.databricks/token-cache.json"

title "Logout dev without --delete"
trace $CLI auth logout --profile dev --force
trace $CLI auth logout --profile dev --auto-approve

title "Config after logout — both profiles should still exist\n"
cat "./home/.databrickscfg"
Expand Down
2 changes: 1 addition & 1 deletion acceptance/cmd/auth/logout/token-only/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
]

=== Logout without --delete
>>> [CLI] auth logout --profile dev --force
>>> [CLI] auth logout --profile dev --auto-approve
Logged out of profile "dev". Use --delete to also remove it from the config file.

=== Config after logout — profile should still exist
Expand Down
2 changes: 1 addition & 1 deletion acceptance/cmd/auth/logout/token-only/script
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ title "Token cache keys before logout\n"
jq -S '.tokens | keys' "./home/.databricks/token-cache.json"

title "Logout without --delete"
trace $CLI auth logout --profile dev --force
trace $CLI auth logout --profile dev --auto-approve

title "Config after logout — profile should still exist\n"
cat "./home/.databrickscfg"
Expand Down
18 changes: 9 additions & 9 deletions cmd/auth/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,26 @@ the profile is an error.

1. If you specify a profile (via argument or --profile), the command logs
out of that profile. In an interactive terminal you'll be asked to
confirm unless --force is set.
confirm unless --auto-approve is set.

2. If you omit the profile in an interactive terminal, you'll be shown
an interactive picker listing all profiles from your configuration file.
You can search by profile name, host, or account ID. After selecting a
profile, you'll be asked to confirm unless --force is specified.
profile, you'll be asked to confirm unless --auto-approve is specified.

3. If you omit the profile in a non-interactive environment (e.g. CI/CD
pipeline), the command will fail with an error asking you to specify
a profile.

4. Use --force to skip the confirmation prompt. This is required when
4. Use --auto-approve to skip the confirmation prompt. This is required when
running in non-interactive environments.

5. Use --delete to also remove the selected profile from ~/.databrickscfg.`,
}

var force bool
var autoApprove bool
var deleteProfile bool
cmd.Flags().BoolVar(&force, "force", false, "Skip confirmation prompt")
cmd.Flags().BoolVar(&autoApprove, "auto-approve", false, "Skip confirmation prompt")
cmd.Flags().BoolVar(&deleteProfile, "delete", false, "Delete the profile from the config file")

cmd.RunE = func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -127,7 +127,7 @@ the profile is an error.

return runLogout(ctx, logoutArgs{
profileName: profileName,
force: force,
autoApprove: autoApprove,
deleteProfile: deleteProfile,
profiler: profiler,
tokenCache: tokenCache,
Expand All @@ -140,7 +140,7 @@ the profile is an error.

type logoutArgs struct {
profileName string
force bool
autoApprove bool
deleteProfile bool
profiler profile.Profiler
tokenCache cache.TokenCache
Expand All @@ -153,9 +153,9 @@ func runLogout(ctx context.Context, args logoutArgs) error {
return err
}

if !args.force {
if !args.autoApprove {
if !cmdio.IsPromptSupported(ctx) {
return errors.New("please specify --force to skip confirmation in non-interactive mode")
return errors.New("please specify --auto-approve to skip confirmation in non-interactive mode")
}

configPath, err := args.profiler.GetPath(ctx)
Expand Down
Loading
Loading