chg: [api] 405 response: add url to api endpoint documentation

pull/370/head
Terrtia 2019-08-06 11:29:12 +02:00
parent 4ce548ab84
commit 0a071a5165
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
3 changed files with 16 additions and 17 deletions

View File

@ -18,7 +18,6 @@ When submitting data in a POST, PUT or DELETE operation you need to specify in w
~~~~ ~~~~
Content-Type: application/json Content-Type: application/json
~~~~ ~~~~
Take me to [delete_item_tag](#delete_item_tag)
Example: Example:

View File

@ -294,7 +294,12 @@ def searchbox():
@app.errorhandler(405) @app.errorhandler(405)
def _handle_client_error(e): def _handle_client_error(e):
if request.path.startswith('/api/'): 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: else:
return e return e

View File

@ -35,6 +35,7 @@ r_serv_db = Flask_config.r_serv_db
r_serv_onion = Flask_config.r_serv_onion r_serv_onion = Flask_config.r_serv_onion
r_serv_metadata = Flask_config.r_serv_metadata r_serv_metadata = Flask_config.r_serv_metadata
restApi = Blueprint('restApi', __name__, template_folder='templates') restApi = Blueprint('restApi', __name__, template_folder='templates')
# ============ AUTH FUNCTIONS ============ # ============ AUTH FUNCTIONS ============
@ -128,8 +129,6 @@ def authErrors(user_role):
# ============ API CORE ============= # ============ API CORE =============
# ============ FUNCTIONS ============ # ============ FUNCTIONS ============
def is_valid_uuid_v4(header_uuid): def is_valid_uuid_v4(header_uuid):
@ -167,21 +166,17 @@ def one():
# } # }
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
@restApi.route("api/v1/get/item", methods=['GET', 'POST']) @restApi.route("api/v1/get/item", methods=['POST'])
@token_required('analyst') @token_required('analyst')
def get_item_id(): def get_item_id():
if request.method == 'POST':
data = request.get_json() data = request.get_json()
res = Item.get_item(data) res = Item.get_item(data)
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1] return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
else:
return 'description API endpoint'
@restApi.route("api/v1/get/item/default", methods=['POST']) @restApi.route("api/v1/get/item/default", methods=['POST'])
@token_required('analyst') @token_required('analyst')
def get_item_id_basic(): def get_item_id_basic():
if request.method == 'POST':
data = request.get_json() data = request.get_json()
item_id = data.get('id', None) item_id = data.get('id', None)
req_data = {'id': item_id, 'date': True, 'content': True, 'tags': True} req_data = {'id': item_id, 'date': True, 'content': True, 'tags': True}