# Path: drift/core/extensions/driftconfig.py
# def check_tenant(f):
#     """Make sure current tenant is provided, provisioned and active."""
#     @wraps(f)
#     def _check(*args, **kwargs):
#         if not tenant_from_hostname:
#             abort(
#                 http_client.BAD_REQUEST,
#                 description="No tenant specified. Please specify one using host name prefix or "
#                 "the environment variable DRIFT_DEFAULT_TENANT."
#             )
# 
#         conf = current_app.extensions['driftconfig'].get_config()
#         if not conf.tenant:
#             # This will trigger a proper exception
#             try:
#                 get_config_for_request(allow_missing_tenant=False)
#                 raise RuntimeError("Should not reach this.")
#             except TenantNotConfigured as e:
#                 abort(http_client.BAD_REQUEST, description=str(e))
# 
#         check_tenant_state(g.conf.tenant)
#         return f(*args, **kwargs)
# 
#     return _check


import os
import datetime
import logging
import redis
from six.moves import cPickle as pickle, http_client
from flask import g, abort
from flask import _app_ctx_stack as stack
from werkzeug._compat import integer_types
from werkzeug.local import LocalProxy
from driftconfig.util import get_parameters
from drift.core.extensions.driftconfig import check_tenant
class RedisExtension(object):
    """Redis Flask extension."""
    def __init__(self, app=None):
        self.app = app
        if app is not None:
            self.init_app(app)

    def init_app(self, app):
        if not hasattr(app, 'extensions'):
            app.extensions = {}

        app.extensions['redis'] = self
        app.before_request(self.before_request)

    def before_request(self):
        g.redis = LocalProxy(self.get_session)

    def get_session(self):
        ctx = stack.top
        if ctx is not None:
            if not hasattr(ctx, 'redis_session'):
                ctx.redis_session = get_redis_session()
            return ctx.redis_session

    def get_session_if_available(self):
        """Return redis session if it's already initialized."""
        if stack.top:
            return getattr(stack.top, 'redis_session', None)



# Path: drift/core/extensions/driftconfig.py
# def check_tenant(f):
#     """Make sure current tenant is provided, provisioned and active."""
#     @wraps(f)
#     def _check(*args, **kwargs):
#         if not tenant_from_hostname:
#             abort(
#                 http_client.BAD_REQUEST,
#                 description="No tenant specified. Please specify one using host name prefix or "
#                 "the environment variable DRIFT_DEFAULT_TENANT."
#             )
# 
#         conf = current_app.extensions['driftconfig'].get_config()
#         if not conf.tenant:
#             # This will trigger a proper exception
#             try:
#                 get_config_for_request(allow_missing_tenant=False)
#                 raise RuntimeError("Should not reach this.")
#             except TenantNotConfigured as e:
#                 abort(http_client.BAD_REQUEST, description=str(e))
# 
#         check_tenant_state(g.conf.tenant)
#         return f(*args, **kwargs)
# 
#     return _check


# Path: drift/core/resources/redis.py
import os
import datetime
import logging
import redis
from six.moves import cPickle as pickle, http_client
from flask import g, abort
from flask import _app_ctx_stack as stack
from werkzeug._compat import integer_types
from werkzeug.local import LocalProxy
from driftconfig.util import get_parameters
from drift.core.extensions.driftconfig import check_tenant

class RedisExtension(object):
    """Redis Flask extension."""
    def __init__(self, app=None):
        self.app = app
        if app is not None:
            self.init_app(app)

    def init_app(self, app):
        if not hasattr(app, 'extensions'):
            app.extensions = {}

        app.extensions['redis'] = self
        app.before_request(self.before_request)

    def before_request(self):
        g.redis = LocalProxy(self.get_session)

    def get_session(self):
        ctx = stack.top
        if ctx is not None:
            if not hasattr(ctx, 'redis_session'):
                ctx.redis_session = get_redis_session()
            return ctx.redis_session

    def get_session_if_available(self):
        """Return redis session if it's already initialized."""
        if stack.top:
            return getattr(stack.top, 'redis_session', None)



@check_tenant