chg: [api] add 404 errors code + add future endpoints in doc

pull/370/head
Terrtia 2019-08-01 09:45:59 +02:00
parent 918b4c28ed
commit 8c02c1b00b
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
4 changed files with 97 additions and 17 deletions

View File

@ -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')

View File

@ -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)

View File

@ -27,10 +27,10 @@ curl --header "Authorization: YOUR_API_KEY" --header "Content-Type: application/
## Item management
### Get item: `api/get/item/info/<path:item_id>`
### Get item: `api/get/item/basic/<path:item_id>`
#### 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/ <domain><port>`` GET
### Get domain tags
##### ``api/get/crawler/domain/tag/ <domain><port>`` GET
### Get domain history
##### ``api/get/crawler/domain/history/ <domain><port>`` GET
### Get domain list of items
##### ``api/get/crawler/domain/item/ <domain><port>`` 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/<sha1>`` GET
### Get decoded item metadata
### Check if a decoded item exists (via sha1)
##### ``api/get/decoded/metadata/<sha1>`` GET
### Get decoded item correlation (1 depth)
##### ``api/get/decoded/metadata/<sha1>`` GET
-----
-----
##### ``api/get/cryptocurrency`` POST
### Check if a cryptocurrency address (bitcoin, ..) exists
##### ``api/get/cryptocurrency/exist/<bitcoin_address>`` GET
### Get cryptocurrency address metadata
##### ``api/get/cryptocurrency/metadata/<bitcoin_address>`` 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

View File

@ -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/<path:item_id>", methods=['GET'])
@restApi.route("api/get/item/basic/<path:item_id>", 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)