Last active
April 24, 2020 09:40
-
-
Save MrLotU/fb2b84abd9584556ca22e5280fac884d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@staticmethod | |
def log(f=None): | |
def deco(f): | |
@functools.wraps(f) | |
def func(*args, **kwargs): | |
audit = AuditModel() | |
user = request.headers.get("X-Auth-User") | |
if user is None: | |
return 'UNAUTHORIZED. Please provide X-Auth-User header.', 403 | |
audit.user = user | |
audit.action = f'{f.__module__}.{f.__name__}' | |
audit.timestamp = datetime.utcnow() | |
if 'audit' in f.__code__.co_varnames: | |
kwargs['audit'] = audit | |
result = f(*args, **kwargs) | |
if not audit.abort: | |
audit.save(force_insert=True) | |
return result | |
return func | |
if f and callable(f): | |
return deco(f) | |
return deco |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment