Island: Initialize IMachineRepository on Island start

This commit is contained in:
Mike Salvatore 2022-09-20 14:27:58 -04:00
parent ff0a57aa93
commit 36142774dd
1 changed files with 9 additions and 1 deletions

View File

@ -43,6 +43,7 @@ from monkey_island.cc.repository import (
MongoMachineRepository, MongoMachineRepository,
MongoNodeRepository, MongoNodeRepository,
RetrievalError, RetrievalError,
initialize_machine_repository,
) )
from monkey_island.cc.server_utils.consts import MONKEY_ISLAND_ABS_PATH from monkey_island.cc.server_utils.consts import MONKEY_ISLAND_ABS_PATH
from monkey_island.cc.server_utils.encryption import ILockableEncryptor, RepositoryEncryptor 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(IAgentEventRepository, container.resolve(MongoAgentEventRepository))
container.register_instance(INodeRepository, container.resolve(MongoNodeRepository)) 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)) container.register_instance(IAgentRepository, container.resolve(MongoAgentRepository))
@ -133,6 +134,13 @@ def _build_agent_binary_repository() -> IAgentBinaryRepository:
return agent_binary_repository 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): def _setup_agent_event_serializers(container: DIContainer):
agent_event_serializer_registry = AgentEventSerializerRegistry() agent_event_serializer_registry = AgentEventSerializerRegistry()
register_common_agent_event_serializers(agent_event_serializer_registry) register_common_agent_event_serializers(agent_event_serializer_registry)