Download utils/audit.py from Hfzune/Test: direct link, hf CLI and curl.
- Browser
- Download file 783 Bytes
-
https://huggingface.co/spaces/Hfzune/Test/resolve/main/utils/audit.py
- Command line
-
hf download hf://spaces/Hfzune/Test/utils/audit.py
-
curl -L -o audit.py https://huggingface.co/spaces/Hfzune/Test/resolve/main/utils/audit.py
783 Bytes
| import json | |
| import logging | |
| from datetime import datetime, timezone | |
| from db.init import get_conn | |
| log = logging.getLogger("audit") | |
| def audit(admin_id: str, action: str, target_user_id=None, details=None): | |
| try: | |
| with get_conn() as conn: | |
| conn.execute( | |
| """INSERT INTO admin_audit(admin_id, action, target_user_id, | |
| timestamp, details) | |
| VALUES (?, ?, ?, ?, ?)""", | |
| ( | |
| str(admin_id), | |
| action, | |
| target_user_id, | |
| datetime.now(timezone.utc).isoformat(), | |
| json.dumps(details or {}), | |
| ), | |
| ) | |
| except Exception: | |
| log.exception("audit write failed") |