From f57c37ab60dca9760bd2ec7cdd5643bf3c6ea9f8 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 27 May 2026 13:18:48 +0200 Subject: [PATCH 1/2] auth: suggest ACCOUNT- as default profile name for --skip-workspace When `databricks auth login --host X --skip-workspace` runs, the profile- name prompt suggested the host's first DNS label (e.g. `db-deco-test`) even though the resulting profile is account-only. The naming logic in `getProfileName` already returns `ACCOUNT-` when `AccountID` is populated, but `setHostAndAccountId` (which discovers `account_id` via `.well-known/databricks-config`) only runs *after* the profile-name prompt, so `AccountID` was still empty at suggestion time. For the `--skip-workspace` path with a known host, run URL-param extraction and host discovery eagerly before the prompt fires. Other login paths are unchanged. Co-authored-by: Isaac --- cmd/auth/login.go | 17 +++++++++++++++ cmd/auth/login_test.go | 49 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/cmd/auth/login.go b/cmd/auth/login.go index 475a72ed36..7c24571830 100644 --- a/cmd/auth/login.go +++ b/cmd/auth/login.go @@ -221,6 +221,23 @@ a new profile is created. } } + // If --skip-workspace is set and we already know the host, eagerly run + // URL-param extraction and host discovery so getProfileName can suggest + // ACCOUNT- as the default name. Without this, AccountID is + // only populated by setHostAndAccountId further down, which runs after + // the profile-name prompt. + if skipWorkspace && profileName == "" && authArguments.Host != "" && authArguments.AccountID == "" { + params := auth.ExtractHostQueryParams(authArguments.Host) + authArguments.Host = params.Host + if authArguments.AccountID == "" { + authArguments.AccountID = params.AccountID + } + if authArguments.WorkspaceID == "" { + authArguments.WorkspaceID = params.WorkspaceID + } + runHostDiscovery(ctx, authArguments) + } + // If the user has not specified a profile name, prompt for one. if profileName == "" { var err error diff --git a/cmd/auth/login_test.go b/cmd/auth/login_test.go index 101f2e92e5..7627926403 100644 --- a/cmd/auth/login_test.go +++ b/cmd/auth/login_test.go @@ -564,6 +564,55 @@ func TestSetHostAndAccountId_URLParamsOverrideProfile(t *testing.T) { assert.Equal(t, "99999", args.WorkspaceID) } +func TestGetProfileName(t *testing.T) { + tests := []struct { + name string + args *auth.AuthArguments + want string + }{ + { + name: "account id set", + args: &auth.AuthArguments{Host: "https://db-deco-test.databricks.com", AccountID: "abc-123"}, + want: "ACCOUNT-abc-123", + }, + { + name: "no account id falls back to host", + args: &auth.AuthArguments{Host: "https://db-deco-test.databricks.com"}, + want: "db-deco-test", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equal(t, tt.want, getProfileName(tt.args)) + }) + } +} + +// TestSkipWorkspaceProfileNameUsesDiscoveredAccountID verifies that the +// pre-naming discovery block populates AccountID from .well-known so the +// profile-name prompt suggests ACCOUNT- instead of the host-based +// default. +func TestSkipWorkspaceProfileNameUsesDiscoveredAccountID(t *testing.T) { + server := newDiscoveryServer(t, map[string]any{ + "account_id": "abc-123", + "oidc_endpoint": "https://spog.example.com/oidc/accounts/abc-123", + }) + + ctx := t.Context() + args := &auth.AuthArguments{Host: server.URL} + + // Mirrors the pre-naming block in newLoginCommand's RunE for --skip-workspace. + params := auth.ExtractHostQueryParams(args.Host) + args.Host = params.Host + if args.AccountID == "" { + args.AccountID = params.AccountID + } + runHostDiscovery(ctx, args) + + assert.Equal(t, "abc-123", args.AccountID) + assert.Equal(t, "ACCOUNT-abc-123", getProfileName(args)) +} + func TestValidateDiscoveryFlagCompatibility(t *testing.T) { tests := []struct { name string From 22e4516ae015f76c7f9e9e5342ddf8d830d234bb Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 27 May 2026 16:41:02 +0200 Subject: [PATCH 2/2] ci: retrigger integration tests