Açıklama Yok

manage_severities_routes.py 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # IRIS Source Code
  2. # contact@dfir-iris.org
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Lesser General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 3 of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # Lesser General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Lesser General Public License
  15. # along with this program; if not, write to the Free Software Foundation,
  16. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. from flask import Blueprint
  18. from flask import Response
  19. from flask import request
  20. from app.datamgmt.manage.manage_common import get_severity_by_id
  21. from app.datamgmt.manage.manage_common import get_severities_list
  22. from app.datamgmt.manage.manage_common import search_severity_by_name
  23. from app.schema.marshables import SeveritySchema
  24. from app.blueprints.access_controls import ac_api_requires
  25. from app.blueprints.responses import response_error
  26. from app.blueprints.responses import response_success
  27. manage_severities_rest_blueprint = Blueprint('manage_severities_rest', __name__)
  28. @manage_severities_rest_blueprint.route('/manage/severities/list', methods=['GET'])
  29. @ac_api_requires()
  30. def list_severities() -> Response:
  31. """
  32. Get the list of severities
  33. Returns:
  34. Flask Response object
  35. """
  36. l_cl = get_severities_list()
  37. schema = SeveritySchema()
  38. return response_success("", data=schema.dump(l_cl, many=True))
  39. @manage_severities_rest_blueprint.route('/manage/severities/<int:severity_id>', methods=['GET'])
  40. @ac_api_requires()
  41. def get_case_alert_status(severity_id: int) -> Response:
  42. """
  43. Get the alert status
  44. Args:
  45. severity_id (int): severity id
  46. """
  47. cl = get_severity_by_id(severity_id)
  48. schema = SeveritySchema()
  49. return response_success("", data=schema.dump(cl))
  50. @manage_severities_rest_blueprint.route('/manage/severities/search', methods=['POST'])
  51. @ac_api_requires()
  52. def search_analysis_status():
  53. if not request.is_json:
  54. return response_error("Invalid request")
  55. severity_name = request.json.get('severity_name')
  56. if severity_name is None:
  57. return response_error("Invalid severity. Got None")
  58. exact_match = request.json.get('exact_match', False)
  59. # Search for severity with a name that contains the specified search term
  60. severity = search_severity_by_name(severity_name, exact_match=exact_match)
  61. if not severity:
  62. return response_error("No severity found")
  63. # Serialize the severity and return them in a JSON response
  64. schema = SeveritySchema(many=True)
  65. return response_success("", data=schema.dump(severity))