2018-01-25 17:56:30 +01:00
|
|
|
#!/usr/bin/env python
|
2024-01-17 13:13:14 +01:00
|
|
|
|
|
|
|
from __future__ import annotations
|
2018-01-25 17:56:30 +01:00
|
|
|
|
2024-02-01 14:40:12 +01:00
|
|
|
from ..api import PyMISP
|
|
|
|
|
2018-01-25 17:56:30 +01:00
|
|
|
try:
|
2024-02-01 14:40:12 +01:00
|
|
|
from pymispwarninglists import WarningLists, WarningList # type: ignore
|
2018-01-25 17:56:30 +01:00
|
|
|
has_pymispwarninglists = True
|
|
|
|
except ImportError:
|
|
|
|
has_pymispwarninglists = False
|
|
|
|
|
|
|
|
|
2024-02-01 14:40:12 +01:00
|
|
|
def from_instance(pymisp_instance: PyMISP, slow_search: bool=False) -> WarningLists:
|
2018-01-25 17:56:30 +01:00
|
|
|
"""Load the warnindlist from an existing MISP instance
|
|
|
|
:pymisp_instance: Already instantialized PyMISP instance."""
|
|
|
|
|
2024-02-01 14:40:12 +01:00
|
|
|
warninglists_index = pymisp_instance.warninglists(pythonify=True)
|
2018-01-25 17:56:30 +01:00
|
|
|
all_warningslists = []
|
|
|
|
for warninglist in warninglists_index:
|
2024-02-01 14:40:12 +01:00
|
|
|
if isinstance(warninglist, WarningList):
|
|
|
|
wl = pymisp_instance.get_warninglist(warninglist['Warninglist']['id'])['Warninglist']
|
|
|
|
wl['list'] = wl.pop('WarninglistEntry')
|
|
|
|
all_warningslists.append(wl)
|
2018-01-25 17:56:30 +01:00
|
|
|
|
|
|
|
return WarningLists(slow_search, all_warningslists)
|
|
|
|
|
|
|
|
|
2024-02-01 14:40:12 +01:00
|
|
|
def from_package(slow_search: bool=False) -> WarningLists:
|
2018-01-25 17:56:30 +01:00
|
|
|
return WarningLists(slow_search)
|