Commit 3c867c9
authored
api: route per-call against unified hosts (#5137)
## Why
`databricks api` always sent the workspace routing identifier
(`X-Databricks-Org-Id`) when the profile had one, even when the path was
an account API. On unified hosts (one host serving both workspace and
account APIs) this misrouted account calls. There was also no way to
explicitly route a call to the account API or override the identifier
per call.
## Changes
Before: routing was decided once from the profile and applied to every
call.
Now: routing is decided per call from the path being requested.
- Paths under `/accounts/{id}/` are auto-detected as account-scope; the
routing identifier is dropped.
- A small hand-written list in `cmd/api/paths.go` carves out
workspace-routed proxy APIs that happen to live under `/accounts/`, so
they keep the identifier.
- `--account` forces account-scope on a non-`/accounts/` path.
- `--workspace-id <id>` overrides the identifier per call. Mutually
exclusive with `--account`.
- `?o=<id>` on the path (the SPOG URL convention used by the Databricks
UI) is recognized as a per-call workspace override, so URLs pasted from
the browser route correctly.
- The CLI-only `workspace_id = none` sentinel is stripped before the
routing decision so the literal "none" never goes on the wire.
Routing logic lives in pure functions (`hasAccountSegment`,
`extractOrgIDFromQuery`, `resolveOrgID`, `normalizeWorkspaceID`,
`isWorkspaceProxyPath`) that take primitives. The cobra `RunE` is a thin
adapter that resolves config and calls them.
## Test plan
- [x] `go test ./cmd/api` covers the helpers with table-driven cases:
deny-list hits and misses, query/fragment edge cases, mutual-exclusion
errors, sentinel stripping, `?o=` extraction.
- [x] `go test ./acceptance -run TestAccept/cmd/api` exercises seven
variants end to end against terraform and direct engines: workspace
path, account path, deny-listed proxy under `/accounts/`, `--account`,
`--workspace-id`, `?o=` query, `workspace_id = none`. Each test asserts
header presence/absence explicitly via `print_requests.py |
contains.py`.
- [x] `make checks`1 parent 521074c commit 3c867c9
28 files changed
Lines changed: 648 additions & 2 deletions
File tree
- acceptance/cmd/api
- account-flag
- account-path
- workspace-id-flag
- workspace-id-from-query
- workspace-id-none
- workspace-path
- workspace-proxy-regression
- cmd/api
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 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 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| 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 | + | |
0 commit comments