Commit a57fe14
authored
auth: extract ?o=/?a= from DATABRICKS_HOST env var (#5337)
## Why
Pasting a SPOG URL from the Databricks UI (e.g.
`https://acme.azuredatabricks.net/?o=12345`) into `DATABRICKS_HOST`
drops the workspace identifier before any API call goes out. The SDK
strips path and query from `Host` in `fixHostIfNeeded` without promoting
`?o=` to `WorkspaceID`, so the request goes to the SPOG hostname without
an `X-Databricks-Org-Id` header. The server can't route it and answers
with the login HTML page, which surfaces as:
```
$ DATABRICKS_HOST=https://acme.azuredatabricks.net/?o=12345 databricks bundle validate
Error: received HTML response instead of JSON
```
The bundle YAML `workspace.host` field is already normalized via
`NormalizeHostURL` in `bundle/config/workspace.go`, and `databricks api`
handles `?o=` per call (#5137). The env-var path was the remaining gap.
## Changes
Before: `DATABRICKS_HOST=https://acme.databricks.net/?o=12345` reached
the SDK with the query intact, the SDK dropped it, and `WorkspaceID`
stayed empty.
Now: `auth.NormalizeDatabricksHostEnv` runs once at the top of
`root.Execute`, before the SDK reads anything. It uses the existing
`ExtractHostQueryParams` helper to promote `?o=` / `?workspace_id=` to
`DATABRICKS_WORKSPACE_ID` and `?a=` / `?account_id=` to
`DATABRICKS_ACCOUNT_ID` (only when those env vars are unset), then
rewrites `DATABRICKS_HOST` without the query string.
A follow-up PR will push the same normalization into the SDK's
`fixHostIfNeeded` so Python/Java/JS SDK users and any direct Go-SDK
callers get the same fix without going through the CLI.
## Test plan
- [x] `go test ./libs/auth/` covers the new helper with table-driven
cases: `?o=` promotion, `?a=` + `?o=` together, existing
`DATABRICKS_WORKSPACE_ID` is preserved, hosts without query are
untouched, non-numeric `?o=` is dropped, unset `DATABRICKS_HOST` is a
no-op.
- [x] `go test ./cmd/root/` passes.
- [x] `./task checks`.
- [x] Manual end-to-end repro with a local SPOG-shaped test server:
before the fix the SDK sent no `X-Databricks-Org-Id` header and got HTML
back; after the fix the header is `258628866953061` and `bundle
validate` proceeds to the workspace API.1 parent 68d6ae1 commit a57fe14
4 files changed
Lines changed: 132 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| 97 | + | |
| 98 | + | |
97 | 99 | | |
98 | 100 | | |
99 | 101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
155 | 156 | | |
156 | 157 | | |
157 | 158 | | |
| |||
250 | 251 | | |
251 | 252 | | |
252 | 253 | | |
| 254 | + | |
253 | 255 | | |
254 | 256 | | |
255 | 257 | | |
| |||
| 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 | + | |
| 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 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
0 commit comments