From 947644152601fbecbb71ed603edbd2de9c8a13ea Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 11 May 2021 11:14:39 -0400 Subject: [PATCH] island: Remove circular dep btw ConfigService and PostBreachFilesService --- monkey/monkey_island/cc/services/config.py | 23 +++++++++++++++---- .../cc/services/post_breach_files.py | 21 +---------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index 3dbdd9039..c0fb3a20c 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -9,9 +9,11 @@ import monkey_island.cc.environment.environment_singleton as env_singleton from monkey_island.cc.database import mongo from monkey_island.cc.server_utils.encryptor import get_encryptor from monkey_island.cc.services.config_schema.config_schema import SCHEMA - -# TODO: Remove circular dependency between ConfigService and PostBreachFilesService. -from monkey_island.cc.services.post_breach_files import PostBreachFilesService +from monkey_island.cc.services.post_breach_files import ( + PBA_LINUX_FILENAME_PATH, + PBA_WINDOWS_FILENAME_PATH, + PostBreachFilesService, +) from monkey_island.cc.services.utils.network_utils import local_ip_addresses __author__ = "itay.mizeretz" @@ -193,7 +195,7 @@ class ConfigService: # PBA file upload happens on pba_file_upload endpoint and corresponding config options # are set there config_json = ConfigService._filter_none_values(config_json) - PostBreachFilesService.set_config_PBA_files(config_json) + ConfigService.set_config_PBA_files(config_json) if should_encrypt: try: ConfigService.encrypt_config(config_json) @@ -204,6 +206,19 @@ class ConfigService: logger.info("monkey config was updated") return True + @staticmethod + def set_config_PBA_files(config_json): + """ + Sets PBA file info in config_json to current config's PBA file info values. + :param config_json: config_json that will be modified + """ + if ConfigService.get_config(): + linux_filename = ConfigService.get_config_value(PBA_LINUX_FILENAME_PATH) + windows_filename = ConfigService.get_config_value(PBA_WINDOWS_FILENAME_PATH) + + config_json["monkey"]["post_breach"]["PBA_linux_filename"] = linux_filename + config_json["monkey"]["post_breach"]["PBA_windows_filename"] = windows_filename + @staticmethod def init_default_config(): if ConfigService.default_config is None: diff --git a/monkey/monkey_island/cc/services/post_breach_files.py b/monkey/monkey_island/cc/services/post_breach_files.py index 7e2ce4e45..1a8407564 100644 --- a/monkey/monkey_island/cc/services/post_breach_files.py +++ b/monkey/monkey_island/cc/services/post_breach_files.py @@ -2,16 +2,13 @@ import logging import os from pathlib import Path -# TODO: Remove circular dependency between ConfigService and PostBreachFilesService. -import monkey_island.cc.services.config - __author__ = "VakarisZ" logger = logging.getLogger(__name__) # Where to find file names in config -PBA_WINDOWS_FILENAME_PATH = ["monkey", "post_breach", "PBA_windows_filename"] PBA_LINUX_FILENAME_PATH = ["monkey", "post_breach", "PBA_linux_filename"] +PBA_WINDOWS_FILENAME_PATH = ["monkey", "post_breach", "PBA_windows_filename"] class PostBreachFilesService: @@ -45,19 +42,3 @@ class PostBreachFilesService: return os.path.join( PostBreachFilesService.DATA_DIR, PostBreachFilesService.CUSTOM_PBA_DIRNAME ) - - @staticmethod - def set_config_PBA_files(config_json): - """ - Sets PBA file info in config_json to current config's PBA file info values. - :param config_json: config_json that will be modified - """ - if monkey_island.cc.services.config.ConfigService.get_config(): - linux_filename = monkey_island.cc.services.config.ConfigService.get_config_value( - PBA_LINUX_FILENAME_PATH - ) - windows_filename = monkey_island.cc.services.config.ConfigService.get_config_value( - PBA_WINDOWS_FILENAME_PATH - ) - config_json["monkey"]["post_breach"]["PBA_linux_filename"] = linux_filename - config_json["monkey"]["post_breach"]["PBA_windows_filename"] = windows_filename