diff options
author | Thomas Duval <thomas.duval@orange.com> | 2018-03-14 11:25:06 +0100 |
---|---|---|
committer | Thomas Duval <thomas.duval@orange.com> | 2018-03-15 10:47:03 +0100 |
commit | d425d4edf13ed389cd34113bd9fd78eaa0a08c20 (patch) | |
tree | 1ecfdf8a7f97f71748cf31e0ef45518997672993 /moon_manager/moon_manager | |
parent | acb811aafc97d60cdcc71e0b9b2466fb00bfb097 (diff) |
Fix bugs due to the modification of python_moondb
Change-Id: Id3855a6e8da9f8ef942c7a34a3e8da4f87be4c9e
Diffstat (limited to 'moon_manager/moon_manager')
-rw-r--r-- | moon_manager/moon_manager/api/json_export.py | 9 | ||||
-rw-r--r-- | moon_manager/moon_manager/http_server.py | 35 |
2 files changed, 14 insertions, 30 deletions
diff --git a/moon_manager/moon_manager/api/json_export.py b/moon_manager/moon_manager/api/json_export.py index feb4fde2..9ddcfc8d 100644 --- a/moon_manager/moon_manager/api/json_export.py +++ b/moon_manager/moon_manager/api/json_export.py @@ -1,3 +1,8 @@ +# Copyright 2018 Open Platform for NFV Project, Inc. and its contributors +# This software is distributed under the terms and conditions of the 'Apache-2.0' +# 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_restful import Resource from python_moonutilities.security_functions import check_auth @@ -95,8 +100,8 @@ class JsonExport(Resource): JsonUtils.copy_field_if_exists(data_group["data"][data_key], data_dict, "name", str) JsonUtils.copy_field_if_exists(data_group["data"][data_key], data_dict, "description", str) else: - JsonUtils.copy_field_if_exists(data_group["data"][data_key]["value"], data_dict, "name", str) - JsonUtils.copy_field_if_exists(data_group["data"][data_key]["value"], data_dict, "description", str) + JsonUtils.copy_field_if_exists(data_group["data"][data_key], data_dict, "name", str) + JsonUtils.copy_field_if_exists(data_group["data"][data_key], data_dict, "description", str) JsonUtils.convert_id_to_name(policy_id, data_dict, "policy", "policy", PolicyManager, self._user_id) JsonUtils.convert_id_to_name(category_id, data_dict, "category", type_element + "_category", ModelManager, self._user_id, policy_key) diff --git a/moon_manager/moon_manager/http_server.py b/moon_manager/moon_manager/http_server.py index 28d77ea0..76d04599 100644 --- a/moon_manager/moon_manager/http_server.py +++ b/moon_manager/moon_manager/http_server.py @@ -2,12 +2,10 @@ # This software is distributed under the terms and conditions of the 'Apache-2.0' # license which can be found in the file 'LICENSE' in this package distribution # or at 'http://www.apache.org/licenses/LICENSE-2.0'. -from werkzeug.exceptions import HTTPException from flask import Flask, jsonify, Response, make_response from flask_cors import CORS, cross_origin from json import dumps from flask_restful import Resource, Api -import flask_restful import logging import sqlalchemy.exc import time @@ -24,7 +22,6 @@ from moon_manager.api.data import SubjectData, ObjectData, ActionData from moon_manager.api.assignments import SubjectAssignments, ObjectAssignments, ActionAssignments from moon_manager.api.rules import Rules from moon_manager.api.json_import import JsonImport -from moon_manager.api.base_exception import BaseException from moon_manager.api.json_export import JsonExport from python_moonutilities import configuration from python_moondb.core import PDPManager @@ -112,17 +109,19 @@ class Root(Resource): class CustomApi(Api): - def handle_error(self, e): + @staticmethod + def handle_error(e): try: - error_message = dumps({'message': str(e)}) + error_message = dumps({'message': str(e), "code": getattr(e, "code", 500)}) logger.error(error_message) - return make_response(error_message, e.code) - except Exception as e2: # unhandled exception in the api... + return make_response(error_message, getattr(e, "code", 500)) + except Exception as e2: # unhandled exception in the api... logger.error(str(e2)) return make_response(error_message, 500) class HTTPServer(Server): + def __init__(self, host="localhost", port=80, **kwargs): super(HTTPServer, self).__init__(host=host, port=port, **kwargs) self.app = Flask(__name__) @@ -135,26 +134,6 @@ class HTTPServer(Server): CORS(self.app) self.api = CustomApi(self.app) self.__set_route() - # self.__hook_errors() - - #def __hook_errors(self): - # def get_500_json(e): - # logger.error("get_500_json") - # return jsonify({"result": False, "code": 500, "description": str(e)}), 500 - # self.app.register_error_handler(JsonUtilsException, get_500_json) - # self.app.register_error_handler(JsonImportException, get_500_json) - # self.app.register_error_handler(UnknownName, get_500_json) - - # def get_404_json(e): - # return jsonify({"result": False, "code": 404, "description": str(e)}), 404 - # self.app.register_error_handler(404, get_404_json) - - # def get_400_json(e): - # return jsonify({"result": False, "code": 400, "description": str(e)}), 400 - - # self.app.register_error_handler(500, lambda e: get_500_json) - # self.app.register_error_handler(400, lambda e: get_400_json) - # self.app.register_error_handler(403, exceptions.AuthException) def __set_route(self): self.api.add_resource(Root, '/') @@ -179,4 +158,4 @@ class HTTPServer(Server): def run(self): self.__check_if_db_is_up() - self.app.run(debug=True, host=self._host, port=self._port) # nosec + self.app.run(host=self._host, port=self._port) # nosec |