Island: Rename IEventRepository -> IAgentEventRepository

This commit is contained in:
Shreya Malviya 2022-09-16 18:11:08 +05:30 committed by Mike Salvatore
parent f0d5545f28
commit 0dccbd32b6
8 changed files with 13 additions and 13 deletions

View File

@ -1,13 +1,13 @@
import logging import logging
from common.events import AbstractAgentEvent from common.events import AbstractAgentEvent
from monkey_island.cc.repository import IEventRepository, StorageError from monkey_island.cc.repository import IAgentEventRepository, StorageError
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class save_event_to_event_repository: class save_event_to_event_repository:
def __init__(self, event_repository: IEventRepository): def __init__(self, event_repository: IAgentEventRepository):
self._event_repository = event_repository self._event_repository = event_repository
def __call__(self, event: AbstractAgentEvent): def __call__(self, event: AbstractAgentEvent):

View File

@ -10,7 +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 .i_event_repository import IAgentEventRepository
from .local_storage_file_repository import LocalStorageFileRepository from .local_storage_file_repository import LocalStorageFileRepository

View File

@ -7,7 +7,7 @@ from common.types import AgentID
T = TypeVar("T", bound=AbstractAgentEvent) T = TypeVar("T", bound=AbstractAgentEvent)
class IEventRepository(ABC): class IAgentEventRepository(ABC):
"""A repository used to store and retrieve event objects""" """A repository used to store and retrieve event objects"""
@abstractmethod @abstractmethod

View File

@ -5,13 +5,13 @@ from pymongo import MongoClient
from common.agent_event_serializers import EVENT_TYPE_FIELD, AgentEventSerializerRegistry from common.agent_event_serializers import EVENT_TYPE_FIELD, AgentEventSerializerRegistry
from common.events import AbstractAgentEvent from common.events import AbstractAgentEvent
from common.types import AgentID from common.types import AgentID
from monkey_island.cc.repository import IEventRepository from monkey_island.cc.repository import IAgentEventRepository
from . import RemovalError, RetrievalError, StorageError from . import RemovalError, RetrievalError, StorageError
from .consts import MONGO_OBJECT_ID_KEY from .consts import MONGO_OBJECT_ID_KEY
class MongoEventRepository(IEventRepository): class MongoEventRepository(IAgentEventRepository):
"""A repository for storing and retrieving events in MongoDB""" """A repository for storing and retrieving events in MongoDB"""
def __init__( def __init__(

View File

@ -3,13 +3,13 @@ from typing import Sequence, Type, TypeVar
from common.events import AbstractAgentEvent from common.events import AbstractAgentEvent
from common.types import AgentID from common.types import AgentID
from . import IEventRepository from . import IAgentEventRepository
T = TypeVar("T", bound=AbstractAgentEvent) T = TypeVar("T", bound=AbstractAgentEvent)
# TODO: Remove this class after #2180 is complete # TODO: Remove this class after #2180 is complete
class StubbedEventRepository(IEventRepository): class StubbedEventRepository(IAgentEventRepository):
def save_event(self, event: AbstractAgentEvent): def save_event(self, event: AbstractAgentEvent):
return return

View File

@ -4,7 +4,7 @@ from typing import Optional, Sequence
from monkey_island.cc.models.zero_trust.event import Event from monkey_island.cc.models.zero_trust.event import Event
class IEventRepository(ABC): class IAgentEventRepository(ABC):
def get_events(self, finding_id: Optional[str] = None) -> Sequence[Event]: def get_events(self, finding_id: Optional[str] = None) -> Sequence[Event]:
pass pass

View File

@ -23,8 +23,8 @@ from monkey_island.cc.repository import (
FileSimulationRepository, FileSimulationRepository,
IAgentBinaryRepository, IAgentBinaryRepository,
IAgentConfigurationRepository, IAgentConfigurationRepository,
IAgentEventRepository,
ICredentialsRepository, ICredentialsRepository,
IEventRepository,
IFileRepository, IFileRepository,
ISimulationRepository, ISimulationRepository,
IUserRepository, IUserRepository,
@ -102,7 +102,7 @@ def _register_repositories(container: DIContainer, data_dir: Path):
container.register_instance(IUserRepository, container.resolve(JSONFileUserRepository)) container.register_instance(IUserRepository, container.resolve(JSONFileUserRepository))
# TODO: Replace with MongoEventRepository # TODO: Replace with MongoEventRepository
container.register_instance(IEventRepository, StubbedEventRepository()) container.register_instance(IAgentEventRepository, StubbedEventRepository())
def _decorate_file_repository(file_repository: IFileRepository) -> IFileRepository: def _decorate_file_repository(file_repository: IFileRepository) -> IFileRepository:

View File

@ -5,7 +5,7 @@ from monkey_island.cc.agent_event_handlers import (
save_event_to_event_repository, save_event_to_event_repository,
save_stolen_credentials_to_repository, save_stolen_credentials_to_repository,
) )
from monkey_island.cc.repository import ICredentialsRepository, IEventRepository from monkey_island.cc.repository import IAgentEventRepository, ICredentialsRepository
def setup_agent_event_handlers(container: DIContainer): def setup_agent_event_handlers(container: DIContainer):
@ -15,7 +15,7 @@ def setup_agent_event_handlers(container: DIContainer):
def _subscribe_and_store_to_event_repository(container: DIContainer): def _subscribe_and_store_to_event_repository(container: DIContainer):
agent_event_queue = container.resolve(IAgentEventQueue) agent_event_queue = container.resolve(IAgentEventQueue)
save_event_subscriber = save_event_to_event_repository(container.resolve(IEventRepository)) save_event_subscriber = save_event_to_event_repository(container.resolve(IAgentEventRepository))
agent_event_queue.subscribe_all_events(save_event_subscriber) agent_event_queue.subscribe_all_events(save_event_subscriber)
save_stolen_credentials_subscriber = save_stolen_credentials_to_repository( save_stolen_credentials_subscriber = save_stolen_credentials_to_repository(