From b89ffbae241dddadba9b1a210fd8698b545be4a1 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Mon, 1 Aug 2022 13:28:19 +0530 Subject: [PATCH] Island: Register Island log file path as convention in DI container and inject into IslandLog --- monkey/monkey_island/cc/resources/island_logs.py | 4 ++++ monkey/monkey_island/cc/services/initialize.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/monkey/monkey_island/cc/resources/island_logs.py b/monkey/monkey_island/cc/resources/island_logs.py index 85184e0c5..3e37e1748 100644 --- a/monkey/monkey_island/cc/resources/island_logs.py +++ b/monkey/monkey_island/cc/resources/island_logs.py @@ -1,4 +1,5 @@ import logging +from pathlib import Path from monkey_island.cc.resources.AbstractResource import AbstractResource from monkey_island.cc.resources.request_authentication import jwt_required @@ -10,6 +11,9 @@ logger = logging.getLogger(__name__) class IslandLog(AbstractResource): urls = ["/api/island/log"] + def __init__(self, island_log_file_path: Path): + self._island_log_file_path = island_log_file_path + @jwt_required def get(self): try: diff --git a/monkey/monkey_island/cc/services/initialize.py b/monkey/monkey_island/cc/services/initialize.py index c3623e716..ff2872c7f 100644 --- a/monkey/monkey_island/cc/services/initialize.py +++ b/monkey/monkey_island/cc/services/initialize.py @@ -32,6 +32,7 @@ from monkey_island.cc.repository import ( ) 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.island_logger import get_log_file_path from monkey_island.cc.services import AWSService, IslandModeService, RepositoryService from monkey_island.cc.services.attack.technique_reports.T1003 import T1003, T1003GetReportData from monkey_island.cc.services.run_local_monkey import LocalMonkeyRunService @@ -87,6 +88,7 @@ def _register_conventions(container: DIContainer, data_dir: Path): "default_ransomware_agent_configuration", DEFAULT_RANSOMWARE_AGENT_CONFIGURATION, ) + container.register_convention(Path, "island_log_file_path", get_log_file_path()) def _register_repositories(container: DIContainer, data_dir: Path):