Island: Add IEventRepository

This commit is contained in:
Ilija Lazoroski 2022-09-14 12:34:29 +02:00
parent ed0e8c4870
commit c54d1b89ab
3 changed files with 76 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,68 @@
from abc import ABC, abstractmethod
from typing import Sequence, Type
from common.events import AbstractAgentEvent
from common.types import AgentID
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[AbstractAgentEvent]
) -> Sequence[AbstractAgentEvent]:
"""
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
"""

View File

@ -16,6 +16,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
@ -300,6 +301,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