Commit 39437a3c authored by Daniele Venzano's avatar Daniele Venzano

Fix validation endpoint

parent eedbd381
......@@ -50,15 +50,7 @@ Usage::
curl -X POST --data-urlencode @filename http://bf5:8080/api/<api_version>/zapp_validate
Needs a JSON document passed as the request body::
{
"application": <zapp json>,
}
Where:
* ``application`` is the full ZApp JSON document, the application description
The full ZApp JSON document, the application description document, is expected as the body of the request.
Will return a 200 HTTP status in case the JSON document passes validation, 400 otherwise.
......
......@@ -68,7 +68,7 @@ class APIEndpoint:
try:
zoe_lib.applications.app_validate(application_description)
except zoe_lib.exceptions.InvalidApplicationDescription as e:
raise zoe_api.exceptions.ZoeRestAPIException('Invalid application description: ' + e.message)
raise zoe_api.exceptions.ZoeRestAPIException('Invalid application description: {}'.format(e.message), status_code=400)
def _check_quota(self, user: zoe_lib.state.User, application_description): # pylint: disable=unused-argument
"""Check quota for given user and execution."""
......
......@@ -27,17 +27,16 @@ class ZAppValidateAPI(ZoeAPIRequestHandler):
def post(self):
"""HTTP GET method."""
try:
data = tornado.escape.json_decode(self.request.body)
application_description = tornado.escape.json_decode(self.request.body)
except ValueError:
self.set_status(400, 'Error decoding JSON data')
return
application_description = data['application']
try:
self.api_endpoint.zapp_validate(application_description)
except ZoeException as e:
self.set_status(e.status_code, e.message)
self.set_status(e.status_code, "Invalid application description")
self.write(e.message)
return
self.write({'validation': 'ok'})
......@@ -34,10 +34,7 @@ class ZoeValidationAPI(ZoeAPIBase):
:return:
"""
zapp = {
"application": application_description,
}
data_, status_code = self._rest_post('/zapp_validate', zapp)
data_, status_code = self._rest_post('/zapp_validate', application_description)
if status_code != 200:
return False
else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment