Repository navigation
feat(api-keys): pause and resume a key instead of only revoking it - #445
Merged
Merged
Conversation
A key used to be `active` or `revoked`, and revoking is terminal and drops the row from the list, so there was no way to stop a key temporarily and bring it back. Add `paused` (rant 2026-11-12T14:13:23, item 1). - dao: `LIVE_KEY_STATUSES` is the single source for the two switchable values; list / rename / revoke guards derive their SQL from it instead of each spelling the set. `revoked` stays terminal: no path writes it back. - PATCH /api/api-keys/:id accepts `status: active|paused` next to `name`. Invalid values are 400, and the message names every accepted one. - GET /api/api-keys marks the caller's own key with `current`. - Pausing the key the request is authenticated with is refused (400). That key is also the session credential, so pausing it would sign the caller out, and the next login would mint a fresh key over the pause — the pause would undo itself. Refusing is the only exit that is neither a lockout nor a no-op; the UI disables that one button and says why. - UI: badge + action come from one three-state map (the shape the sharing page already uses, C2153), and each row gets a pause/resume button. The previously unreachable non-active pill branch is now reachable. - docs/architecture.md and ui/README.md are updated with the new endpoint behaviour and the session-key restriction.
This was referenced Nov 12, 2026
Merged
argszero
added a commit
that referenced
this pull request
Nov 12, 2026
Two commits since v0.7.34, no schema change (still 18): - #445 lets an API key be paused and resumed instead of only revoked. - #446 breaks the transactions summary down by API key. The version string moves in the five carriers deploy_gate guards: Cargo.toml, Cargo.lock, Dockerfile (three places), docker-compose.yml (two) and the new CHANGELOG heading. Co-authored-by: argszero <argszero@argszerodeMac-mini.local>
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
A distribution key could only be
activeorrevoked. Revoking is terminal and drops the row out of the list, so there was no way to stop a key temporarily and bring it back — the settings page could not even show a key that was not active.This adds the third state,
paused:active/paused/revoked, whererevokedis still terminal and still delete-only.dao::LIVE_KEY_STATUSESis the single source for the two switchable values; the list, rename, enable/disable and revoke guards derive their SQL from it instead of each spelling the set.PATCH /api/api-keys/:idnow takesstatus: active|pausedalongsidename(both optional, at least one required). An invalid value is a 400 whose message names every accepted one. Non-owner, missing and already-revoked are all the same 404, as before.GET /api/api-keyslistsactiveandpausedrows and marks the caller's own key withcurrent. Therevokeddisplay semantics are unchanged.find_api_key_user_and_idstill requiresactive, so a paused key stops working for both the gateway and the platform API the moment it is paused.The one thing this PR deliberately does not do
Pausing the key the request is authenticated with is refused (400). The reason is architectural rather than cautious: an API key here is also the session credential (
AuthUserextracts through the samefind_api_key_user_and_id), so pausing your own key ends the session — and on the next loginget_or_create_api_keyfinds noactiverow and mints a fresh key, which makes that pause cosmetic (that is exactly the hole the work order asked to close). The alternative — never mint while a paused row exists — would let a user pause their last key and then be unable to sign in at all, so the row could never be resumed.Both of those exits are broken, so the endpoint takes the third one: it refuses, and the UI disables that single button with the reason attached ("this is the key you are signed in with").
get_or_create_api_keyis left exactly as it was, and the hole closes structurally instead: the key thatget_or_create_api_keywill find can never be paused, so a login can never mint a second key over a pause.api_key_cannot_pause_the_key_it_is_signed_in_withpins that (it asserts the re-login returns the very same key).The consequence to be aware of: the oldest active key — the one login returns — cannot be paused from a browser session, while every key created afterwards can. If that trade is not what you want, the real fix is separating the session credential from the distribution key, which is a much larger change than this PR and is not attempted here.
UI
Badge and action come from one three-state map, the same shape the sharing page already uses for its three states (C2153) — never a two-value ternary, which is how "relisted" once got reported as "resumed". Both the pill text and the button label go through i18n keys in
zhanden; no literal strings in JS. The "non-active" pill branch that existed inrenderSettingswas unreachable before (the backend filtered those rows out) and is reachable now.Related Issue
No tracked issue: this implements the host's work order filed as rant
2026-11-12T14:13:23(agent=aitokenpool), item ①.Item ② of the same rant (a per-key usage comparison on the transactions page) is not in this PR — it follows separately, branched from the tip this one lands on.
Changes
src/dao.rs— the status set,set_api_key_status, and the widened guardssrc/routes/api_keys.rs— PATCH takesstatus,currentmarking, the session-key guardsrc/routes/mod.rs— route registration + three endpoint testsui/js/app.js+ui/js/i18n.js— pause/resume button, three-state map,zh&enkeysdocs/architecture.md,ui/README.md— the endpoint list and the settings-page descriptionsrc/i18n_pack.rsmoved to the values the gates report (key counts,T()literal counts, backend message count,ERR_MAPentries) — these exist to prove the scanners are not blind, so they are updated rather than loosenedstatusalready exists withDEFAULT 'active')Tests
cargo test— 610 passed, 0 failedcargo fmt --check— cleancargo clippy --all-targets -- -D warnings— cleanNew tests, and the direction each was measured in:
api_key_pause_stops_the_key_and_resume_brings_it_backpaused, it can still be renamed, resume → the same key works again, and a paused row can still be revokedapi_key_cannot_pause_the_key_it_is_signed_in_withactive, and a re-login returns the same key (no second key minted)api_key_status_rejects_values_outside_the_live_pairrevoked/off/on/ACTIVE/""are 400, an empty body is 400, and a revoked key cannot be revivedthe_status_400_names_every_accepted_valueLIVE_KEY_STATUSES, read from the source so the two cannot driftMutation evidence (the failure was actually measured, not assumed). The three endpoint tests were also run against the unmodified
05716b9tree, in a separate worktree ofupstream/mainwith only the tests added: all three fail there, for the behaviour and not for a missing symbol —— i.e. the old endpoint could not express a status change at all (
RenameKeyReqrequiredname). The session-key guard's own test was measured the other way, with the guard switched off in this tree: it then fails on暂停自己应被拒绝withleft: 200, right: 400.Checklist
feat/…)src/routes/mod.rsedit outside tests is the one-identifier registration (api_keys::rename→api_keys::patch), the same step every sibling endpoint takes