23 lines
686 B
Python
23 lines
686 B
Python
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() |