Skip to content

feat: brainpod api - #27

Merged
jeroenrinzema merged 1 commit into
mainfrom
feat/api-passthrough
Nov 25, 2026
Merged

jeroenrinzema merged 1 commit into
mainfrom
feat/api-passthrough

Conversation

@jeroenrinzema

Copy link
Copy Markdown
Collaborator

Summary

Adds brainpod api, a gh api-style passthrough. Agents and scripts can use it to reach endpoints that have no first-class command (onboarding, builds and build logs, secrets) without the API token ever leaving the CLI.

brainpod [--pod <pod>] api <PATH> [-X GET|POST|PUT|PATCH|DELETE] [--input <file|->] [-q KEY=VALUE]...
  api_path_segments(PATH)      # relative only; {pod} filled from --pod
  Client::send(method, ...)    # same endpoint, auth and ApiError envelope as every command
  print                        # pretty JSON; text as-is; 204 prints nothing
  • The token stays inside the CLI. The path is split into segments, and each segment is added, percent-encoded, to the configured endpoint. The CLI rejects schemes (https://, localhost:8080), a leading //, ?/# (use -q), backslashes, control characters, and ./.. segments, including %2e. A path copied out of a repository therefore cannot send the token to another host.
  • Method: GET by default, POST when --input is given (as gh does). An explicit -X wins.
  • {pod} is replaced from --pod / BRAINPOD_POD / config. The command errors clearly when no pod is selected; otherwise a pod is optional.
  • Event streams are refused, with a pointer to brainpod events --watch.
  • describe api: requirements apiToken: true, pod: null; effect conditional-remote-write. The next steps say to prefer first-class commands and name /v1/openapi.json as the contract.
  • Client::request is now built on the new Client::send, so auth and error handling exist once.

This is the escape hatch the agent skill (brainpodnl/skills) will use for the GitHub-first flow, until those endpoints get commands of their own.

Evidence

  • cargo test: 253 passed. That includes 11 path-validator tests, one per rejection plus the accepted forms and {pod}, and parse tests for method defaulting.
  • cargo clippy --all-targets: no new warnings.
  • Against production (GET only):
    $ brainpod api /v1/me                                        → the user as pretty JSON, exit 0
    $ brainpod --json --pod nonexistent-pod-zz9 api /v1/pods/{pod}
    {"error":{"code":"NOT_FOUND","httpStatus":404,"message":"pod not found","requestId":"b3d0a55e-..."}}
    $ brainpod api https://example.com/v1/me
    error: API path must be relative to the configured endpoint, such as /v1/me; URLs are not accepted
    

Merge Danger

Door: two-way. It adds a command; existing commands only change in that Client::request now delegates to send.

Blast Radius: small. Every JSON command goes through the refactored request; the test suite covers its error and non-JSON paths.

Add a gh api-style passthrough for API endpoints without a first-class command. PATH must be relative to the configured endpoint (URLs, //, dot segments, backslashes, ?/# and control characters are rejected locally), so the API token never leaves the CLI. {pod} expands to the selected pod; -X defaults to GET, or POST with --input; -q adds query parameters. Responses print as JSON; event streams point to brainpod events --watch.
@jeroenrinzema
jeroenrinzema added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 6ff05b0 Nov 25, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants