2021-05-10 16:08:58 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from flask import Blueprint, jsonify, Response, request
|
|
|
|
from app.decorators import require_header_token, require_get_token
|
2021-06-08 18:22:52 +02:00
|
|
|
from app.classes.misp import MISP
|
2021-05-10 16:08:58 +02:00
|
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
misp_bp = Blueprint("misp", __name__)
|
2021-06-08 18:22:52 +02:00
|
|
|
misp = MISP()
|
2021-05-10 16:08:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
@misp_bp.route('/add', methods=['POST'])
|
|
|
|
@require_header_token
|
2021-06-08 20:11:51 +02:00
|
|
|
def add_instance():
|
2021-05-10 16:08:58 +02:00
|
|
|
"""
|
|
|
|
Parse and add a MISP instance to the database.
|
|
|
|
:return: status of the operation in JSON
|
|
|
|
"""
|
|
|
|
data = json.loads(request.data)
|
2021-06-10 18:37:40 +02:00
|
|
|
res = misp.add_instance(data["data"]["instance"])
|
2021-05-10 16:08:58 +02:00
|
|
|
return jsonify(res)
|
|
|
|
|
|
|
|
@misp_bp.route('/delete/<misp_id>', methods=['GET'])
|
|
|
|
@require_header_token
|
2021-06-08 20:11:51 +02:00
|
|
|
def delete_instance(misp_id):
|
2021-05-10 16:08:58 +02:00
|
|
|
"""
|
|
|
|
Delete a MISP instance by its id to the database.
|
|
|
|
:return: status of the operation in JSON
|
|
|
|
"""
|
2021-06-09 18:24:37 +02:00
|
|
|
res = misp.delete_instance(misp_id)
|
2021-05-10 16:08:58 +02:00
|
|
|
return jsonify(res)
|
|
|
|
|
2021-06-08 18:22:52 +02:00
|
|
|
|
2021-05-10 16:08:58 +02:00
|
|
|
@misp_bp.route('/get_all', methods=['GET'])
|
2021-06-09 18:24:37 +02:00
|
|
|
@require_header_token
|
2021-05-10 16:08:58 +02:00
|
|
|
def get_all():
|
|
|
|
"""
|
|
|
|
Retreive a list of all MISP instances.
|
|
|
|
:return: list of MISP instances in JSON.
|
|
|
|
"""
|
2021-06-09 18:24:37 +02:00
|
|
|
res = misp.get_instances()
|
2021-05-10 16:08:58 +02:00
|
|
|
return jsonify({"results": [i for i in res]})
|