From 8c02c1b00b0730d660d4c110d4dfe57ecc799521 Mon Sep 17 00:00:00 2001 From: Terrtia Date: Thu, 1 Aug 2019 09:45:59 +0200 Subject: [PATCH] chg: [api] add 404 errors code + add future endpoints in doc --- bin/packages/Import_helper.py | 2 +- bin/packages/Tag.py | 4 +- doc/README.md | 91 +++++++++++++++++++++++- var/www/modules/restApi/Flask_restApi.py | 17 ++--- 4 files changed, 97 insertions(+), 17 deletions(-) diff --git a/bin/packages/Import_helper.py b/bin/packages/Import_helper.py index 0b7fdfb8..c95c101b 100755 --- a/bin/packages/Import_helper.py +++ b/bin/packages/Import_helper.py @@ -49,7 +49,7 @@ def check_import_status(UUID): processing = r_serv_log_submit.get(UUID + ':processing') if not processing: - return ({'status': 'error', 'reason': 'Unknown uuid'}, 400) + return ({'status': 'error', 'reason': 'Unknown uuid'}, 404) # nb_total = r_serv_log_submit.get(UUID + ':nb_total') # nb_sucess = r_serv_log_submit.get(UUID + ':nb_sucess') diff --git a/bin/packages/Tag.py b/bin/packages/Tag.py index 5d717bb7..3665451f 100755 --- a/bin/packages/Tag.py +++ b/bin/packages/Tag.py @@ -76,7 +76,7 @@ def get_item_tags(item_id): def add_items_tag(tags=[], galaxy_tags=[], item_id=None): res_dict = {} if item_id == None: - return ({'status': 'error', 'reason': 'Item id not found'}, 400) + return ({'status': 'error', 'reason': 'Item id not found'}, 404) if not tags and not galaxy_tags: return ({'status': 'error', 'reason': 'Tags or Galaxy not specified'}, 400) @@ -136,7 +136,7 @@ def add_item_tag(tag, item_path): # API QUERY def remove_item_tags(tags=[], item_id=None): if item_id == None: - return ({'status': 'error', 'reason': 'Item id not found'}, 400) + return ({'status': 'error', 'reason': 'Item id not found'}, 404) if not tags: return ({'status': 'error', 'reason': 'No Tag(s) specified'}, 400) diff --git a/doc/README.md b/doc/README.md index 8979780a..0a819ac6 100644 --- a/doc/README.md +++ b/doc/README.md @@ -27,10 +27,10 @@ curl --header "Authorization: YOUR_API_KEY" --header "Content-Type: application/ ## Item management -### Get item: `api/get/item/info/` +### Get item: `api/get/item/basic/` #### Description -Get a specific item information. +Get anitem basic information. **Method** : `GET` @@ -462,3 +462,90 @@ curl -k https://127.0.0.1:7000/api/import/item/b20a69f1-99ad-4cb3-b212-7ce24b763 {"status": "error", "reason": "Invalid uuid"} {"status": "error", "reason": "Unknown uuid"} ``` + + + + + + + + +# FUTURE endpoints + +### Text search by daterange +##### ``api/search/textIndexer/item`` POST + +### Get all tags list +##### ``api/get/tag/all`` + +### Get tagged items by daterange +##### ``api/search/tag/item`` POST + +### Submit a domain to crawl +##### ``api/add/crawler/domain`` POST + +### Create a term/set/regex tracker +##### ``api/add/termTracker/`` POST + +### Get tracker items list +##### ``api/get/termTracker/item`` POST + +----- + +### Check if a tor/regular domain have been crawled +##### ``api/get/crawler/domain/`` POST + +### Check if a tor/regular domain have been crawled +##### ``api/get/crawler/domain/metadata/ `` GET + +### Get domain tags +##### ``api/get/crawler/domain/tag/ `` GET + +### Get domain history +##### ``api/get/crawler/domain/history/ `` GET + +### Get domain list of items +##### ``api/get/crawler/domain/item/ `` GET + +----- + +### Create auto-crawlers +##### ``api/add/crawler/autoCrawler/`` POST + +----- + +### get item by mime type/ decoded type +##### ``api/get/decoded`` POST + +### Check if a decoded item exists (via sha1) +##### ``api/get/decoded/exist/`` GET + +### Get decoded item metadata +### Check if a decoded item exists (via sha1) +##### ``api/get/decoded/metadata/`` GET + +### Get decoded item correlation (1 depth) +##### ``api/get/decoded/metadata/`` GET + +----- + + +----- +##### ``api/get/cryptocurrency`` POST + +### Check if a cryptocurrency address (bitcoin, ..) exists +##### ``api/get/cryptocurrency/exist/`` GET + +### Get cryptocurrency address metadata +##### ``api/get/cryptocurrency/metadata/`` GET + +----- + +### Item correlation (1 depth) +##### ``api/get/item/correlation/`` POST + +### Create MISP event from item +##### ``api/export/item/misp`` POST + +### Create TheHive case from item +##### ``api/export/item/thehive`` POST diff --git a/var/www/modules/restApi/Flask_restApi.py b/var/www/modules/restApi/Flask_restApi.py index 673b83c6..0bb842aa 100644 --- a/var/www/modules/restApi/Flask_restApi.py +++ b/var/www/modules/restApi/Flask_restApi.py @@ -139,14 +139,7 @@ def one(): # def api(): # return 'api doc' -@restApi.route("api/items", methods=['GET', 'POST']) -@token_required('admin') -def items(): - item = request.args.get('id') - - return Response(json.dumps({'test': 2}), mimetype='application/json') - -@restApi.route("api/get/item/info/", methods=['GET']) +@restApi.route("api/get/item/basic/", methods=['GET']) @token_required('admin') def get_item_id(item_id): """ @@ -192,7 +185,7 @@ def get_item_id(item_id): try: item_object = Paste.Paste(item_id) except FileNotFoundError: - return Response(json.dumps({'status': 'error', 'reason': 'Item not found'}, indent=2, sort_keys=True), mimetype='application/json'), 400 + return Response(json.dumps({'status': 'error', 'reason': 'Item not found'}, indent=2, sort_keys=True), mimetype='application/json'), 404 data = item_object.get_item_dict() return Response(json.dumps(data, indent=2, sort_keys=True), mimetype='application/json') @@ -252,7 +245,7 @@ def get_item_tag(item_id): """ if not Item.exist_item(item_id): - return Response(json.dumps({'status': 'error', 'reason': 'Item not found'}, indent=2, sort_keys=True), mimetype='application/json'), 400 + return Response(json.dumps({'status': 'error', 'reason': 'Item not found'}, indent=2, sort_keys=True), mimetype='application/json'), 404 tags = Tag.get_item_tags(item_id) dict_tags = {} dict_tags['id'] = item_id @@ -471,7 +464,7 @@ def get_item_content(item_id): try: item_object = Paste.Paste(item_id) except FileNotFoundError: - return Response(json.dumps({'status': 'error', 'reason': 'Item not found'}, indent=2, sort_keys=True), mimetype='application/json'), 400 + return Response(json.dumps({'status': 'error', 'reason': 'Item not found'}, indent=2, sort_keys=True), mimetype='application/json'), 404 item_object = Paste.Paste(item_id) dict_content = {} dict_content['id'] = item_id @@ -572,7 +565,7 @@ def import_item(): tags.append('infoleak:submission="manual"') if sys.getsizeof(text_to_import) > 900000: - return Response(json.dumps({'status': 'error', 'reason': 'Size exceeds default'}, indent=2, sort_keys=True), mimetype='application/json'), 400 + return Response(json.dumps({'status': 'error', 'reason': 'Size exceeds default'}, indent=2, sort_keys=True), mimetype='application/json'), 413 UUID = str(uuid.uuid4()) Import_helper.create_import_queue(tags, galaxy, text_to_import, UUID)