Add 'datumctl api proxy': a local authenticated API proxy#247
Draft
scotwells wants to merge 1 commit into
Draft
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
What users get
A new command that starts a loopback proxy to the Datum Cloud API of your datumctl session, injecting your credentials on every request and refreshing them transparently. Any local tool — a dev server, a test harness,
curl— talks to the platform with zero token plumbing:API_URLswapping gives dev/prod parity.--project/--organizationre-base the proxy at one control plane for short URLs. Scope and session are pinned at startup;datumctl auth switchnever repoints a running proxy.Authorizationstripped, tokens never logged or served.502with a Status body andX-Datum-Proxy-Error: truetelling the user to rundatumctl login(never a fake401); upstream errors pass through untouched. Logging out mid-run degrades gracefully and logging back in recovers without a proxy restart.docs/api-proxy.md.Design rationale, security model, and prior art: see the companion enhancement proposal #246.
How it's built
internal/apiproxy/— the engine (no Cobra/keyring imports; token source and upstream injected):httputil.ReverseProxywithRewrite+FlushInterval: -1, refresh-failure cooldown, redacting request log with streaming start/end lines.internal/cmd/api/— theapicommand group andproxysubcommand, registered inroot.go.internal/client/session_endpoint.go— session/endpoint/TLS resolution extracted into a shared helper;ToRESTConfignow uses the same code paths (flag precedence and error messages preserved) so the proxy and resource commands can't drift.internal/authutil/credentials.go—persistingTokenSourcenow re-reads the keyring when a refresh is needed, so long-running consumers track logout/re-login instead of silently refreshing a session the user ended. This touches shared auth code — the diff deserves reviewer attention.auth login→loginin user-facing hints (per repo convention that primary login is top-level), and HOME isolation ininternal/authutil/migrate_test.go, which could previously read the developer's real~/.datumctl/credentials.jsonthrough the mock-keyring fallback.Validation
go test ./... -race;go build,go vet,go installclean.--namespaceflag text, which predates this PR).Known minor follow-ups (reported by review, deliberately not bundled)
Upstream CORS headers pass through un-stripped; hidden root flags like
--serverare silently ignored by the proxy; degenerate session endpoints can surface a raw error; per-request IDs /-v6transport dumps not wired; host allowlist is port-agnostic (matches kubectl proxy prior art).🤖 Generated with Claude Code