Send X-Databricks-Workspace-Id on remaining raw client.Do callers#5398
Merged
Conversation
PR #5368 flipped the workspace routing header from X-Databricks-Org-Id to X-Databricks-Workspace-Id across five hand-written CLI code paths. Review on that PR identified five more raw apiClient.Do call sites that were quietly missing the routing header entirely. On unified hosts with cfg.WorkspaceID set, those calls land on the gateway with no routing information and can fail or be misrouted. The newly covered call sites are all workspace-routed endpoints: - bundle/generate/downloader.go GET /api/2.0/workspace/get-status (databricks bundle generate) - cmd/pipelines/utils.go GET /api/2.0/pipelines/<id>/events (databricks pipelines events) - libs/databrickscfg/cfgpickers/warehouses.go GET /api/2.0/sql/warehouses (warehouse picker) - libs/apps/prompt/listers.go GET /api/2.0/database/instances/.../databases (Lakebase database lister) - libs/git/info.go GET /api/2.0/workspace/get-status (DBR-runtime git info probe) Rather than copying the header-building snippet a sixth time, this PR introduces a shared helper in libs/auth: auth.WorkspaceIDHeader = "X-Databricks-Workspace-Id" auth.WorkspaceIDHeaders(cfg *sdkconfig.Config) map[string]string The helper returns nil when cfg.WorkspaceID is unset or holds the CLI-only "none" sentinel, so callers can pass the result directly to client.Do without conditional checks. The five new sites use it. As cleanup, the four existing copies of the same pattern are migrated to the helper as well: - cmd/api/api.go (workspaceIDHeader const) - bundle/deploy/filer.go ((s stateFiler) workspaceIDHeaders) - libs/filer/files_client.go ((w *FilesClient) workspaceIDHeaders) - libs/telemetry/logger.go (workspaceIDHeaders package function) libs/filer/workspace_files_client.go keeps a thin method wrapper around the shared helper because it has a legitimate nil-workspaceClient case in its existing tests; the wrapper handles that nil safety and delegates the rest. Side effect of the consolidation: callers that previously sent X-Databricks-Workspace-Id: none when cfg.WorkspaceID was the CLI sentinel "none" no longer do — the shared helper treats "none" as unset, matching the existing cmd/api/api.go normalization and the auth.ResolveWorkspaceID helper introduced in PR #5379. In practice users who set workspace_id = none in .databrickscfg are on account-scoped auth and these workspace- routed calls wouldn't succeed regardless, so this is a defensive cleanup not a behavior regression.
Collaborator
|
Commit: 73dfa49 |
hectorcast-db
approved these changes
Jun 2, 2026
andrewnester
approved these changes
Jun 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#5368 flipped the workspace routing header from `X-Databricks-Org-Id` to `X-Databricks-Workspace-Id` across five hand-written CLI code paths. Review on that PR identified five more raw `apiClient.Do` call sites that were quietly missing the routing header entirely. On unified hosts with `cfg.WorkspaceID` set, those calls land on the gateway with no routing information and can fail or be misrouted.
Follow-up to #5368 (comment) — splitting the audit work out per the merge-now-audit-after plan.
New call sites covered
All five hit workspace-routed endpoints:
Shared helper
Rather than copying the header-building snippet a sixth time, this PR adds a shared helper:
```go
// libs/auth/headers.go
const WorkspaceIDHeader = "X-Databricks-Workspace-Id"
func WorkspaceIDHeaders(cfg *sdkconfig.Config) map[string]string {
if cfg == nil {
return nil
}
wsID := cfg.WorkspaceID
if wsID == "" || wsID == WorkspaceIDNone {
return nil
}
return map[string]string{WorkspaceIDHeader: wsID}
}
```
The helper returns `nil` when the workspace ID is unset or holds the CLI-only `"none"` sentinel, so callers can pass the result directly to `client.Do` without conditional checks.
Cleanup: consolidate the existing copies
The four existing copies of the same pattern are migrated to the helper:
`libs/filer/workspace_files_client.go` keeps a thin method wrapper around the shared helper because it has a legitimate nil-`workspaceClient` case in its existing tests; the wrapper handles that nil safety and delegates the rest.
Side effect of consolidation
Callers that previously sent `X-Databricks-Workspace-Id: none` when `cfg.WorkspaceID` was the CLI sentinel `"none"` no longer do — the shared helper treats `"none"` as unset, matching the existing `cmd/api/api.go` normalization and the `auth.ResolveWorkspaceID` helper introduced in #5379. In practice, users who set `workspace_id = none` in `.databrickscfg` are on account-scoped auth and these workspace-routed calls wouldn't succeed regardless, so this is a defensive cleanup, not a behavior regression.
Test plan