Merge pull request #2287 from guardicore/2180-i-event-repository
Island: Add IEventRepository
This commit is contained in:
commit
2fe3a2ece3
|
@ -10,6 +10,7 @@ from .i_user_repository import IUserRepository
|
||||||
from .i_machine_repository import IMachineRepository
|
from .i_machine_repository import IMachineRepository
|
||||||
from .i_agent_repository import IAgentRepository
|
from .i_agent_repository import IAgentRepository
|
||||||
from .i_node_repository import INodeRepository
|
from .i_node_repository import INodeRepository
|
||||||
|
from .i_event_repository import IEventRepository
|
||||||
|
|
||||||
|
|
||||||
from .local_storage_file_repository import LocalStorageFileRepository
|
from .local_storage_file_repository import LocalStorageFileRepository
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
from typing import Sequence, Type, TypeVar
|
||||||
|
|
||||||
|
from common.events import AbstractAgentEvent
|
||||||
|
from common.types import AgentID
|
||||||
|
|
||||||
|
T = TypeVar("T", bound=AbstractAgentEvent)
|
||||||
|
|
||||||
|
|
||||||
|
class IEventRepository(ABC):
|
||||||
|
"""A repository used to store and retrieve event objects"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def save_event(self, event: AbstractAgentEvent):
|
||||||
|
"""
|
||||||
|
Save an event to the repository
|
||||||
|
|
||||||
|
:param event: The event to store in the repository
|
||||||
|
:raises StorageError: If an error occured while attempting to save an event
|
||||||
|
"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get_events(self) -> Sequence[AbstractAgentEvent]:
|
||||||
|
"""
|
||||||
|
Retrieve all events stored in the repository
|
||||||
|
|
||||||
|
:return: All stored events
|
||||||
|
:raises RetrievalError: If an error occured while attempting to retrieve the events
|
||||||
|
"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get_events_by_type(self, event_type: Type[T]) -> Sequence[T]:
|
||||||
|
"""
|
||||||
|
Retrieve all events with same type
|
||||||
|
|
||||||
|
:param event_type: Type of event
|
||||||
|
:return: Stored events that have same type
|
||||||
|
:raises RetrievalError: If an error occured while attempting to retrieve the event
|
||||||
|
"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get_events_by_tag(self, tag: str) -> Sequence[AbstractAgentEvent]:
|
||||||
|
"""
|
||||||
|
Retrieve all events with same tag
|
||||||
|
|
||||||
|
:param tag: Tag of event
|
||||||
|
:return: Stored events that have same tag
|
||||||
|
:raises RetrievalError: If an error occured while attempting to retrieve the event
|
||||||
|
"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get_events_by_source(self, source: AgentID) -> Sequence[AbstractAgentEvent]:
|
||||||
|
"""
|
||||||
|
Retrieve all events from the same source
|
||||||
|
|
||||||
|
:param source: The ID of the agent that observed the events
|
||||||
|
:return: Stored events that have same source
|
||||||
|
:raises RetrievalError: If an error occured while attempting to retrieve the event
|
||||||
|
"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def reset(self):
|
||||||
|
"""
|
||||||
|
Remove all data from the repository
|
||||||
|
|
||||||
|
:raises RemovalError: If an error occurred while attempting to remove all events from the
|
||||||
|
repository
|
||||||
|
"""
|
|
@ -17,6 +17,7 @@ from monkey_island.cc.repository.attack.IMitigationsRepository import IMitigatio
|
||||||
from monkey_island.cc.repository.i_agent_repository import IAgentRepository
|
from monkey_island.cc.repository.i_agent_repository import IAgentRepository
|
||||||
from monkey_island.cc.repository.i_attack_repository import IAttackRepository
|
from monkey_island.cc.repository.i_attack_repository import IAttackRepository
|
||||||
from monkey_island.cc.repository.i_config_repository import IConfigRepository
|
from monkey_island.cc.repository.i_config_repository import IConfigRepository
|
||||||
|
from monkey_island.cc.repository.i_event_repository import IEventRepository
|
||||||
from monkey_island.cc.repository.i_log_repository import ILogRepository
|
from monkey_island.cc.repository.i_log_repository import ILogRepository
|
||||||
from monkey_island.cc.repository.i_machine_repository import IMachineRepository
|
from monkey_island.cc.repository.i_machine_repository import IMachineRepository
|
||||||
from monkey_island.cc.repository.i_report_repository import IReportRepository
|
from monkey_island.cc.repository.i_report_repository import IReportRepository
|
||||||
|
@ -301,6 +302,12 @@ deserialize
|
||||||
serialized_event
|
serialized_event
|
||||||
PydanticEventSerializer
|
PydanticEventSerializer
|
||||||
|
|
||||||
|
# TODO: Remove once #2180 is closed
|
||||||
|
IEventRepository.save_event
|
||||||
|
IEventRepository.get_events_by_type
|
||||||
|
IEventRepository.get_events_by_tag
|
||||||
|
IEventRepository.get_events_by_source
|
||||||
|
|
||||||
# pydantic base models
|
# pydantic base models
|
||||||
underscore_attrs_are_private
|
underscore_attrs_are_private
|
||||||
extra
|
extra
|
||||||
|
|
Loading…
Reference in New Issue