Skip to content

Commit fb01984

Browse files
authored
Exclude entitlements from CurrentWorkspaceID Me probe (#1681)
This PR makes `WorkspaceClient.CurrentWorkspaceID` ask the SCIM server to skip the `entitlements` attribute on the underlying `Me` call. ## Why `CurrentWorkspaceID` issues a `GET /api/2.0/preview/scim/v2/Me` request and reads the `X-Databricks-Org-Id` response header to identify the workspace. The body of the response is discarded. By default, however, the SCIM server computes the `User.Entitlements` field for `/Me` responses - and that computation scans every entitlement grant in the workspace, regardless of which user is calling. On workspaces with a lot of accumulated grants, that's a meaningful amount of server work for a value the SDK never looks at. This change passes `?excludedAttributes=entitlements` on the request so the server can skip the scan entirely. The endpoint already honors that query parameter today. ## What changed One option appended to the existing `Do` call: ```go httpclient.WithRequestData(map[string]string{"excludedAttributes": "entitlements"}) ``` And a doc-comment line on `CurrentWorkspaceID` explaining the why. ## Tests New `TestCurrentWorkspaceIDExcludesEntitlements` stands up an `httptest` server, captures `r.URL.RawQuery`, and asserts it's `excludedAttributes=entitlements`. The two existing `TestCurrentWorkspaceID*` tests in this file already match on `r.URL.Path`, so they still pass. --------- Co-authored-by: Omer Lachish <rauchy@users.noreply.github.com>
1 parent fbb184c commit fb01984

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

NEXT_CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
### Internal Changes
1414

15+
* Pass `excludedAttributes=entitlements` on the SCIM `/Me` request made by `WorkspaceClient.CurrentWorkspaceID` ([#1681](https://github.com/databricks/databricks-sdk-go/pull/1681)).
16+
17+
`CurrentWorkspaceID` only reads the `X-Databricks-Org-Id` response header and discards the body, so it has no use for the `User.Entitlements` field. Skipping that attribute avoids an expensive `getEffectivePermissions` scan on the SCIM backend, which has caused incidents on workspaces with large grant counts.
18+
1519
### API Changes
1620
* Add `Revert` method for [w.Lakeview](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/dashboards#LakeviewAPI) workspace-level service.
1721
* Add `ParentPath` field for [dashboards.GenieUpdateSpaceRequest](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/dashboards#GenieUpdateSpaceRequest).

workspace_functions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func (w *WorkspaceClient) CurrentWorkspaceID(ctx context.Context) (int64, error)
1919
var workspaceIdStr string
2020
opts := []httpclient.DoOption{
2121
httpclient.WithResponseHeader("X-Databricks-Org-Id", &workspaceIdStr),
22+
httpclient.WithRequestData(map[string]string{"excludedAttributes": "entitlements"}),
2223
}
2324
if w.Config != nil && w.Config.WorkspaceID != "" {
2425
opts = append(opts, httpclient.WithRequestHeader("X-Databricks-Org-Id", w.Config.WorkspaceID))

workspace_functions_test.go

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

45+
func TestCurrentWorkspaceIDExcludesEntitlements(t *testing.T) {
46+
var gotRawQuery string
47+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
48+
if r.URL.Path == "/api/2.0/preview/scim/v2/Me" {
49+
gotRawQuery = r.URL.RawQuery
50+
w.Header().Set("X-Databricks-Org-Id", "7474644166319138")
51+
w.Write([]byte(`{}`))
52+
return
53+
}
54+
http.NotFound(w, r)
55+
}))
56+
defer server.Close()
57+
58+
w, err := NewWorkspaceClient(&Config{
59+
Host: server.URL,
60+
Token: "token",
61+
})
62+
require.NoError(t, err)
63+
64+
_, err = w.CurrentWorkspaceID(t.Context())
65+
require.NoError(t, err)
66+
assert.Equal(t, "excludedAttributes=entitlements", gotRawQuery)
67+
}
68+
4569
func TestCurrentWorkspaceIDOmitsOrgIdHeaderWhenConfigMissingWorkspaceID(t *testing.T) {
4670
// On legacy workspace hosts the host itself identifies the workspace, so
4771
// no routing header is needed. When Config.WorkspaceID is empty we send

0 commit comments

Comments
 (0)