Audit trail
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import json
|
||||
from uuid import uuid4
|
||||
|
||||
from backend.app.database import get_connection
|
||||
|
||||
|
||||
def record_audit_event(
|
||||
actor_id: str | None,
|
||||
action: str,
|
||||
target_type: str,
|
||||
target_id: str | None = None,
|
||||
outcome: str = 'success',
|
||||
details: dict | None = None,
|
||||
) -> None:
|
||||
safe_details = details or {}
|
||||
with get_connection() as conn:
|
||||
conn.execute(
|
||||
'''INSERT INTO security_audit_events
|
||||
(id, actor_id, action, target_type, target_id, outcome, details)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)''',
|
||||
(str(uuid4()), actor_id, action, target_type, target_id, outcome, json.dumps(safe_details)),
|
||||
)
|
||||
conn.commit()
|
||||
Reference in New Issue
Block a user