Skip to content

Commit b6cd53d

Browse files
maksim-zuev-dbIsaac
andauthored
Revert "Skip the workspace picker in the non-interactive device code login"
This reverts commit bda3307. The picker only prompted when the second step ran in a terminal for a host whose metadata has an account ID but no workspace ID, and the prompt can be skipped, so the extra branch is not worth it. Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 3d3be4f commit b6cd53d

2 files changed

Lines changed: 2 additions & 48 deletions

File tree

‎cmd/auth/login.go‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ const (
5252
// deviceCodeEnvVar enables the experimental device code login flow
5353
// (--use-device-code) while it is experimental.
5454
deviceCodeEnvVar = "DATABRICKS_CLI_DEVICE_CODE"
55-
// workspaceIDHint is shown instead of the workspace picker when login
56-
// cannot prompt.
57-
workspaceIDHint = "To use workspace commands, set workspace_id in your profile or pass --workspace-id."
5855
)
5956

6057
// discoveryErr wraps an error (or creates a new one) and appends the
@@ -469,13 +466,7 @@ a new profile is created.
469466
// 2. Configuring cluster and serverless;
470467
// 3. Saving the profile.
471468

472-
promptWorkspace := shouldPromptWorkspace(authArguments, existingProfile, skipWorkspace)
473-
switch {
474-
case promptWorkspace && nonInteractive:
475-
// The non-interactive device code login does not prompt, even in
476-
// a terminal.
477-
cmdio.LogString(ctx, workspaceIDHint)
478-
case promptWorkspace:
469+
if shouldPromptWorkspace(authArguments, existingProfile, skipWorkspace) {
479470
wsID, wsErr := promptForWorkspaceSelection(ctx, authArguments, tokenSource)
480471
if wsErr != nil {
481472
log.Warnf(ctx, "Workspace selection failed: %v", wsErr)
@@ -990,7 +981,7 @@ func u2mResourcesFromProfile(p *profile.Profile) []string {
990981
// to the user.
991982
func promptForWorkspaceSelection(ctx context.Context, authArguments *auth.AuthArguments, tokenSource oauth2.TokenSource) (string, error) {
992983
if !cmdio.IsPromptSupported(ctx) {
993-
cmdio.LogString(ctx, workspaceIDHint)
984+
cmdio.LogString(ctx, "To use workspace commands, set workspace_id in your profile or pass --workspace-id.")
994985
return "", nil
995986
}
996987

‎cmd/auth/login_device_code_test.go‎

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import (
55
"context"
66
"encoding/json"
77
"errors"
8-
"fmt"
98
"io"
109
"net/http"
11-
"net/http/httptest"
12-
"net/http/httputil"
1310
"net/url"
1411
"os"
1512
"path/filepath"
@@ -468,40 +465,6 @@ func TestLoginDeviceCodeCompletesInTerminal(t *testing.T) {
468465
// A user code that does not match the pending login fails before the token
469466
// exchange, so the confirmation code is not sent with the device code of
470467
// another login.
471-
func TestLoginDeviceCodeCompletionInTerminalSkipsWorkspacePicker(t *testing.T) {
472-
backend := newDeviceCodeServer(t)
473-
backendURL, err := url.Parse(backend.URL)
474-
require.NoError(t, err)
475-
// The host metadata of the fake server has a workspace ID, which skips the
476-
// workspace picker. Without it, login with an account ID asks for the
477-
// workspace.
478-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
479-
if r.URL.Path == "/.well-known/databricks-config" {
480-
fmt.Fprintf(w, `{"oidc_endpoint": %q}`, backend.URL+"/oidc")
481-
return
482-
}
483-
httputil.NewSingleHostReverseProxy(backendURL).ServeHTTP(w, r)
484-
}))
485-
t.Cleanup(server.Close)
486-
setUpDeviceCodeLogin(t, "")
487-
host := server.URL + "?a=123"
488-
ctx := cmdio.InContext(t.Context(), cmdio.NewIO(t.Context(), flags.OutputText, strings.NewReader(""), &bytes.Buffer{}, &bytes.Buffer{}, "", ""))
489-
require.NoError(t, runDeviceCodeLogin(ctx, "--host", host, "--profile", "test"))
490-
491-
tm := termtest.Run(t, func(ctx context.Context) (struct{}, error) {
492-
return struct{}{}, runDeviceCodeLogin(ctx, "--host", host, "--profile", "test", "--user-code", "WDJB-MJHT", "--confirmation-code", "FTFA-QQKY")
493-
})
494-
tm.WaitFor(workspaceIDHint)
495-
_, err = tm.Result()
496-
require.NoError(t, err)
497-
498-
profiles, err := profile.DefaultProfiler.LoadProfiles(t.Context(), profile.WithName("test"))
499-
require.NoError(t, err)
500-
require.Len(t, profiles, 1)
501-
assert.Equal(t, "123", profiles[0].AccountID)
502-
assert.Empty(t, profiles[0].WorkspaceID)
503-
}
504-
505468
func TestLoginDeviceCodeCompletionChecksUserCode(t *testing.T) {
506469
server := newDeviceCodeServer(t)
507470
var tokenRequests atomic.Int32

0 commit comments

Comments
 (0)