Commit f121e12
Add
## 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 `~/.databrickscfg` or always pass `--profile`.
Now: `databricks auth switch` lets users select a named profile as the
default. The choice is stored in a `[__settings__]` section with a
`default_profile` key. `auth profiles` shows a `(Default)` marker, and
`auth describe` shows 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 (with `host`, `token`, etc.), so adding
`default_profile` there 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 (no `host` key means it
is skipped in profile iteration).
### Implementation
- **`libs/databrickscfg/ops.go`**:
`GetDefaultProfile`/`GetDefaultProfileFrom` with fallback resolution
(explicit setting, single-profile auto-default, legacy DEFAULT section).
`SetDefaultProfile` to write the setting. Shared
`backupAndSaveConfigFile` and `resolveConfigFilePath` helpers to
deduplicate existing code.
- **`cmd/auth/switch.go`**: new command with `--profile` flag
(non-interactive) and interactive profile picker showing the current
default.
- **`cmd/auth/profiles.go`**: `(Default)` marker in output and `default`
field 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_profile` when no
`--profile` is given) is out of scope. That will be a follow-up change
touching `cmd/root/auth.go` and the bundle config path.
## Test plan
- [x] Unit tests for `GetDefaultProfile`, `GetDefaultProfileFrom`,
`SetDefaultProfile` (table-driven, covering: explicit setting,
single-profile fallback, DEFAULT fallback, no file, round-trip with
`SaveToProfile`)
- [x] Unit tests for `auth switch` command (with `--profile`, profile
not found, non-interactive error, settings section written correctly)
- [x] Unit tests for `hasNoProfiles` (fresh machine /
ErrNoConfiguration, empty file, existing profiles)
- [x] Unit test for `(Default)` marker in `auth profiles`
- [x] `GetDefaultProfile` does not create the config file as a side
effect (asserted in test)
- [x] `make checks` and `make lintfull` pass
- [x] Manual: `databricks auth switch --profile <name>`, verify
`~/.databrickscfg` has `[__settings__]` section
- [x] Manual: `databricks auth profiles` shows `(Default)` marker
- [x] Manual: `databricks auth switch` interactive picker shows current
default
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>databricks auth switch command for setting the default profile (#4651)1 parent c8d825c commit f121e12
File tree
29 files changed
+1169
-9
lines changed- acceptance/cmd/auth
- describe/default-profile
- login
- nominal
- with-scopes
- logout/delete-clears-default
- switch/nominal
- cmd
- auth
- configure
- root
- libs/databrickscfg
29 files changed
+1169
-9
lines changedLines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
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: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
0 commit comments