From 2e35a7e46f0929438c1c206e3116caa829f07dc6 Mon Sep 17 00:00:00 2001 From: Thomas Duval Date: Fri, 5 Oct 2018 16:54:37 +0200 Subject: Update code to 4.6 official version Change-Id: Ibd0da0e476e24b2685f54693efc11f7a58d40a62 --- moon_authz/moon_authz/http_server.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'moon_authz/moon_authz/http_server.py') diff --git a/moon_authz/moon_authz/http_server.py b/moon_authz/moon_authz/http_server.py index 7d3b1ec3..86d8a914 100644 --- a/moon_authz/moon_authz/http_server.py +++ b/moon_authz/moon_authz/http_server.py @@ -3,15 +3,16 @@ # license which can be found in the file 'LICENSE' in this package distribution # or at 'http://www.apache.org/licenses/LICENSE-2.0'. +import logging from flask import Flask from flask_restful import Resource, Api -import logging from moon_authz import __version__ from moon_authz.api.authorization import Authz +from moon_authz.api.update import Update from python_moonutilities.cache import Cache from python_moonutilities import exceptions -logger = logging.getLogger("moon.authz.http_server") +LOGGER = logging.getLogger("moon.authz.http_server") CACHE = Cache() CACHE.update() @@ -62,15 +63,15 @@ class Server: __API__ = ( - Authz, - ) + Authz, Update +) class Root(Resource): """ The root of the web service """ - __urls__ = ("/", ) + __urls__ = ("/",) __methods = ("get", "post", "put", "delete", "options") def get(self): @@ -97,7 +98,7 @@ class HTTPServer(Server): def __init__(self, host="localhost", port=38001, **kwargs): super(HTTPServer, self).__init__(host=host, port=port, **kwargs) self.component_data = kwargs.get("component_data", {}) - logger.info("HTTPServer port={} {}".format(port, kwargs)) + LOGGER.info("HTTPServer port={} {}".format(port, kwargs)) self.app = Flask(__name__) self._port = port self._host = host @@ -106,6 +107,7 @@ class HTTPServer(Server): self.container_chaining = kwargs.get("container_chaining") self.api = Api(self.app) self.__set_route() + # self.__hook_errors() @self.app.errorhandler(exceptions.AuthException) @@ -116,10 +118,12 @@ class HTTPServer(Server): # FIXME (dthom): it doesn't work def get_404_json(e): return {"error": "Error", "code": 404, "description": e} + self.app.register_error_handler(404, get_404_json) def get_400_json(e): return {"error": "Error", "code": 400, "description": e} + self.app.register_error_handler(400, lambda e: get_400_json) self.app.register_error_handler(403, exceptions.AuthException) -- cgit 1.2.3-korg