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
1 change: 1 addition & 0 deletions .nextchanges/air/7153.md
Original file line number Diff line number Diff line change
@@ -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))
3 changes: 2 additions & 1 deletion cmd/air/runlaunch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
20 changes: 20 additions & 0 deletions cmd/air/runlaunch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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(`
Expand Down
Loading