Skip to content

Commit b048fe1

Browse files
committed
exclude entitlements from CurrentWorkspaceID Me probe
CurrentWorkspaceID issues `GET /api/2.0/preview/scim/v2/Me` to read the X-Databricks-Org-Id response header. The Me endpoint computes User.Entitlements by default - a scan whose cost scales with the total number of entitlement grants in the workspace - and CurrentWorkspaceID never reads the body at all. Ask the server to skip the attribute.
1 parent 04b7dda commit b048fe1

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

workspace_functions.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@ import (
1515
// sent in the X-Databricks-Org-Id request header to route the call to the
1616
// correct workspace; on unified hosts with no WorkspaceID set, the request has
1717
// no routing information and will fail.
18+
//
19+
// The Me endpoint computes the User.Entitlements field by default, which scans
20+
// every entitlement grant in the workspace. That work is unused here - only the
21+
// X-Databricks-Org-Id response header is read - so the request asks the server
22+
// to skip the attribute.
1823
func (w *WorkspaceClient) CurrentWorkspaceID(ctx context.Context) (int64, error) {
1924
var workspaceIdStr string
2025
opts := []httpclient.DoOption{
2126
httpclient.WithResponseHeader("X-Databricks-Org-Id", &workspaceIdStr),
27+
httpclient.WithRequestData(map[string]string{"excludedAttributes": "entitlements"}),
2228
}
2329
if w.Config != nil && w.Config.WorkspaceID != "" {
2430
opts = append(opts, httpclient.WithRequestHeader("X-Databricks-Org-Id", w.Config.WorkspaceID))

workspace_functions_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,33 @@ func TestCurrentWorkspaceIDSendsOrgIdHeaderWhenConfigHasWorkspaceID(t *testing.T
4242
assert.Equal(t, "7474644166319138", gotOrgIdHeader)
4343
}
4444

45+
func TestCurrentWorkspaceIDExcludesEntitlements(t *testing.T) {
46+
// The Me endpoint computes User.Entitlements by default, which is a
47+
// workspace-wide scan; CurrentWorkspaceID only reads a response header, so
48+
// it asks the server to skip that attribute.
49+
var gotRawQuery string
50+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
51+
if r.URL.Path == "/api/2.0/preview/scim/v2/Me" {
52+
gotRawQuery = r.URL.RawQuery
53+
w.Header().Set("X-Databricks-Org-Id", "7474644166319138")
54+
w.Write([]byte(`{}`))
55+
return
56+
}
57+
http.NotFound(w, r)
58+
}))
59+
defer server.Close()
60+
61+
w, err := NewWorkspaceClient(&Config{
62+
Host: server.URL,
63+
Token: "token",
64+
})
65+
require.NoError(t, err)
66+
67+
_, err = w.CurrentWorkspaceID(t.Context())
68+
require.NoError(t, err)
69+
assert.Equal(t, "excludedAttributes=entitlements", gotRawQuery)
70+
}
71+
4572
func TestCurrentWorkspaceIDOmitsOrgIdHeaderWhenConfigMissingWorkspaceID(t *testing.T) {
4673
// On legacy workspace hosts the host itself identifies the workspace, so
4774
// no routing header is needed. When Config.WorkspaceID is empty we send

0 commit comments

Comments
 (0)