# Path: drift/core/extensions/jwt.py
# JWT_VERIFY_CLAIMS = ['signature', 'exp', 'iat']
# JWT_REQUIRED_CLAIMS = ['exp', 'iat', 'jti']
# JWT_ALGORITHM = 'RS256'
# JWT_EXPIRATION_DELTA = 60 * 60 * 24
# JWT_LEEWAY = 10
# JWT_EXPIRATION_DELTA_FOR_SERVICES = 60 * 60 * 24 * 365
# TRUSTED_ISSUERS = {'drift-base'}
# WHITELIST_ENDPOINTS = [
#     r"^api-docs\.",  # the marshmalloc documentation endpoint
#     r"^static$",  # the marshmalloc documentation endpoint
# ]
# SESSION_COOKIE_NAME = 'drift-session'
# ALPHABET = string.ascii_uppercase + string.ascii_lowercase + string.digits + '-_'
# ALPHABET_REVERSE = dict((c, i) for (i, c) in enumerate(ALPHABET))
# BASE = len(ALPHABET)
# SIGN_CHARACTER = '$'
# def drift_init_extension(app, api, **kwargs):
# def check_jwt_authorization():
# def query_current_user():
# def requires_auth(got_auth):
# def abort_unauthorized(description):
# def register_auth_provider(app, provider, handler):
# def requires_roles(_roles):
#     def wrapper(fn):
#         def decorator(*args, **kwargs):
# def jwt_not_required(fn):
# def error_handler(error):
# def _fix_legacy_auth(auth_info):
# def _authenticate(auth_info, conf):
#     def post(self, auth_info):
#     def post(self, auth_info):
#     def get(self):
#     def post(self):
# def authenticate_with_provider(auth_info):
# def issue_token(payload, expire=None):
# def get_auth_token_and_type():
# def verify_jwt(token, conf):
# def _is_jwt(token):
# def lookup_bearer_token(token, conf):
# def verify_token(token, auth_type, conf):
# def create_standard_claims(expire=None):
# def cache_token(payload, expire=None):
# def get_cached_token(jti):
# def num_encode(n):
# def num_decode(s):
#     def get(self):
# def endpoint_info(current_user):
# class AuthRequestSchema(ma.Schema):
#     class Meta:
# class AuthSchema(ma.Schema):
#     class Meta:
# class AuthApi(MethodView):
# class AuthLoginApi(MethodView):
# class AuthLogoutApi(MethodView):
# class JwkSchema(ma.Schema):
#     class Meta:
# class JwksSchema(ma.Schema):
#     class Meta:
# class JWKSApi(MethodView):
# 
# 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 os
import logging
import logging.config
import json
import datetime
import sys
import time
import uuid
import six
    import inspect
from logging.handlers import SysLogHandler
from socket import gethostname
from collections import OrderedDict
from functools import wraps
from logstash_formatter import LogstashFormatterV1
from six.moves.urllib.parse import urlsplit
from flask import g, request
from drift.core.extensions.jwt import current_user
from drift.utils import get_tier_name


def get_clean_path_from_url(url):
    """extract the endpoint path from the passed in url and remove
    service information and any id's so that the endpoint path
    might be easily used in grouping.
    """
    clean_path = None
    try:
        lst = urlsplit(url)
        path = lst.path
        lst = path.split("/")
        for i, l in enumerate(lst):
            try:
                int(l)
            except ValueError:
                pass
            else:
                lst[i] = "<int>"
        # assume that the service name is the first part so we skip it
        clean_path = "/" + "/".join(lst[2:])
    except Exception:
        # Todo: should report these errors
        pass
    return clean_path


def get_log_details():
    details = OrderedDict()
    tenant_name = None

# Path: drift/core/extensions/jwt.py
# JWT_VERIFY_CLAIMS = ['signature', 'exp', 'iat']
# JWT_REQUIRED_CLAIMS = ['exp', 'iat', 'jti']
# JWT_ALGORITHM = 'RS256'
# JWT_EXPIRATION_DELTA = 60 * 60 * 24
# JWT_LEEWAY = 10
# JWT_EXPIRATION_DELTA_FOR_SERVICES = 60 * 60 * 24 * 365
# TRUSTED_ISSUERS = {'drift-base'}
# WHITELIST_ENDPOINTS = [
#     r"^api-docs\.",  # the marshmalloc documentation endpoint
#     r"^static$",  # the marshmalloc documentation endpoint
# ]
# SESSION_COOKIE_NAME = 'drift-session'
# ALPHABET = string.ascii_uppercase + string.ascii_lowercase + string.digits + '-_'
# ALPHABET_REVERSE = dict((c, i) for (i, c) in enumerate(ALPHABET))
# BASE = len(ALPHABET)
# SIGN_CHARACTER = '$'
# def drift_init_extension(app, api, **kwargs):
# def check_jwt_authorization():
# def query_current_user():
# def requires_auth(got_auth):
# def abort_unauthorized(description):
# def register_auth_provider(app, provider, handler):
# def requires_roles(_roles):
#     def wrapper(fn):
#         def decorator(*args, **kwargs):
# def jwt_not_required(fn):
# def error_handler(error):
# def _fix_legacy_auth(auth_info):
# def _authenticate(auth_info, conf):
#     def post(self, auth_info):
#     def post(self, auth_info):
#     def get(self):
#     def post(self):
# def authenticate_with_provider(auth_info):
# def issue_token(payload, expire=None):
# def get_auth_token_and_type():
# def verify_jwt(token, conf):
# def _is_jwt(token):
# def lookup_bearer_token(token, conf):
# def verify_token(token, auth_type, conf):
# def create_standard_claims(expire=None):
# def cache_token(payload, expire=None):
# def get_cached_token(jti):
# def num_encode(n):
# def num_decode(s):
#     def get(self):
# def endpoint_info(current_user):
# class AuthRequestSchema(ma.Schema):
#     class Meta:
# class AuthSchema(ma.Schema):
#     class Meta:
# class AuthApi(MethodView):
# class AuthLoginApi(MethodView):
# class AuthLogoutApi(MethodView):
# class JwkSchema(ma.Schema):
#     class Meta:
# class JwksSchema(ma.Schema):
#     class Meta:
# class JWKSApi(MethodView):
# 
# 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/logging.py
import os
import logging
import logging.config
import json
import datetime
import sys
import time
import uuid
import six
    import inspect
from logging.handlers import SysLogHandler
from socket import gethostname
from collections import OrderedDict
from functools import wraps
from logstash_formatter import LogstashFormatterV1
from six.moves.urllib.parse import urlsplit
from flask import g, request
from drift.core.extensions.jwt import current_user
from drift.utils import get_tier_name



def get_clean_path_from_url(url):
    """extract the endpoint path from the passed in url and remove
    service information and any id's so that the endpoint path
    might be easily used in grouping.
    """
    clean_path = None
    try:
        lst = urlsplit(url)
        path = lst.path
        lst = path.split("/")
        for i, l in enumerate(lst):
            try:
                int(l)
            except ValueError:
                pass
            else:
                lst[i] = "<int>"
        # assume that the service name is the first part so we skip it
        clean_path = "/" + "/".join(lst[2:])
    except Exception:
        # Todo: should report these errors
        pass
    return clean_path


def get_log_details():
    details = OrderedDict()
    tenant_name = None

    tier_name = get_tier_name()