chg: [api] rename endpoints

This commit is contained in:
Terrtia 2021-11-26 17:54:15 +01:00
parent 65eb084e41
commit 054df7c495
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
2 changed files with 31 additions and 28 deletions

View file

@ -222,7 +222,7 @@ def get_item(request_dict):
def get_item_content_encoded_text(request_dict): def api_get_item_content_base64_utf8(request_dict):
item_id = request_dict.get('id', None) item_id = request_dict.get('id', None)
if not request_dict: if not request_dict:
return {'status': 'error', 'reason': 'Malformed JSON'}, 400 return {'status': 'error', 'reason': 'Malformed JSON'}, 400
@ -236,22 +236,23 @@ def get_item_content_encoded_text(request_dict):
return {'status': 'success', 'content': item_content}, 200 return {'status': 'success', 'content': item_content}, 200
def get_item_sources(): def api_get_items_sources():
item_content = {'sources': get_all_sources()} item_content = {'sources': get_all_sources()}
return item_content, 200 return item_content, 200
def check_item_source(request_dict): # def check_item_source(request_dict):
source = request_dict.get('source', None) # source = request_dict.get('source', None)
if not request_dict: # if not request_dict:
return {'status': 'error', 'reason': 'Malformed JSON'}, 400 # return {'status': 'error', 'reason': 'Malformed JSON'}, 400
if not source: # if not source:
return {'status': 'error', 'reason': 'Mandatory parameter(s) not provided'}, 400 # return {'status': 'error', 'reason': 'Mandatory parameter(s) not provided'}, 400
#
# all_sources = item_basic.get_all_items_sources()
#
# if source not in all_sources:
# return {'status': 'error', 'reason': 'Invalid source', 'provide': source}, 400
# return {'status': 'success', 'reason': 'Valid source', 'provide': source}, 200
all_sources = item_basic.get_all_items_sources()
if source not in all_sources:
return {'status': 'error', 'reason': 'Invalid source', 'provide': source}, 400
return {'status': 'success', 'reason': 'Valid source', 'provide': source}, 200
### ###
### correlation ### correlation
### ###

View file

@ -29,7 +29,7 @@ sys.path.append(os.path.join(os.environ['AIL_BIN'], 'import'))
import importer import importer
from flask import Flask, render_template, jsonify, request, Blueprint, redirect, url_for, Response from flask import Flask, render_template, jsonify, request, Blueprint, redirect, url_for, Response, escape
from flask_login import login_required from flask_login import login_required
from functools import wraps from functools import wraps
@ -313,32 +313,33 @@ def get_item_content():
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]
@restApi.route("api/v1/get/item/content/encoded/text", methods=['POST']) @restApi.route("api/v1/get/item/content/utf8/base64", methods=['POST'])
@token_required('read_only') @token_required('read_only')
def get_item_content_encoded_text(): def get_item_content_encoded_text():
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} req_data = {'id': item_id}
res = Item.get_item_content_encoded_text(req_data) res = Item.api_get_item_content_base64_utf8(req_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]
@restApi.route("api/v1/get/item/sources", methods=['GET']) @restApi.route("api/v1/get/items/sources", methods=['GET'])
@token_required('read_only') @token_required('read_only')
def get_item_sources(): def get_item_sources():
res = Item.get_item_sources() res = Item.api_get_items_sources()
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]
@restApi.route("api/v1/get/item/source/check", methods=['POST']) # @restApi.route("api/v1/get/item/source/check", methods=['POST'])
@token_required('read_only') # @token_required('read_only')
def get_check_item_source(): # def get_check_item_source():
data = request.get_json() # data = request.get_json()
source = data.get('source', None) # source = data.get('source', None)
req_data = {'source': source} # req_data = {'source': source}
res = Item.check_item_source(req_data) # res = Item.check_item_source(req_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]
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # TAGS # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # TAGS # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
@ -395,11 +396,11 @@ def get_tracker_term_item():
def get_default_yara_rule_content(): def get_default_yara_rule_content():
data = request.get_json() data = request.get_json()
rule_name = data.get('rule_name', None) rule_name = data.get('rule_name', None)
rule_name = escape(rule_name)
req_data = {'rule_name': rule_name} req_data = {'rule_name': rule_name}
res = Tracker.get_yara_rule_content_restapi(req_data) res = Tracker.get_yara_rule_content_restapi(req_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]
@restApi.route("api/v1/get/tracker/metadata", methods=['POST']) @restApi.route("api/v1/get/tracker/metadata", methods=['POST'])
@token_required('read_only') @token_required('read_only')
def get_tracker_metadata_api(): def get_tracker_metadata_api():
@ -408,6 +409,7 @@ def get_tracker_metadata_api():
req_data = {'tracker_uuid': tracker_uuid} req_data = {'tracker_uuid': tracker_uuid}
res = Tracker.get_tracker_metadata_api(req_data) res = Tracker.get_tracker_metadata_api(req_data)
return Response(json.dumps(res[0], indent=2, sort_keys=False), mimetype='application/json'), res[1] return Response(json.dumps(res[0], indent=2, sort_keys=False), mimetype='application/json'), res[1]
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # CRYPTOCURRENCY # # # # # # # # # # # # # # # # # # # # # # # # # # CRYPTOCURRENCY # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #