aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--moon_wrapper/moon_wrapper/api/oslowrapper.py16
-rw-r--r--moon_wrapper/moon_wrapper/http_server.py9
-rw-r--r--moon_wrapper/tests/unit_python/api/test_wrapper.py3
3 files changed, 18 insertions, 10 deletions
diff --git a/moon_wrapper/moon_wrapper/api/oslowrapper.py b/moon_wrapper/moon_wrapper/api/oslowrapper.py
index ad9e430a..905c32db 100644
--- a/moon_wrapper/moon_wrapper/api/oslowrapper.py
+++ b/moon_wrapper/moon_wrapper/api/oslowrapper.py
@@ -37,8 +37,14 @@ class OsloWrapper(Resource):
def post(self):
logger.debug("POST {}".format(request.form))
response = flask.make_response("False")
- if self.manage_data():
- response = flask.make_response("True")
+ try:
+ if self.manage_data():
+ response = flask.make_response("True")
+ except exceptions.AuthzException as e:
+ logger.error(e, exc_info=True)
+ except Exception as e:
+ logger.error(e, exc_info=True)
+
response.headers['content-type'] = 'application/octet-stream'
return response
@@ -109,10 +115,10 @@ class OsloWrapper(Resource):
_object,
_action
))
- '''
- [Note] i think here if status != 200, should raise an exception
- '''
+
logger.debug("Get interface {}".format(req.text))
if req.status_code == 200:
if req.json().get("result", False):
return True
+
+ raise exceptions.AuthzException("error in authz request") \ No newline at end of file
diff --git a/moon_wrapper/moon_wrapper/http_server.py b/moon_wrapper/moon_wrapper/http_server.py
index 8027a0d3..f23af182 100644
--- a/moon_wrapper/moon_wrapper/http_server.py
+++ b/moon_wrapper/moon_wrapper/http_server.py
@@ -3,6 +3,7 @@
# license which can be found in the file 'LICENSE' in this package distribution
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
+import flask
from flask import Flask, jsonify
from flask_restful import Resource, Api
import logging
@@ -112,13 +113,13 @@ class HTTPServer(Server):
def __hook_errors(self):
def get_404_json(e):
- return jsonify({"result": False, "code": 404,
- "description": str(e)}), 404
+ return flask.make_response("False")
+
self.app.register_error_handler(404, get_404_json)
def get_400_json(e):
- return jsonify({"result": False, "code": 400,
- "description": str(e)}), 400
+ return flask.make_response("False")
+
self.app.register_error_handler(400, lambda e: get_400_json)
self.app.register_error_handler(403, exceptions.AuthException)
diff --git a/moon_wrapper/tests/unit_python/api/test_wrapper.py b/moon_wrapper/tests/unit_python/api/test_wrapper.py
index be3e8576..bd6baf32 100644
--- a/moon_wrapper/tests/unit_python/api/test_wrapper.py
+++ b/moon_wrapper/tests/unit_python/api/test_wrapper.py
@@ -68,4 +68,5 @@ def test_authz_error_no_interface_key(context):
'target': json.dumps(_target),
'credentials': 'null'}
req = client.post("/authz/oslo", data=json.dumps(authz_data))
- assert req.status_code == 403 \ No newline at end of file
+
+ assert req.data == b"False" \ No newline at end of file