From 227039f30c18dba82993ed6a3bd3bbc7da2907c5 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 7 Jun 2021 19:44:42 +0530 Subject: [PATCH] Add `_expand_path()` to wrap `os.path.expandvars()\' and `os.path.expanduser()\' --- .../cc/setup/island_config_options.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/monkey/monkey_island/cc/setup/island_config_options.py b/monkey/monkey_island/cc/setup/island_config_options.py index e8a0f7016..664159944 100644 --- a/monkey/monkey_island/cc/setup/island_config_options.py +++ b/monkey/monkey_island/cc/setup/island_config_options.py @@ -13,8 +13,8 @@ from monkey_island.cc.server_utils.consts import ( class IslandConfigOptions: def __init__(self, config_contents: dict): - self.data_dir = os.path.expandvars( - os.path.expanduser(config_contents.get("data_dir", DEFAULT_DATA_DIR)) + self.data_dir = IslandConfigOptions._expand_path( + config_contents.get("data_dir", DEFAULT_DATA_DIR) ) self.log_level = config_contents.get("log_level", DEFAULT_LOG_LEVEL) @@ -23,9 +23,13 @@ class IslandConfigOptions: "mongodb", {"start_mongodb": DEFAULT_START_MONGO_DB} ).get("start_mongodb", DEFAULT_START_MONGO_DB) - self.crt_path = os.path.expandvars( - os.path.expanduser(config_contents.get("cert_path", DEFAULT_CRT_PATH)) + self.crt_path = IslandConfigOptions._expand_path( + config_contents.get("cert_path", DEFAULT_CRT_PATH) ) - self.key_path = os.path.expandvars( - os.path.expanduser(config_contents.get("key_path", DEFAULT_KEY_PATH)) + self.key_path = IslandConfigOptions._expand_path( + config_contents.get("key_path", DEFAULT_KEY_PATH) ) + + @staticmethod + def _expand_path(path: str) -> str: + return os.path.expandvars(os.path.expanduser(path))