"""Application Handlers. Requests are redirected to handlers, which are responsible for getting information from the URL and passing it down to the logic layer. The way each layer talks to each other is through Response objects which defines the type status of the data and the data itself. Please note: the Orchard uses the term handlers over views as convention for clarity See: oto.response for more details. """ from flask import g, jsonify, request from owsresponse import response from owsresponse.adaptors.flask import flaskify from JWT_to_principal import config from JWT_to_principal.api import app from JWT_to_principal.logic import hello, cerbos, principal from tests.utils import test_data @app.route("/", methods=["GET"]) def hello_world(): """Hello World with an optional GET param "name".""" name = request.args.get("name", "") return flaskify(hello.say_hello(name)) @app.route(config.HEALTH_CHECK, methods=["GET"]) def health(): """Check the health of the application.""" return jsonify({"status": "ok"}) @app.route("/check/", methods=["GET"]) def cerbos_check(orchardIdentityId): """Hydrate JWT. """ return flaskify(response.Response(cerbos.check(orchardIdentityId, test_data.action_view, test_data.account_1))) @app.route("/hydrate/", methods=["GET"]) def hydrate_jwt(orchardIdentityId): """Hydrate JWT. """ return flaskify(response.Response(principal.hydrate_JWT(orchardIdentityId))) @app.errorhandler(500) def exception_handler(error): """Handle error when uncaught exception is raised. Default exception handler. Note: Exception will also be sent to Sentry if config.SENTRY is set. Returns: flask.Response: A 500 response with JSON 'code' & 'message' payload. """ message = ( "The server encountered an internal error " "and was unable to complete your request." ) g.log.exception(error) return flaskify(response.create_fatal_response(message))