diff --git a/.nextchanges/air/7153.md b/.nextchanges/air/7153.md new file mode 100644 index 00000000000..f163925bc66 --- /dev/null +++ b/.nextchanges/air/7153.md @@ -0,0 +1 @@ +* `air run` now spends less time before submitting: it fetches only the user name from SCIM. ([#7153](https://github.com/databricks/cli/pull/7153)) diff --git a/cmd/air/runlaunch.go b/cmd/air/runlaunch.go index 5566ec98ca5..a888d80d85d 100644 --- a/cmd/air/runlaunch.go +++ b/cmd/air/runlaunch.go @@ -21,7 +21,8 @@ const userWorkspaceDirEnv = "DATABRICKS_INTERNAL_USER_WORKSPACE_DIR" // currentUserEmail returns the authenticated user's email (works for any domain). func currentUserEmail(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { - me, err := w.CurrentUser.Me(ctx, iam.MeRequest{}) + // Only userName is needed; the full response also resolves groups and entitlements. + me, err := w.CurrentUser.Me(ctx, iam.MeRequest{Attributes: "userName"}) if err != nil { return "", fmt.Errorf("failed to resolve current user: %w", err) } diff --git a/cmd/air/runlaunch_test.go b/cmd/air/runlaunch_test.go index 7654e544964..edb4803ba65 100644 --- a/cmd/air/runlaunch_test.go +++ b/cmd/air/runlaunch_test.go @@ -9,6 +9,7 @@ import ( "github.com/databricks/cli/libs/filer" "github.com/databricks/cli/libs/testserver" "github.com/databricks/databricks-sdk-go" + "github.com/databricks/databricks-sdk-go/service/iam" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -45,6 +46,25 @@ func TestUserWorkspaceDir(t *testing.T) { assert.Equal(t, "/Workspace/custom", dir) } +func TestUserWorkspaceDirRequestsOnlyUserName(t *testing.T) { + server := testserver.New(t) + t.Cleanup(server.Close) + var attributes []string + server.Handle("GET", "/api/2.0/preview/scim/v2/Me", func(req testserver.Request) any { + attributes = append(attributes, req.URL.Query().Get("attributes")) + return iam.User{UserName: "me@example.com"} + }) + testserver.AddDefaultHandlers(server) + w, err := databricks.NewWorkspaceClient(&databricks.Config{Host: server.URL, Token: "token"}) + require.NoError(t, err) + t.Setenv(userWorkspaceDirEnv, "") + + dir, err := userWorkspaceDir(t.Context(), w) + require.NoError(t, err) + assert.Equal(t, "/Workspace/Users/me@example.com", dir) + assert.Equal(t, []string{"userName"}, attributes) +} + func TestUserWorkspaceDirProfilePrecedence(t *testing.T) { configPath := filepath.Join(t.TempDir(), ".databrickscfg") require.NoError(t, os.WriteFile(configPath, []byte(`