audit-log: expose total count in /api/audit-log response

Per iris's dashboard-side ask: return { entries, total } instead of a
bare array so the UI can show 'latest 500 of N' rather than silently
capping at the clamp. Adds AuditLog::count_total().
This commit is contained in:
atlas 2026-06-13 13:49:54 +02:00
commit 962259a8d6
2 changed files with 23 additions and 5 deletions

View file

@ -1315,12 +1315,21 @@ async fn api_container_resources() -> Response {
/// `GET /api/audit-log` — most-recent agent-initiated privileged-action
/// audit entries, newest first (server-clamped to 500). Backs the
/// operator dashboard's audit view. Returns `Vec<AuditEntry>` JSON.
/// operator dashboard's audit view. Returns
/// `{ "entries": [AuditEntry…], "total": N }` so the UI can show
/// "latest 500 of N" rather than silently capping. `ts_unix` is in
/// **seconds**.
async fn api_audit_log(State(state): State<AppState>) -> Response {
match state.coord.audit_log.list_recent(500) {
Ok(rows) => axum::Json(rows).into_response(),
Err(e) => error_response(&format!("audit-log: {e:#}")),
}
const LIMIT: usize = 500;
let entries = match state.coord.audit_log.list_recent(LIMIT) {
Ok(rows) => rows,
Err(e) => return error_response(&format!("audit-log: {e:#}")),
};
let total = match state.coord.audit_log.count_total() {
Ok(n) => n,
Err(e) => return error_response(&format!("audit-log count: {e:#}")),
};
axum::Json(serde_json::json!({ "entries": entries, "total": total })).into_response()
}
/// Validate that a path-param agent name conforms to the hyperhive