Island: Add IAgentLogRepository

This commit is contained in:
Mike Salvatore 2022-09-22 09:58:14 -04:00
parent 9c0ea39b6d
commit 2c4625eb1c
3 changed files with 44 additions and 0 deletions

View File

@ -11,6 +11,7 @@ from .i_machine_repository import IMachineRepository
from .i_agent_repository import IAgentRepository
from .i_node_repository import INodeRepository
from .i_agent_event_repository import IAgentEventRepository
from .i_agent_log_repository import IAgentLogRepository
from .local_storage_file_repository import LocalStorageFileRepository

View File

@ -0,0 +1,37 @@
from abc import ABC, abstractmethod
from monkey_island.cc.models import AgentID
class IAgentLogRepository(ABC):
"""A repository used to store `Agent` logs"""
@abstractmethod
def upsert_agent_log(self, agent_id: AgentID, log_contents: str):
"""
Upsert (insert or update) the log contents for a particular agent
:param agent_id: The ID of the `Agent` that generated the log
:param log_contents: The log contents
:raises StorageError: If an error occurs while attempting to store the log
"""
@abstractmethod
def get_agent_log(self, agent_id: AgentID) -> str:
"""
Get the log for a specific agent
:param agent_id: The ID of the `Agent` that generated the log
:return: The log contents for the requested `Agent`
:raises UnknownRecordError: If no log for the requested `Agent` is available
:raises RetrievalError: If an error occurs while attempting to retrieve the log
"""
@abstractmethod
def reset(self):
"""
Removes all data from the repository
:raises RemovalError: If an error occurs while attempting to reset the repository
"""

View File

@ -15,6 +15,7 @@ from monkey_island.cc.models.networkmap import Arc, NetworkMap
from monkey_island.cc.repository import MongoAgentRepository, MongoMachineRepository
from monkey_island.cc.repository.attack.IMitigationsRepository import IMitigationsRepository
from monkey_island.cc.repository.i_agent_event_repository import IAgentEventRepository
from monkey_island.cc.repository.i_agent_log_repository import IAgentLogRepository
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_config_repository import IConfigRepository
@ -300,6 +301,11 @@ IAgentEventRepository.get_events_by_type
IAgentEventRepository.get_events_by_tag
IAgentEventRepository.get_events_by_source
# TODO: Remove once #2274 is closed
IAgentLogRepository
IAgentLogRepository.upsert_agent_log
IAgentLogRepository.get_agent_log
# pydantic base models
underscore_attrs_are_private