ISO-27001-Risk-Management/risks/audit_context.py

22 lines
845 B
Python
Raw Normal View History

import threading
# ---------------------------------------------------------------------------
# Thread-local storage for current user
# ---------------------------------------------------------------------------
_local = threading.local()
# ---------------------------------------------------------------------------
# set_current_user()
# ---------------------------------------------------------------------------
def set_current_user(user):
"""Store the current user in thread-local storage."""
_local.user = user
# ---------------------------------------------------------------------------
# get_current_user()
# ---------------------------------------------------------------------------
def get_current_user():
"""Retrieve the current user from thread-local storage (or None)."""
return getattr(_local, "user", None)