Commit f171c1f
authored
SPOG: short-circuit CurrentWorkspaceID and add org-id header to SharesAPI (#1635)
## Changes
Two SPOG fixes for hand-written SDK extension methods that bypass the
generated code's per-call `X-Databricks-Org-Id` header logic.
### 1. Short-circuit `WorkspaceClient.CurrentWorkspaceID()`
Return `Config.WorkspaceID` directly when it is non-empty, instead of
making a `GET` to `/api/2.0/preview/scim/v2/Me` purely to read the
workspace id from the `X-Databricks-Org-Id` response header.
In the CLI bundle flow, `Config.WorkspaceID` is already populated before
this call runs, from any of:
- the matched profile in `.databrickscfg` (`workspace_id = ...`)
- the `?o=<id>` query parameter extracted from the bundle host
- the `DATABRICKS_WORKSPACE_ID` env var
- host metadata at `/.well-known/databricks-config`
Calling `Me()` to re-learn that value is a wasted round-trip, and on
SPOG
hosts it also breaks `databricks bundle open`:
```
Error: Unable to load OAuth Config (400 UNKNOWN)
Endpoint: GET https://<spog-host>/api/2.0/preview/scim/v2/Me
HTTP Status: 400 Bad Request
```
The previous implementation used `httpclient.WithResponseHeader` to read
`X-Databricks-Org-Id` from the response, but did not set it on the
request. SPOG's proxy rejects un-routed requests with the exact 400
above.
#### Why the short-circuit is sufficient
On SPOG, `WorkspaceID` is the routing key. To call `Me()` the request
must carry `X-Databricks-Org-Id`.
- If `Config.WorkspaceID` is set, return it without any API call.
- If `Config.WorkspaceID` is empty, we have no value to put in the
header, so `Me()` on SPOG would fail regardless. A header-setting
patch would add no reachable value.
On non-SPOG hosts the fallback API call still works without the header,
preserving pre-existing behavior.
### 2. Add `X-Databricks-Org-Id` to `SharesAPI.internalList()`
`service/sharing/ext_api.go` `SharesAPI.internalList()` is a
hand-written
extension that calls `a.client.Do()` directly and was missing the
`X-Databricks-Org-Id` request header. On SPOG hosts this causes
`shares.List(Paginated|All)` to fail with the same `Unable to load OAuth
Config` error. Matches the fix in #1634 for
`service/workspace/ext_utilities.go` `Upload()` / `Download()`.
Pointed out by Hector Castejon Diaz.
## Tests
### Unit tests
Added `workspace_functions_test.go`:
- `TestCurrentWorkspaceIDShortCircuitsWhenConfigHasWorkspaceID`: fails
the test if `Me()` is called when `Config.WorkspaceID` is set, and
asserts the returned value matches the configured id.
- `TestCurrentWorkspaceIDFallsBackToAPIWhenConfigMissingWorkspaceID`:
asserts the pre-existing API fallback still works and parses the
`X-Databricks-Org-Id` response header correctly.
No dedicated unit test added for the sharing header change; matches
#1634 which applied the same pattern without one. `make fmt test lint`
clean on the full SDK (1344 tests pass, 103 skipped).
### Empirical SPOG verification
Same bearer token, same endpoint, toggling only the request header:
| Request | Response |
| ------------------------------------------ |
-------------------------------------- |
| `GET /Me` (no `X-Databricks-Org-Id`) | HTTP 400 `Unable to load OAuth
Config` |
| `GET /Me` with `X-Databricks-Org-Id: <id>` | HTTP 200 with valid user
JSON |
Confirms the missing request header is the cause.
### End-to-end with the CLI
Built the CLI against this branch via `go mod edit -replace` and ran on
a
real SPOG workspace (`db-deco-test-chrisst`, host
`https://db-deco-test.databricks.com`):
- `databricks bundle validate -t dev`: OK
- `databricks bundle deploy -t dev`: OK
- `databricks bundle run hello_world -t dev`: OK, job TERMINATED SUCCESS
- `databricks bundle open hello_world -t dev`: OK, opens the job URL.
Previously failed with `Unable to load OAuth Config (400 UNKNOWN)`.
Signed-off-by: simon <simon.faltum@databricks.com>
---------
Signed-off-by: simon <simon.faltum@databricks.com>1 parent b3cd610 commit f171c1f
4 files changed
Lines changed: 77 additions & 0 deletions
File tree
- service/sharing
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
74 | 78 | | |
75 | 79 | | |
76 | 80 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
12 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
13 | 21 | | |
14 | 22 | | |
15 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
0 commit comments