New CLI API: project API improvements.
* On project deletion:
- validate project id before executing anything with it;
- check if project with provided id exists.
@@ -5,6 +5,7 @@ from flask import g, abort, request
from flask_restplus import Resource, fields
from pyinfraboxutils import get_logger
+from pyinfrabox.utils import validate_uuid4
from pyinfraboxutils.ibrestplus import api
from pyinfraboxutils.ibflask import auth_required, OK
@@ -229,14 +230,15 @@ class Project(Resource):
@auth_required(['user'], check_project_owner=True)
def delete(self, project_id):
+ if not validate_uuid4(project_id):
+ abort(400, "Invalid project uuid.")
- project = g.db.execute_one_dict('''
+ project = g.db.execute_one_dict("""
DELETE FROM project WHERE id = %s RETURNING type
- ''', [project_id])
+ """, [project_id])
if not project:
- abort(404)
-
+ abort(400, 'Project with such an id does not exist.')
if project['type'] == 'github':
repo = g.db.execute_one_dict('''
