island: Replace calls to os.{expandpath,expandusers} with expand_path()

This commit is contained in:
Mike Salvatore 2021-06-07 13:21:16 -04:00
parent bf0fe10ea9
commit 4e1b4fbf6b
2 changed files with 5 additions and 4 deletions

View File

@ -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)
)

View File

@ -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