Add databricks auth switch command for setting the default profile#4651
Open
simonfaltum wants to merge 7 commits intomainfrom
Open
Add databricks auth switch command for setting the default profile#4651simonfaltum wants to merge 7 commits intomainfrom
databricks auth switch command for setting the default profile#4651simonfaltum wants to merge 7 commits intomainfrom
Conversation
Collaborator
|
Commit: 58bec97
25 interesting tests: 8 FAIL, 7 KNOWN, 7 SKIP, 2 flaky, 1 BUG
Top 20 slowest tests (at least 2 minutes):
|
fac4c28 to
52cc221
Compare
Introduce a [databricks-cli-settings] section in ~/.databrickscfg with a default_profile key. The new `auth switch` command lets users select a named profile as the default, and `auth profiles` shows a (Default) marker next to it. The default profile resolution uses fallback logic: explicit setting first, then single-profile auto-default, then legacy DEFAULT section. The login flow auto-sets the default when creating the very first profile so new users get a working default out of the box. Resolution wiring (making the CLI use default_profile when no --profile is given) is out of scope for this change. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hasNoProfiles now treats ErrNoConfiguration (no config file) as "no
profiles" instead of returning false. This ensures the first profile
created on a fresh machine is auto-set as the default.
GetDefaultProfile now uses a read-only file loader (loadConfigFile)
that returns ("", nil) when the file doesn't exist, instead of
loadOrCreateConfigFile which would create the file as a side effect.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
auth switch now declares cobra.NoArgs so positional arguments produce a clear error instead of being silently ignored. The interactive profile picker label now shows the current default profile name (e.g. "Current default: e2-dogfood. Select a new default") so users know what they're changing from. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When no --profile flag is set, auth describe now shows the resolved default profile name in parentheses, e.g. "profile: default (e2-dogfood)" instead of just "profile: default". Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…rtion Extract resolveConfigFilePath helper to share tilde expansion logic between loadConfigFile and loadOrCreateConfigFile. In switch.go interactive path, use the already-loaded config file from the profiler to resolve the current default instead of re-reading from disk. Remove duplicate assertion in TestProfilesDefaultMarker. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The auth login acceptance tests now expect the [__databricks-settings__] section in out.databrickscfg and (Default) marker in auth profiles output, since first-profile login auto-sets the default. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
52cc221 to
58bec97
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
There is no way to set which profile is the active default without renaming it to
[DEFAULT]. Users with multiple profiles need a simple way to switch between them.Changes
Before: no mechanism to designate a default profile. Users had to rename sections in
~/.databrickscfgor always pass--profile.Now:
databricks auth switchlets users select a named profile as the default. The choice is stored in a[__databricks-settings__]section with adefault_profilekey.auth profilesshows a(Default)marker, andauth describeshows the resolved default name.Why
[__databricks-settings__]instead of a top-level key?INI files place keys that appear before any section header into the
[DEFAULT]section. The CLI already uses[DEFAULT]as a regular profile section (withhost,token, etc.), so addingdefault_profilethere would mix settings with profile credentials, and the profiles command would try to interpret[DEFAULT]as a profile containing that key. A dedicated[__databricks-settings__]section avoids this collision and is silently ignored by older SDKs (nohostkey means it is skipped in profile iteration).Implementation
libs/databrickscfg/ops.go:GetDefaultProfile/GetDefaultProfileFromwith fallback resolution (explicit setting, single-profile auto-default, legacy DEFAULT section).SetDefaultProfileto write the setting. SharedbackupAndSaveConfigFileandresolveConfigFilePathhelpers to deduplicate existing code.cmd/auth/switch.go: new command with--profileflag (non-interactive) and interactive profile picker showing the current default.cmd/auth/profiles.go:(Default)marker in output anddefaultfield in JSON.cmd/auth/describe.go: shows resolved default profile name, e.g.profile: default (my-workspace).cmd/auth/login.go+token.go: auto-set default when creating the very first profile.Resolution wiring (making the CLI actually use
default_profilewhen no--profileis given) is out of scope. That will be a follow-up change touchingcmd/root/auth.goand the bundle config path.Test plan
GetDefaultProfile,GetDefaultProfileFrom,SetDefaultProfile(table-driven, covering: explicit setting, single-profile fallback, DEFAULT fallback, no file, round-trip withSaveToProfile)auth switchcommand (with--profile, profile not found, non-interactive error, settings section written correctly)hasNoProfiles(fresh machine / ErrNoConfiguration, empty file, existing profiles)(Default)marker inauth profilesGetDefaultProfiledoes not create the config file as a side effect (asserted in test)make checksandmake lintfullpassdatabricks auth switch --profile <name>, verify~/.databrickscfghas[__databricks-settings__]sectiondatabricks auth profilesshows(Default)markerdatabricks auth switchinteractive picker shows current default