From b7786e2d0ac5afcf7c1ce0fc981e5d085c10e56a Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Mon, 11 Jul 2022 14:24:57 +0200 Subject: [PATCH] Island: Register mongo client in DI container --- monkey/monkey_island/cc/services/initialize.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/monkey/monkey_island/cc/services/initialize.py b/monkey/monkey_island/cc/services/initialize.py index a06d3635a..5c951eca3 100644 --- a/monkey/monkey_island/cc/services/initialize.py +++ b/monkey/monkey_island/cc/services/initialize.py @@ -66,6 +66,9 @@ def _register_conventions(container: DIContainer, data_dir: Path): "default_ransomware_agent_configuration", DEFAULT_RANSOMWARE_AGENT_CONFIGURATION, ) + container.register_convention( + MongoClient, "mongo", MongoClient(MONGO_URL, serverSelectionTimeoutMS=100) + ) def _register_repositories(container: DIContainer, data_dir: Path): @@ -78,7 +81,9 @@ def _register_repositories(container: DIContainer, data_dir: Path): IAgentConfigurationRepository, container.resolve(FileAgentConfigurationRepository) ) container.register_instance(ISimulationRepository, container.resolve(FileSimulationRepository)) - container.register_instance(ICredentialsRepository, _build_mongo_credentials_repository()) + container.register_instance( + ICredentialsRepository, container.resolve(MongoCredentialsRepository) + ) def _decorate_file_repository(file_repository: IFileRepository) -> IFileRepository: @@ -96,13 +101,6 @@ def _build_agent_binary_repository(): return agent_binary_repository -def _build_mongo_credentials_repository(): - mongo = MongoClient(MONGO_URL, serverSelectionTimeoutMS=100) - - mongo_credentials_repository = MongoCredentialsRepository(mongo) - return mongo_credentials_repository - - def _log_agent_binary_hashes(agent_binary_repository: IAgentBinaryRepository): """ Logs all the hashes of the agent executables for debbuging ease