Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions cmd/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-<account-id> 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
Expand Down
49 changes: 49 additions & 0 deletions cmd/auth/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-<account-id> 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
Expand Down
Loading