# Path: openbrokerapi/helper.py
# def to_json_response(obj):
#     """ Following https://stackoverflow.com/a/1118038 """
#     from flask import jsonify
#     return jsonify(_to_dict(obj))
# 
# def version_tuple(v):
#     return tuple(map(int, (v.split("."))))
# 
# Path: openbrokerapi/response.py
# class ErrorResponse:
#     def __init__(self,
#                  error: str = None,
#                  description: str = None):
#         self.error = error
#         self.description = description
# 
# Path: openbrokerapi/settings.py
# MIN_VERSION = version_tuple(MIN_VERSION_STR)


import base64
import functools
import logging
from http import HTTPStatus
from openbrokerapi.helper import to_json_response, version_tuple
from openbrokerapi.response import ErrorResponse
from openbrokerapi.settings import MIN_VERSION
    from flask import request
    from flask import request, json
        from flask import request
        from flask import request
    from flask import request
        except ValueError as e:
            return to_json_response(ErrorResponse(
                description='Improper "X-Broker-API-Originating-Identity" header. ' + str(e))
            ), HTTPStatus.BAD_REQUEST
    else:
        request.originating_identity = None


def requires_application_json(f):
    """Decorator for enforcing application/json Content-Type"""

    @functools.wraps(f)
    def wrapped(*args, **kwargs):
        if request.get_json(silent=True) is None:
            er = ErrorResponse(description='Improper Content-Type header. Expecting "application/json"')
            return to_json_response(er), HTTPStatus.BAD_REQUEST
        else:
            return f(*args, **kwargs)

    return wrapped


def get_auth_filter(broker_credentials):
    def requires_auth():
        """Check authentication over all provided usernames else sends a 401 response that enables basic auth"""
        auth = request.authorization
        if auth:
            for credentials in broker_credentials:
                if auth.username == credentials.username and auth.password == credentials.password:
                    return

# Path: openbrokerapi/helper.py
# def to_json_response(obj):
#     """ Following https://stackoverflow.com/a/1118038 """
#     from flask import jsonify
#     return jsonify(_to_dict(obj))
# 
# def version_tuple(v):
#     return tuple(map(int, (v.split("."))))
# 
# Path: openbrokerapi/response.py
# class ErrorResponse:
#     def __init__(self,
#                  error: str = None,
#                  description: str = None):
#         self.error = error
#         self.description = description
# 
# Path: openbrokerapi/settings.py
# MIN_VERSION = version_tuple(MIN_VERSION_STR)


# Path: openbrokerapi/request_filter.py
import base64
import functools
import logging
from http import HTTPStatus
from openbrokerapi.helper import to_json_response, version_tuple
from openbrokerapi.response import ErrorResponse
from openbrokerapi.settings import MIN_VERSION
    from flask import request
    from flask import request, json
        from flask import request
        from flask import request
    from flask import request

        except ValueError as e:
            return to_json_response(ErrorResponse(
                description='Improper "X-Broker-API-Originating-Identity" header. ' + str(e))
            ), HTTPStatus.BAD_REQUEST
    else:
        request.originating_identity = None


def requires_application_json(f):
    """Decorator for enforcing application/json Content-Type"""

    @functools.wraps(f)
    def wrapped(*args, **kwargs):
        if request.get_json(silent=True) is None:
            er = ErrorResponse(description='Improper Content-Type header. Expecting "application/json"')
            return to_json_response(er), HTTPStatus.BAD_REQUEST
        else:
            return f(*args, **kwargs)

    return wrapped


def get_auth_filter(broker_credentials):
    def requires_auth():
        """Check authentication over all provided usernames else sends a 401 response that enables basic auth"""
        auth = request.authorization
        if auth:
            for credentials in broker_credentials:
                if auth.username == credentials.username and auth.password == credentials.password:
                    return

        return to_json_response(ErrorResponse(