From 6e7ddbc6c7909023bcc17044ffb5d94002f1fa1a Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Wed, 1 Dec 2021 14:35:37 +0200 Subject: [PATCH] Agent: improve the readability of island_config_options.py --- .../cc/setup/island_config_options.py | 38 +++++++------------ 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/monkey/monkey_island/cc/setup/island_config_options.py b/monkey/monkey_island/cc/setup/island_config_options.py index 384ed3079..27df897e8 100644 --- a/monkey/monkey_island/cc/setup/island_config_options.py +++ b/monkey/monkey_island/cc/setup/island_config_options.py @@ -1,7 +1,5 @@ from __future__ import annotations -from dpath import util - from common.utils.file_utils import expand_path from monkey_island.cc.server_utils.consts import ( DEFAULT_CERTIFICATE_PATHS, @@ -25,7 +23,7 @@ class IslandConfigOptions: def __init__(self, config_contents: dict = None): if not config_contents: config_contents = {} - self.data_dir = expand_path(config_contents.get(_DATA_DIR, DEFAULT_DATA_DIR)) + self.data_dir = config_contents.get(_DATA_DIR, DEFAULT_DATA_DIR) self.log_level = config_contents.get(_LOG_LEVEL, DEFAULT_LOG_LEVEL) @@ -33,30 +31,20 @@ class IslandConfigOptions: _MONGODB, {_START_MONGODB: DEFAULT_START_MONGO_DB} ).get(_START_MONGODB, DEFAULT_START_MONGO_DB) - self.crt_path = expand_path( - config_contents.get(_SSL_CERT, DEFAULT_CERTIFICATE_PATHS).get( - _SSL_CERT_FILE, DEFAULT_CRT_PATH - ) + self.crt_path = config_contents.get(_SSL_CERT, DEFAULT_CERTIFICATE_PATHS).get( + _SSL_CERT_FILE, DEFAULT_CRT_PATH ) - self.key_path = expand_path( - config_contents.get(_SSL_CERT, DEFAULT_CERTIFICATE_PATHS).get( - _SSL_CERT_KEY, DEFAULT_KEY_PATH - ) + self.key_path = config_contents.get(_SSL_CERT, DEFAULT_CERTIFICATE_PATHS).get( + _SSL_CERT_KEY, DEFAULT_KEY_PATH ) + self._expand_paths() + + def _expand_paths(self): + self.data_dir = expand_path(str(self.data_dir)) + self.crt_path = expand_path(str(self.crt_path)) + self.key_path = expand_path(str(self.key_path)) + def update(self, target: dict): - target = self._expand_config_paths(target) self.__dict__.update(target) - - @staticmethod - def _expand_config_paths(config: dict) -> dict: - config_paths = [_DATA_DIR, f"{_SSL_CERT}.{_SSL_CERT_FILE}", f"{_SSL_CERT}.{_SSL_CERT_KEY}"] - - for config_path in config_paths: - try: - expanded_val = expand_path(util.get(config, config_path, ".")) - util.set(config, config_path, expanded_val, ".") - except KeyError: - pass - - return config + self._expand_paths()