Renamed stuff
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
2021-12-10 23:08:58 +01:00
parent 3b5621278f
commit 2f5a4929a5
15 changed files with 17 additions and 17 deletions

View File

@ -0,0 +1,5 @@
#!/usr/bin/env python3
from .require_decorators import json_required
from .error_handlers import register_all_error_handlers
from .healthchecks import register_health_checks
from .redis_client import redis_client

View File

@ -0,0 +1,20 @@
#!/usr/bin/env python3
from flask import jsonify
def get_standard_error_handler(code: int):
def error_handler(err):
return jsonify({"msg": err.description, "status": code}), code
return error_handler
def register_all_error_handlers(app):
"""
function to register all handlers
"""
error_codes_to_override = [404, 403, 401, 405, 400, 409, 422]
for code in error_codes_to_override:
app.register_error_handler(code, get_standard_error_handler(code))

View File

@ -0,0 +1,13 @@
#!/usr/bin/env python3
from healthcheck import HealthCheck
from flask import Flask
def health_database_status():
return True, f'db is ok'
def register_health_checks(app: Flask):
health = HealthCheck()
health.add_check(health_database_status)
app.add_url_rule("/healthz", "healthcheck", view_func=lambda: health.run())

View File

@ -0,0 +1,3 @@
from flask_redis import FlaskRedis
redis_client = FlaskRedis()

View File

@ -0,0 +1,16 @@
#!/usr/bin/env python3
from flask import request, abort
from functools import wraps
def json_required(f):
@wraps(f)
def call(*args, **kwargs):
if request.is_json:
return f(*args, **kwargs)
else:
abort(400, "JSON required")
return call