diff --git a/monkey/monkey_island/cc/services/initialize.py b/monkey/monkey_island/cc/services/initialize.py index 8cbaa4a7a..9e6425215 100644 --- a/monkey/monkey_island/cc/services/initialize.py +++ b/monkey/monkey_island/cc/services/initialize.py @@ -43,6 +43,7 @@ from monkey_island.cc.repository import ( MongoMachineRepository, MongoNodeRepository, RetrievalError, + initialize_machine_repository, ) from monkey_island.cc.server_utils.consts import MONKEY_ISLAND_ABS_PATH from monkey_island.cc.server_utils.encryption import ILockableEncryptor, RepositoryEncryptor @@ -114,7 +115,7 @@ def _register_repositories(container: DIContainer, data_dir: Path): container.register_instance(IAgentEventRepository, container.resolve(MongoAgentEventRepository)) container.register_instance(INodeRepository, container.resolve(MongoNodeRepository)) - container.register_instance(IMachineRepository, container.resolve(MongoMachineRepository)) + container.register_instance(IMachineRepository, _build_machine_repository(container)) container.register_instance(IAgentRepository, container.resolve(MongoAgentRepository)) @@ -133,6 +134,13 @@ def _build_agent_binary_repository() -> IAgentBinaryRepository: return agent_binary_repository +def _build_machine_repository(container: DIContainer) -> IMachineRepository: + machine_repository = container.resolve(MongoMachineRepository) + initialize_machine_repository(machine_repository) + + return machine_repository + + def _setup_agent_event_serializers(container: DIContainer): agent_event_serializer_registry = AgentEventSerializerRegistry() register_common_agent_event_serializers(agent_event_serializer_registry)