Skip to content

Instantly share code, notes, and snippets.

@shar1z
Created August 1, 2022 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shar1z/22ed3d2b374fff5e4d90083c48011dbd to your computer and use it in GitHub Desktop.
Save shar1z/22ed3d2b374fff5e4d90083c48011dbd to your computer and use it in GitHub Desktop.
"""
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