From a329177b499fc32980bf4c13a9ca8bcf5550ec4e Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Sat, 2 Jul 2022 19:59:50 -0400 Subject: [PATCH] Island: Decorate LocalStorageFileRepository --- monkey/monkey_island/cc/services/initialize.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/monkey/monkey_island/cc/services/initialize.py b/monkey/monkey_island/cc/services/initialize.py index 28a88558c..dad5b92c7 100644 --- a/monkey/monkey_island/cc/services/initialize.py +++ b/monkey/monkey_island/cc/services/initialize.py @@ -12,6 +12,9 @@ from common.utils.file_utils import get_binary_io_sha256_hash from monkey_island.cc.repository import ( AgentBinaryRepository, FileAgentConfigurationRepository, + FileRepositoryCachingDecorator, + FileRepositoryLockingDecorator, + FileRepositoryLoggingDecorator, FileSimulationRepository, IAgentBinaryRepository, IAgentConfigurationRepository, @@ -62,7 +65,8 @@ def _register_conventions(container: DIContainer, data_dir: Path): def _register_repositories(container: DIContainer, data_dir: Path): container.register_instance( - IFileRepository, LocalStorageFileRepository(data_dir / "runtime_data") + IFileRepository, + _decorate_file_repository(LocalStorageFileRepository(data_dir / "runtime_data")), ) container.register_instance(IAgentBinaryRepository, _build_agent_binary_repository()) container.register_instance( @@ -71,6 +75,12 @@ def _register_repositories(container: DIContainer, data_dir: Path): container.register_instance(ISimulationRepository, container.resolve(FileSimulationRepository)) +def _decorate_file_repository(file_repository: IFileRepository) -> IFileRepository: + return FileRepositoryLockingDecorator( + FileRepositoryCachingDecorator(FileRepositoryLoggingDecorator(file_repository)) + ) + + def _build_agent_binary_repository(): file_repository = LocalStorageFileRepository(AGENT_BINARIES_PATH) agent_binary_repository = AgentBinaryRepository(file_repository)