From 4e1b4fbf6b85f078109fcdd5d81844b405632300 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 7 Jun 2021 13:21:16 -0400 Subject: [PATCH] island: Replace calls to os.{expandpath,expandusers} with expand_path() --- monkey/monkey_island/cc/server_utils/consts.py | 5 +++-- monkey/monkey_island/cc/setup/config_setup.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/monkey/monkey_island/cc/server_utils/consts.py b/monkey/monkey_island/cc/server_utils/consts.py index 9149d81b1..02f23428d 100644 --- a/monkey/monkey_island/cc/server_utils/consts.py +++ b/monkey/monkey_island/cc/server_utils/consts.py @@ -2,6 +2,7 @@ import os from pathlib import Path from monkey_island.cc.environment.utils import is_windows_os +from monkey_island.cc.server_utils import file_utils __author__ = "itay.mizeretz" @@ -25,7 +26,7 @@ SERVER_CONFIG_FILENAME = "server_config.json" MONKEY_ISLAND_ABS_PATH = _get_monkey_island_abs_path() -DEFAULT_DATA_DIR = os.path.expandvars(get_default_data_dir()) +DEFAULT_DATA_DIR = file_utils.expand_path(get_default_data_dir()) DEFAULT_MONKEY_TTL_EXPIRY_DURATION_IN_SECONDS = 60 * 5 @@ -36,7 +37,7 @@ MONGO_EXECUTABLE_PATH = ( _MONGO_EXECUTABLE_PATH_WIN if is_windows_os() else _MONGO_EXECUTABLE_PATH_LINUX ) -DEFAULT_SERVER_CONFIG_PATH = os.path.expandvars( +DEFAULT_SERVER_CONFIG_PATH = file_utils.expand_path( os.path.join(DEFAULT_DATA_DIR, SERVER_CONFIG_FILENAME) ) diff --git a/monkey/monkey_island/cc/setup/config_setup.py b/monkey/monkey_island/cc/setup/config_setup.py index 6cc036760..3621ea7fc 100644 --- a/monkey/monkey_island/cc/setup/config_setup.py +++ b/monkey/monkey_island/cc/setup/config_setup.py @@ -1,9 +1,9 @@ -import os from typing import Tuple from monkey_island.cc.arg_parser import IslandCmdArgs from monkey_island.cc.environment import server_config_handler from monkey_island.cc.environment.utils import create_secure_directory +from monkey_island.cc.server_utils import file_utils from monkey_island.cc.server_utils.consts import DEFAULT_DATA_DIR, DEFAULT_SERVER_CONFIG_PATH from monkey_island.cc.setup.island_config_options import IslandConfigOptions @@ -16,7 +16,7 @@ def setup_data_dir(island_args: IslandCmdArgs) -> Tuple[IslandConfigOptions, str def _setup_config_by_cmd_arg(server_config_path) -> Tuple[IslandConfigOptions, str]: - server_config_path = os.path.expandvars(os.path.expanduser(server_config_path)) + server_config_path = file_utils.expand_path(server_config_path) config = server_config_handler.load_server_config_from_file(server_config_path) create_secure_directory(config.data_dir, create_parent_dirs=True) return config, server_config_path