faucet_cli/serve/
audit.rs1use crate::serve::history::AuditEntry;
7use crate::serve::rbac::AuthContext;
8use crate::serve::state::ServerState;
9
10pub async fn write(
14 state: &ServerState,
15 ctx: &AuthContext,
16 action: &str,
17 run_id: Option<String>,
18 config_fingerprint: Option<String>,
19 result: &str,
20) {
21 let entry = AuditEntry {
22 id: uuid::Uuid::now_v7().to_string(),
23 timestamp: chrono::Utc::now(),
24 principal: ctx.principal.clone(),
25 role: ctx.role.as_str().to_string(),
26 action: action.to_string(),
27 run_id,
28 config_fingerprint,
29 source_ip: ctx.source_ip.clone(),
30 result: result.to_string(),
31 };
32 if let Err(e) = state.history().record_audit(&entry).await {
33 tracing::warn!(
34 action, principal = %ctx.principal, error = %e,
35 "failed to write audit record"
36 );
37 }
38}