#124 Audit log export as JSON lines
Originally created by: bosd
Implements the second slice of [#119]: exporting the audit log. dopbase audit export streams records as JSON lines to standard output or a file, so an operator can ship them to external, write-once storage.
Stacked on [#123]: this branch builds on feat/audit-chain, so the PR currently shows that commit too. Once [#123] merges (or on a rebase) only the export commit remains; review 8e9eae3 for this change. Retention and the read-only auditor role from [#119] follow in separate PRs.
Summary
-
dopbase audit exportwrites one JSON object per line to standard output, or to a file with--output <FILE>. Files are written atomically with owner-only permissions (0600) through the same path assecret export, and an existing file is never replaced without--force. -
The export follows pagination to the end, so a full export never silently stops at the 200-record API page limit.
--limit <N>caps the stream when a partial export is wanted, and--action,--project(name or ID),--environment(reference or ID), and--actor(email or actor ID) narrow it. Without filters the whole log is exported. -
The audit list API now carries the chain fields
seq,prevHash, andrecordHashon every item, so each exported line keeps the evidence needed to check and anchor the copy outside Dopbase. The fields are absent only for records that predate the chain and have not been sealed yet. -
Standard output stays raw JSON lines in every mode so it can be piped directly (
dopbase audit export | jq ...); with--outputand--jsonthe count and path are printed as an object instead.
Compatibility
- Additive only: the three chain fields join the audit list response, older clients ignore them, and all existing filters, endpoints, and clients are unchanged.
- Export reads the audit log through the existing list API, so it is administrator-only exactly like reading the log, and it reads no secret values.
- The new
audit::collectionpath builder replaces no existing route;GET /api/v1/audit-eventsis unchanged apart from the added response fields.
Verification
cargo fmt --checkcargo clippy --locked --all-targets --all-features -- -D warningscargo test: cli 211 (new tests cover one JSON line per record with chain fields and newest-first order, action/project/environment/actor filters, a failed project lookup, a zero limit, a capped stream, 205 records flowing past one API page through the cursor, private file output that refuses to overwrite without--force, and the--jsonsummary), constants 4 (encoding of the new filter builder), main 27, services 21, users 15, backups 9. The 3 pre-existingcommands::export::*failures need the util-linuxscriptbinary and are unrelated to this change.bun run test:docs,bun run test:github(17/17),bunx prettier --checkon the changed Markdown.
Checklist
- [x] I kept this pull request focused on one problem.
- [x] I added or updated tests for behavior changes, or explained why tests are not needed.
- [x] I updated the documentation and
CHANGELOG.mdwhen public behavior changed, or explained why they are not needed. - [x] I updated relevan documentation inside
/docs
Originally posted by: bosd
Superseded by [#131], which merged this work (rebased onto main, with review hardening on top). Closing.
Related
Tickets:
#131Ticket changed by: bosd