Ejemplo n.º 1
0
def value_error(error_instance):
    error("value_error")
    exception(error_instance)
    message = str(error_instance)
    code = 400
    title = 'Bad request'
    return fault(message, STORAGE_0011, code, title)
Ejemplo n.º 2
0
def type_error(error_instance):
    error("type_error")
    exception(error_instance)
    message = str(error_instance).replace("__init__() ", "")
    code = 400
    title = 'Bad request'
    return fault(message, STORAGE_0012, code, title)
Ejemplo n.º 3
0
def bad_request(exception_instance):
    error("bad_request")
    exception(exception_instance)
    message = exception_instance.description
    code = 400
    title = 'Bad request'
    return fault(message, STORAGE_0004, code, title)
Ejemplo n.º 4
0
def connexion_bad_request(exception_instance):
    error("connexion_bad_request")
    exception(exception_instance)
    message = exception_instance.detail
    code = exception_instance.status
    title = exception_instance.title
    return fault(message, STORAGE_9999, code, title)
Ejemplo n.º 5
0
def after_request(response):
    try:
        response = run_debug_toolbar_for_json_if_needed(response)
    except Exception as e:
        exception('after_request.exception: %s', e)
    finally:
        return response
Ejemplo n.º 6
0
def storage_bad_request(exception_instance):
    error("storage_bad_request")
    exception(exception_instance)
    message = exception_instance.description
    code = 409
    title = 'Bad request'
    return fault(message, exception_instance.error_code, code, title)
Ejemplo n.º 7
0
def internal_server_error(error_instance):
    error("internal_server_error")
    exception(error_instance)
    message = str(error_instance)
    code = 500
    if isinstance(error_instance, HTTPException):
        code = error_instance.code
    title = 'Internal server error'
    return fault(message, STORAGE_0001, code, title)
Ejemplo n.º 8
0
def integrity_error(error_instance):
    error("integrity_error")
    exception(error_instance)
    if "unique constraint" in str(error_instance):
        message = "Unique constraint: please check request values on uniquiness"
    else:
        message = str(error_instance)
    code = 400
    title = 'Bad request'
    return fault(message, STORAGE_0014, code, title)
Ejemplo n.º 9
0
def log_stash(response):
    try:
        is_log_stash_mode = (os.environ.get("LOGTASH_MODE") == 'True') or False
        if is_log_stash_mode:
            logger = logging.getLogger('logstash')
            extra = build_log_stash_extra(response)
            current_time = convert_date_with_ms_to_string(now())
            logger.info(current_time, extra=extra)
    except Exception as e:
        exception(e)
Ejemplo n.º 10
0
def request_parameters(to_dict=False):
    parameters = {}
    try:
        if request.method == 'POST' and request.get_json() is not None:
            parameters = request.get_json()
        else:
            parameters = to_json(request.args)
        save_request(parameters)
    except Exception as e:
        exception(e)
    return parameters
Ejemplo n.º 11
0
def invalid_request_error(error_instance):
    error("invalid_request_error")
    exception(error_instance)
    message = str(error_instance) \
        .replace("'", "") \
        .replace("class ", "") \
        .replace("app.classes.", "") \
        .replace("<", "") \
        .replace(">", "")
    code = 400
    title = 'Bad request'
    return fault(message, STORAGE_0013, code, title)
Ejemplo n.º 12
0
def verify_auth_token(token,
                      ip='0.0.0.0',
                      path='/',
                      grant='get_all',
                      raise_error=True):
    token_checked = ("token_checked" in g and g.token_checked)
    if token_checked:
        return True

    if '127.0.0.1' in ip or '0.0.0.0' in ip:
        info('Permission granted. System request.')
        g.token_checked = True
        return True

    try:
        payload = decode_token(token)
        if "login" in payload:
            g.login = payload['login']
        if "id" in payload:
            g.user_id = payload['id']
        if "role" in payload:
            g.user_role = payload['role']
    except Exception as e:
        exception(e)
        if raise_error:
            raise e
        else:
            return False

    permission = check_grants(payload['role'], path, grant)
    if permission is None:
        error('Permission denied. No rights for ' + path)
        if raise_error:
            raise Unauthorized('Permission denied. No rights for ' + path)
        else:
            return False

    g.token_checked = True
    return True
Ejemplo n.º 13
0
def unhandled_exception(exception_instance):
    error("unhandled_exception")
    exception(exception_instance)
    message = str(exception_instance)
    return fault(message, STORAGE_0002, 404, RESOURCE_NOT_FOUND)