Created
August 1, 2022 09:55
-
-
Save shar1z/22ed3d2b374fff5e4d90083c48011dbd 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
""" | |
decorators.py - creating the credentials | |
""" | |
import functools | |
from contextvars import ContextVar, copy_context | |
dynamodb_session_keys = ContextVar("dynamodb_session_keys", default=None) | |
def dynamodb_tenant_isolation(func): | |
@functools.wraps(func) | |
def inner(event, context): | |
ctx = copy_context() | |
session_keys = generate_credentials(event) # the logic implemented earlier | |
ctx.run(_set_dynamodb_session_keys, session_keys) | |
return ctx.run(func, event, context) | |
return inner | |
def _set_dynamodb_session_keys(session_keys): | |
dynamodb_session_keys.set(session_keys) | |
def get_dynamodb_session_keys(): | |
"""accessor to get the relevant credentials""" | |
return dynamodb_session_keys.get() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment