Geen omschrijving

manage_case_objs.py 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # IRIS Source Code
  2. # Copyright (C) 2021 - Airbus CyberSecurity (SAS)
  3. # ir@cyberactionlab.net
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Lesser General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 3 of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # Lesser General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Lesser General Public License
  16. # along with this program; if not, write to the Free Software Foundation,
  17. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. from sqlalchemy import func
  19. from app.models.models import AnalysisStatus
  20. from app.models.models import IocType
  21. from app.models.models import AssetsType
  22. from app.models.models import EventCategory
  23. def search_analysis_status_by_name(name: str, exact_match: bool = False) -> AnalysisStatus:
  24. """
  25. Search an analysis status by its name
  26. args:
  27. name: the name of the analysis status
  28. exact_match: if True, the name must be exactly the same as the one in the database
  29. return: the analysis status
  30. """
  31. if exact_match:
  32. return AnalysisStatus.query.filter(func.lower(AnalysisStatus.name) == name.lower()).all()
  33. return AnalysisStatus.query.filter(AnalysisStatus.name.ilike(f'%{name}%')).all()
  34. def search_ioc_type_by_name(name: str, exact_match: bool = False) -> IocType:
  35. """
  36. Search an IOC type by its name
  37. args:
  38. name: the name of the IOC type
  39. exact_match: if True, the name must be exactly the same as the one in the database
  40. return: the IOC type
  41. """
  42. if exact_match:
  43. return IocType.query.filter(func.lower(IocType.type_name) == name.lower()).all()
  44. return IocType.query.filter(IocType.type_name.ilike(f'%{name}%')).all()
  45. def search_asset_type_by_name(name: str, exact_match: bool = False) -> AssetsType:
  46. """
  47. Search an asset type by its name
  48. args:
  49. name: the name of the asset type
  50. exact_match: if True, the name must be exactly the same as the one in the database
  51. return: the asset type
  52. """
  53. if exact_match:
  54. return AssetsType.query.filter(func.lower(AssetsType.asset_name) == name.lower()).all()
  55. return AssetsType.query.filter(AssetsType.asset_name.ilike(f'%{name}%')).all()
  56. def search_event_category_by_name(name: str, exact_match: bool = False) -> AssetsType:
  57. """
  58. Search an event category by its name
  59. args:
  60. name: the name of the event category
  61. exact_match: if True, the name must be exactly the same as the one in the database
  62. return: the event category
  63. """
  64. if exact_match:
  65. return EventCategory.query.filter(func.lower(EventCategory.name) == name.lower()).all()
  66. return EventCategory.query.filter(EventCategory.name.ilike(f'%{name}%')).all()