Files
agentic-soc-platform/backend/apps/audit/context.py
funnywolf b6b4cbf017 0.4.0 I always have a choice
You shape nothing until you hold everything.
2026-06-27 19:08:48 +08:00

20 lines
378 B
Python

from contextlib import contextmanager
from threading import local
_state = local()
def get_current_actor():
return getattr(_state, "actor", None)
@contextmanager
def audit_actor(actor):
previous = get_current_actor()
_state.actor = actor if getattr(actor, "is_authenticated", True) else None
try:
yield
finally:
_state.actor = previous