# Path: drift/core/extensions/tenancy.py
# def drift_init_extension(app, **kwargs):
# def get_tenant_name(request_headers=None):
# def _flask_get_tenant_name():
# def _get_tenant_from_hostname(*args, **kw):
# def split_host(host):
# def _is_valid_ipv4_address(address):
# 
# Path: drift/utils.py
# def get_tier_name(fail_hard=True):
#     """
#     Get tier name from environment
#     """
#     if 'DRIFT_TIER' in os.environ:
#         return os.environ['DRIFT_TIER']
# 
#     if fail_hard:
#         raise RuntimeError(
#             "No tier specified. Specify one in "
#             "'DRIFT_TIER' environment variable, or use the --tier command "
#             "line argument."
#         )


import logging
from functools import wraps
from six.moves import http_client
from werkzeug.local import LocalProxy
from flask import g, current_app
from flask import _app_ctx_stack as stack
from flask_smorest import abort
from driftconfig.relib import CHECK_INTEGRITY
from driftconfig.util import get_drift_config, get_default_drift_config, TenantNotConfigured
from drift.core.extensions.tenancy import tenant_from_hostname
from drift.utils import get_tier_name

    def _get_table_store(self):
        ts = get_default_drift_config()
        return ts

    def before_request(self):
        # Add a just-in-time getter for config
        g.conf = LocalProxy(self.get_config)

    def after_request(self, response):
        # TODO: Move this logice elsewhere
        if current_app.config.get("no_response_caching", False) or not response.cache_control.max_age:
            # Turn off all caching
            response.cache_control.no_cache = True
            response.cache_control.no_store = True
            response.cache_control.max_age = 0

        return response

    def get_config(self):
        ctx = stack.top
        if ctx is not None:
            if not hasattr(ctx, 'driftconfig'):
                ctx.driftconfig = get_config_for_request()
            return ctx.driftconfig


def get_config_for_request(allow_missing_tenant=True):
    conf = get_drift_config(
        ts=current_app.extensions['driftconfig'].table_store,

# Path: drift/core/extensions/tenancy.py
# def drift_init_extension(app, **kwargs):
# def get_tenant_name(request_headers=None):
# def _flask_get_tenant_name():
# def _get_tenant_from_hostname(*args, **kw):
# def split_host(host):
# def _is_valid_ipv4_address(address):
# 
# Path: drift/utils.py
# def get_tier_name(fail_hard=True):
#     """
#     Get tier name from environment
#     """
#     if 'DRIFT_TIER' in os.environ:
#         return os.environ['DRIFT_TIER']
# 
#     if fail_hard:
#         raise RuntimeError(
#             "No tier specified. Specify one in "
#             "'DRIFT_TIER' environment variable, or use the --tier command "
#             "line argument."
#         )


# Path: drift/core/extensions/driftconfig.py
import logging
from functools import wraps
from six.moves import http_client
from werkzeug.local import LocalProxy
from flask import g, current_app
from flask import _app_ctx_stack as stack
from flask_smorest import abort
from driftconfig.relib import CHECK_INTEGRITY
from driftconfig.util import get_drift_config, get_default_drift_config, TenantNotConfigured
from drift.core.extensions.tenancy import tenant_from_hostname
from drift.utils import get_tier_name


    def _get_table_store(self):
        ts = get_default_drift_config()
        return ts

    def before_request(self):
        # Add a just-in-time getter for config
        g.conf = LocalProxy(self.get_config)

    def after_request(self, response):
        # TODO: Move this logice elsewhere
        if current_app.config.get("no_response_caching", False) or not response.cache_control.max_age:
            # Turn off all caching
            response.cache_control.no_cache = True
            response.cache_control.no_store = True
            response.cache_control.max_age = 0

        return response

    def get_config(self):
        ctx = stack.top
        if ctx is not None:
            if not hasattr(ctx, 'driftconfig'):
                ctx.driftconfig = get_config_for_request()
            return ctx.driftconfig


def get_config_for_request(allow_missing_tenant=True):
    conf = get_drift_config(
        ts=current_app.extensions['driftconfig'].table_store,

        tenant_name=tenant_from_hostname,