feat: JSON /api/v1 admin API on a shared approve/deny core #35
Loading…
Reference in a new issue
No description provided.
Delete branch "impl/admin-json-api"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Versioned JSON admin surface next to the HTML review UI, per design/webui/admin-json-api.md. internal/adminops extracts the approve/deny core from its two existing copies and both consumers are refactored onto it with byte-identical output. /api/v1 on the admin listener: info, requests list/get, approve, deny, calls, read-only rules. No SSE - deferred with requestlog.Watch. JSON errors everywhere including a catch-all for unknown /api/ paths. rules omits env/env_files deliberately. AuthMiddleware answers /api/ with 401 JSON + WWW-Authenticate Bearer, query token never authenticates the API. requestlog.ErrNotFound sentinel drives 404s. Adds wraptool requests list --json. Reviewed twice, merge-ready, all gates green. Generated with Claude Code.
Adds a read/act JSON surface on the same listener/mux/token as the HTML Web UI: GET info/requests/requests/{id}/calls/rules, POST approve/deny. Handlers are encode/decode veneers over the store and adminops — no new logic. AuthMiddleware now recognizes /api/ paths: Bearer/cookie only, 401 JSON with WWW-Authenticate instead of the HTML login form, and never sets a session cookie for a scripted client. No SSE/events endpoint — deferred per design/webui/admin-json-api.md. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011GjxKV7SYeStUbfFBFe34Erequests approve/denyonto adminops; addlist --json6f6e76e034adminops.Approve left result.Outcome at its zero value (OutcomeNewRule) on the ApplyErr branch, so both the JSON API and CLI reported success ("new_rule"/"Added new allow rule...") when config.ApplyRequest had failed and nothing was written. Set Outcome = OutcomeNotApplied there, and reorder the two call sites' ApplyErr/OutcomeNotApplied checks so the apply-failure message still wins over the apply=false one now that both share the same Outcome value. Also: requestlog.ErrNotFound replaces requestErrorStatus's "not found" substring match; an /api/ catch-all returns the JSON error shape for unknown paths/methods instead of ServeMux's default text/plain; dropped the dead ApproveResult.Request field; corrected the Snippet doc comment; added auth test pins (session cookie ok, wrong Bearer is JSON 401) and a comment on /api/v1/rules omitting Env/EnvFiles. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011GjxKV7SYeStUbfFBFe34E