Skip to content

Extract shared SelectProfile helper to eliminate duplicate profile pickers#4647

Merged
mihaimitrea-db merged 34 commits intomainfrom
mihaimitrea-db/stack/auth_logout_deduplication
Mar 12, 2026
Merged

Extract shared SelectProfile helper to eliminate duplicate profile pickers#4647
mihaimitrea-db merged 34 commits intomainfrom
mihaimitrea-db/stack/auth_logout_deduplication

Conversation

@mihaimitrea-db
Copy link
Collaborator

@mihaimitrea-db mihaimitrea-db commented Mar 3, 2026

🥞 Stacked PR

Use this link to review incremental changes.


Four places built nearly identical promptui.Select prompts for interactive profile selection (auth logout, auth token, cmd/root/auth.go, cmd/root/bundle.go). This PR extracts a reusable profile.SelectProfile function that accepts a declarative SelectConfig with label, profiles, and template strings, replacing all four implementations.

Changes

  • Add profile.SelectProfile in libs/databrickscfg/profile/select.go — a shared interactive profile picker that accepts a SelectConfig (label, profiles, template strings) and returns the selected profile name.
  • Replace the four inline promptui.Select implementations in cmd/auth/logout.go, cmd/auth/token.go, cmd/root/auth.go, and cmd/root/bundle.go with calls to SelectProfile.
  • Add AccountID to Profiles.SearchCaseInsensitive so all pickers support searching by account ID, not just name and host.
  • Extract writeConfigFile helper in libs/databrickscfg/ops.go to consolidate the repeated default-comment / backup / save sequence shared by SaveToProfile and DeleteProfile.

Why

The four profile pickers each duplicated the same prompt setup, searcher wiring, and result extraction. This made it easy for behavior to diverge (e.g., only the logout picker searched by account ID). A single shared helper keeps the UX consistent and reduces the surface area for future changes.

Tests

  • Existing unit and acceptance tests for auth logout, auth token, workspace/account profile selection, and bundle profile resolution continue to pass — the refactor is behavior-preserving.
  • The SelectProfile helper is exercised indirectly through all existing callers.

@eng-dev-ecosystem-bot
Copy link
Collaborator

eng-dev-ecosystem-bot commented Mar 3, 2026

Commit: a48290e

Run: 23008472654

Env 🟨​KNOWN 🔄​flaky 💚​RECOVERED 🙈​SKIP ✅​pass 🙈​skip Time
🟨​ aws linux 7 1 7 268 788 7:04
🟨​ aws windows 7 1 7 270 786 6:29
🔄​ aws-ucws linux 2 7 7 364 703 7:41
🔄​ aws-ucws windows 2 7 7 366 701 6:54
💚​ azure linux 2 9 271 786 5:59
💚​ azure windows 2 9 273 784 5:04
💚​ azure-ucws linux 2 9 370 699 7:49
🔄​ azure-ucws windows 2 1 9 371 697 5:54
💚​ gcp linux 2 9 267 789 5:39
💚​ gcp windows 2 9 269 787 5:04
16 interesting tests: 7 KNOWN, 7 SKIP, 2 flaky
Test Name aws linux aws windows aws-ucws linux aws-ucws windows azure linux azure windows azure-ucws linux azure-ucws windows gcp linux gcp windows
🟨​ TestAccept 🟨​K 🟨​K 💚​R 💚​R 💚​R 💚​R 💚​R 🔄​f 💚​R 💚​R
🙈​ TestAccept/bundle/resources/permissions 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🟨​ TestAccept/bundle/resources/permissions/jobs/destroy_without_mgmtperms/with_permissions 🟨​K 🟨​K 💚​R 💚​R 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🟨​ TestAccept/bundle/resources/permissions/jobs/destroy_without_mgmtperms/with_permissions/DATABRICKS_BUNDLE_ENGINE=direct 🟨​K 🟨​K 💚​R 💚​R
🟨​ TestAccept/bundle/resources/permissions/jobs/destroy_without_mgmtperms/with_permissions/DATABRICKS_BUNDLE_ENGINE=terraform 🟨​K 🟨​K 💚​R 💚​R
🟨​ TestAccept/bundle/resources/permissions/jobs/destroy_without_mgmtperms/without_permissions 🟨​K 🟨​K 💚​R 💚​R 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🟨​ TestAccept/bundle/resources/permissions/jobs/destroy_without_mgmtperms/without_permissions/DATABRICKS_BUNDLE_ENGINE=direct 🟨​K 🟨​K 💚​R 💚​R
🟨​ TestAccept/bundle/resources/permissions/jobs/destroy_without_mgmtperms/without_permissions/DATABRICKS_BUNDLE_ENGINE=terraform 🟨​K 🟨​K 💚​R 💚​R
🙈​ TestAccept/bundle/resources/postgres_branches/basic 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/postgres_branches/recreate 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/postgres_branches/update_protected 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/postgres_branches/without_branch_id 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/postgres_endpoints/recreate 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/synced_database_tables/basic 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🔄​ TestAccept/ssh/connect-serverless-gpu 🙈​s 🙈​s 🔄​f 🔄​f 🙈​s 🙈​s ✅​p 🔄​f 🙈​s 🙈​s
🔄​ TestAccept/ssh/connection 💚​R 💚​R 🔄​f 🔄​f 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 21 slowest tests (at least 2 minutes):
duration env testname
3:43 gcp linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
3:27 azure-ucws linux TestAccept/ssh/connect-serverless-gpu
3:25 aws-ucws windows TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
3:16 gcp windows TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
3:15 azure-ucws linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
3:13 azure-ucws windows TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
3:07 gcp linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
3:04 gcp windows TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
2:55 aws-ucws linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:50 aws windows TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:48 aws linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
2:45 aws windows TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
2:43 aws-ucws windows TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
2:42 aws linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:41 aws-ucws linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
2:16 azure linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:15 azure-ucws windows TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:13 azure windows TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:06 azure windows TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
2:05 azure-ucws linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:05 azure linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct

@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/auth_logout_deduplication branch from c6d25f1 to c9512bf Compare March 4, 2026 09:06
@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/auth_logout_deduplication branch from 8a5d258 to b40887a Compare March 4, 2026 09:45
@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/auth_logout_deduplication branch from b40887a to 16de011 Compare March 4, 2026 10:25
@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/auth_logout_deduplication branch from 16de011 to 3116cbb Compare March 5, 2026 12:39
@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/auth_logout_deduplication branch from 3116cbb to 634b7b9 Compare March 5, 2026 12:52
@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/auth_logout_deduplication branch from 634b7b9 to 40c98ed Compare March 5, 2026 13:06
@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/auth_logout_deduplication branch from 40c98ed to 76e7b0e Compare March 5, 2026 13:15
@mihaimitrea-db mihaimitrea-db changed the base branch from main to mihaimitrea-db/stack/auth_logout_profile_picker March 5, 2026 13:30
@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/auth_logout_profile_picker branch from c6a2f23 to 3c8e18a Compare March 5, 2026 13:53
@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/auth_logout_deduplication branch from 76e7b0e to 109b1ca Compare March 5, 2026 13:53
@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/auth_logout_profile_picker branch from 3c8e18a to c37cac0 Compare March 5, 2026 14:08
@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/auth_logout_deduplication branch from 109b1ca to 336ab51 Compare March 5, 2026 14:08
@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/auth_logout_profile_picker branch from c37cac0 to 6a3a446 Compare March 5, 2026 14:19
@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/auth_logout_deduplication branch from 8e3d5e7 to ed5be7c Compare March 9, 2026 12:41
When --profile is not specified in an interactive terminal, show a
searchable prompt listing all configured profiles. Profiles are sorted
alphabetically and displayed with their host or account ID. The picker
supports fuzzy search by name, host, or account ID.
Document the four interaction modes (explicit profile, interactive
picker, non-interactive error, and --force) in the command's long
help text.
…ckers

Four places built nearly identical promptui.Select prompts for
interactive profile selection (auth logout, auth token, root auth,
root bundle). Extract a reusable profile.SelectProfile function that
takes a declarative SelectConfig with label, profiles, and template
strings.

Also: add AccountID to Profiles.SearchCaseInsensitive so all pickers
support searching by account ID, and remove the redundant
not-found guard in DeleteProfile (ini.DeleteSection is already a
no-op for missing sections).
Extract writeConfigFile helper to consolidate the repeated
default-comment, backup, and save sequence shared by SaveToProfile
and DeleteProfile.

Also switch auth login from os.Getenv to env.Get(ctx, ...) for
DATABRICKS_CONFIG_FILE so it respects context-level env overrides,
consistent with the rest of the codebase.
- Restore StartInSearchMode for logout picker so profiles with 6+
  entries auto-activate search, matching the previous behavior.
- Improve empty-profiles error to suggest running 'databricks auth
  login' instead of the generic "no profiles to select from".
@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/auth_logout_deduplication branch from ed5be7c to 51f14b5 Compare March 10, 2026 15:16
… coupling

- Only preserve host-keyed OAuth tokens when another U2M profile shares
  the host. Non-U2M profiles (PAT, M2M) never use the OAuth cache, so
  they should not prevent token cleanup on logout.
- Add m2m token entries to test fixtures and assert they are preserved
  after logout, verifying the isCreatedByLogin guard works correctly.
- Fix inMemoryTokenCache.Store(nil) to delete the key (matching
  production FileTokenCache behavior) instead of storing a nil value.
- Build the promptui Searcher from the items slice directly in
  SelectProfile to avoid implicit coupling with the original Profiles
  slice.
Copy link
Member

@simonfaltum simonfaltum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@mihaimitrea-db mihaimitrea-db added this pull request to the merge queue Mar 12, 2026
Merged via the queue into main with commit cb3c326 Mar 12, 2026
18 checks passed
@mihaimitrea-db mihaimitrea-db deleted the mihaimitrea-db/stack/auth_logout_deduplication branch March 12, 2026 15:58
@mihaimitrea-db mihaimitrea-db linked an issue Mar 12, 2026 that may be closed by this pull request
mihaimitrea-db added a commit that referenced this pull request Mar 12, 2026
The auth logout feature (PRs #4613, #4616, #4647) was squashed into a
single commit cb3c326 titled after #4647 only, losing traceability for
the new command itself. This followup:

- Adds a comment block to logout.go linking each original PR with its
  commit range and purpose.
- Adds a NEXT_CHANGELOG entry for auth logout under CLI.
- Removes Hidden: true so the command appears in help and completion.
- Aligns the Long description with the public documentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add logout command

3 participants