Add databricks auth switch command for setting the default profile#4651
Open
simonfaltum wants to merge 22 commits intomainfrom
Open
Add databricks auth switch command for setting the default profile#4651simonfaltum wants to merge 22 commits intomainfrom
databricks auth switch command for setting the default profile#4651simonfaltum wants to merge 22 commits intomainfrom
Conversation
Collaborator
|
Commit: 55d8373
18 interesting tests: 7 SKIP, 6 RECOVERED, 5 flaky
Top 22 slowest tests (at least 2 minutes):
|
fac4c28 to
52cc221
Compare
52cc221 to
58bec97
Compare
6c8e7e3 to
fd6b688
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>
When no --profile flag or DATABRICKS_CONFIG_PROFILE env var is set, the CLI now honors the explicit default_profile setting from [__databricks-settings__] before the SDK falls back to the DEFAULT section. Also aligns auth describe to only show the configured default (not fallback heuristics like single-profile auto-default).
fd6b688 to
3f72a7f
Compare
- Rename settings section from `__databricks-settings__` to `__settings__` - Log warning when GetConfiguredDefaultProfile fails in auth describe - Rename isFirstProfile to isOnlyProfile for clarity - Inline hasNoProfiles logic at call sites instead of loading profiles in helper
- Reject reserved __settings__ profile name in SaveToProfile and SetDefaultProfile to prevent collisions with the settings section. - Add auto-set default logic to `databricks configure` so the first profile created via configure also becomes the default, matching the behavior of `auth login` and `auth token`. - Use GetConfiguredDefaultProfileFrom (strict) in `auth profiles` instead of GetDefaultProfileFrom (heuristic) so the (Default) marker only appears when an explicit default_profile is set, matching the resolution logic in cmd/root/auth.go. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
pietern
reviewed
Mar 10, 2026
pietern
reviewed
Mar 10, 2026
1. Extract "default_profile" to a named constant (defaultProfileKey).
2. Simplify GetConfiguredDefaultProfileFrom using Section().Key()
which returns an empty string when the section/key is missing,
removing the need for explicit error handling.
3. Rename profile -> displayProfile in auth describe to clarify
it is only used for display, not as a real profile name downstream.
4. Replace os.Getenv("DATABRICKS_CONFIG_FILE") with env.Get(ctx, ...)
in login.go, token.go, switch.go, and configure.go for testability.
5. Remove existingProfile == nil guard from isOnlyProfile in login.go.
Re-logging into the only profile should still set it as default.
6. Apply default_profile resolution in MustAccountClient, matching
the existing logic in MustWorkspaceClient.
7. Add acceptance tests:
- auth switch nominal: verifies [__settings__] is created, retained,
and updated across two consecutive switches.
- auth describe default-profile: verifies auth describe picks up
the configured default profile without --profile flag.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Collaborator
|
Commit: 64a6473
18 interesting tests: 7 SKIP, 6 RECOVERED, 5 flaky
Top 20 slowest tests (at least 2 minutes):
|
pietern
approved these changes
Mar 11, 2026
1. Extract auto-set-default helpers (IsFirstProfile, SetDefaultProfileQuietly) in libs/databrickscfg/ops.go to consolidate the duplicated "set default on first profile" pattern across login.go, token.go, and configure.go. 2. Extract resolveDefaultProfile helper in cmd/root/auth.go to deduplicate the identical default profile resolution in MustWorkspaceClient and MustAccountClient. 3. Remove dead GetConfiguredDefaultProfile call in cmd/auth/describe.go. When a default_profile is configured, it is already resolved by MustWorkspaceClient/MustAccountClient before getAuthDetails runs. 4. Eliminate double config file load in cmd/auth/switch.go by using GetDefaultProfile directly instead of Get + GetDefaultProfileFrom. 5. Use grep in switch acceptance test to show only __settings__ section instead of dumping the full config.
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[__settings__]section with adefault_profilekey.auth profilesshows a(Default)marker, andauth describeshows the resolved default name.Why
[__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[__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[__settings__]sectiondatabricks auth profilesshows(Default)markerdatabricks auth switchinteractive picker shows current default