diff --git a/doc/README.md b/doc/README.md index 3bce7ee8..76b016e7 100644 --- a/doc/README.md +++ b/doc/README.md @@ -18,7 +18,6 @@ When submitting data in a POST, PUT or DELETE operation you need to specify in w ~~~~ Content-Type: application/json ~~~~ -Take me to [delete_item_tag](#delete_item_tag) Example: diff --git a/var/www/Flask_server.py b/var/www/Flask_server.py index 6361e94c..3d1b524e 100755 --- a/var/www/Flask_server.py +++ b/var/www/Flask_server.py @@ -294,7 +294,12 @@ def searchbox(): @app.errorhandler(405) def _handle_client_error(e): if request.path.startswith('/api/'): - return Response(json.dumps({"status": "error", "reason": "Method Not Allowed: The method is not allowed for the requested URL"}, indent=2, sort_keys=True), mimetype='application/json'), 405 + res_dict = {"status": "error", "reason": "Method Not Allowed: The method is not allowed for the requested URL"} + anchor_id = request.path[8:] + anchor_id = anchor_id.replace('/', '_') + api_doc_url = 'https://github.com/CIRCL/AIL-framework/tree/master/doc#{}'.format(anchor_id) + res_dict['documentation'] = api_doc_url + return Response(json.dumps(res_dict, indent=2, sort_keys=True), mimetype='application/json'), 405 else: return e diff --git a/var/www/modules/restApi/Flask_restApi.py b/var/www/modules/restApi/Flask_restApi.py index 93de87ee..6ea8dd69 100644 --- a/var/www/modules/restApi/Flask_restApi.py +++ b/var/www/modules/restApi/Flask_restApi.py @@ -35,6 +35,7 @@ r_serv_db = Flask_config.r_serv_db r_serv_onion = Flask_config.r_serv_onion r_serv_metadata = Flask_config.r_serv_metadata + restApi = Blueprint('restApi', __name__, template_folder='templates') # ============ AUTH FUNCTIONS ============ @@ -128,8 +129,6 @@ def authErrors(user_role): # ============ API CORE ============= - - # ============ FUNCTIONS ============ def is_valid_uuid_v4(header_uuid): @@ -167,26 +166,22 @@ def one(): # } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -@restApi.route("api/v1/get/item", methods=['GET', 'POST']) +@restApi.route("api/v1/get/item", methods=['POST']) @token_required('analyst') def get_item_id(): - if request.method == 'POST': - data = request.get_json() - res = Item.get_item(data) - return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1] - else: - return 'description API endpoint' + data = request.get_json() + res = Item.get_item(data) + return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1] @restApi.route("api/v1/get/item/default", methods=['POST']) @token_required('analyst') def get_item_id_basic(): - if request.method == 'POST': - data = request.get_json() - item_id = data.get('id', None) - req_data = {'id': item_id, 'date': True, 'content': True, 'tags': True} - res = Item.get_item(req_data) - return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1] + data = request.get_json() + item_id = data.get('id', None) + req_data = {'id': item_id, 'date': True, 'content': True, 'tags': True} + res = Item.get_item(req_data) + return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1] # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # GET