Merge branch 'default-data-dir-bug' into develop

This commit is contained in:
Mike Salvatore 2021-06-07 06:41:38 -04:00
commit a815850c9e
7 changed files with 23 additions and 33 deletions

View File

@ -21,9 +21,6 @@ python:
os: linux
before_install:
# Init server_config.json to default
- cp monkey/monkey_island/cc/server_config.json.develop monkey/monkey_island/cc/server_config.json
install:
# Python

View File

@ -2,20 +2,20 @@ import json
import os
from pathlib import Path
from monkey_island.cc.server_utils.consts import (
DEFAULT_DEVELOP_SERVER_CONFIG_PATH,
DEFAULT_SERVER_CONFIG_PATH,
)
from monkey_island.cc.server_utils.consts import DEFAULT_SERVER_CONFIG_PATH, SERVER_CONFIG_FILENAME
from monkey_island.cc.setup.island_config_options import IslandConfigOptions
def create_default_server_config_file() -> None:
if not os.path.isfile(DEFAULT_SERVER_CONFIG_PATH):
write_default_server_config_to_file(DEFAULT_SERVER_CONFIG_PATH)
def create_default_server_config_file(data_dir: str) -> str:
config_file_path = os.path.join(data_dir, SERVER_CONFIG_FILENAME)
if not os.path.isfile(config_file_path):
write_default_server_config_to_file(config_file_path)
return config_file_path
def write_default_server_config_to_file(path: str) -> None:
default_config = Path(DEFAULT_DEVELOP_SERVER_CONFIG_PATH).read_text()
default_config = Path(DEFAULT_SERVER_CONFIG_PATH).read_text()
Path(path).write_text(default_config)

View File

@ -37,11 +37,7 @@ MONGO_EXECUTABLE_PATH = (
)
DEFAULT_SERVER_CONFIG_PATH = os.path.expandvars(
os.path.join(DEFAULT_DATA_DIR, SERVER_CONFIG_FILENAME)
)
DEFAULT_DEVELOP_SERVER_CONFIG_PATH = os.path.join(
MONKEY_ISLAND_ABS_PATH, "cc", f"{SERVER_CONFIG_FILENAME}.develop"
os.path.join(MONKEY_ISLAND_ABS_PATH, "cc", SERVER_CONFIG_FILENAME)
)
DEFAULT_LOG_LEVEL = "INFO"

View File

@ -4,7 +4,7 @@ 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.consts import DEFAULT_DATA_DIR, DEFAULT_SERVER_CONFIG_PATH
from monkey_island.cc.server_utils.consts import DEFAULT_SERVER_CONFIG_PATH
from monkey_island.cc.setup.island_config_options import IslandConfigOptions
@ -23,8 +23,7 @@ def _setup_config_by_cmd_arg(server_config_path) -> Tuple[IslandConfigOptions, s
def _setup_default_config() -> Tuple[IslandConfigOptions, str]:
server_config_path = DEFAULT_SERVER_CONFIG_PATH
create_secure_directory(DEFAULT_DATA_DIR, create_parent_dirs=False)
server_config_handler.create_default_server_config_file()
config = server_config_handler.load_server_config_from_file(server_config_path)
config = server_config_handler.load_server_config_from_file(DEFAULT_SERVER_CONFIG_PATH)
create_secure_directory(config.data_dir, create_parent_dirs=False)
server_config_path = server_config_handler.create_default_server_config_file(config.data_dir)
return config, server_config_path

View File

@ -1,4 +1,5 @@
import os
import platform
from monkey_island.cc.server_utils import consts
@ -6,3 +7,12 @@ from monkey_island.cc.server_utils import consts
def test_monkey_island_abs_path():
assert consts.MONKEY_ISLAND_ABS_PATH.endswith("monkey_island")
assert os.path.isdir(consts.MONKEY_ISLAND_ABS_PATH)
def test_default_server_config_file_path():
if platform.system() == "Windows":
server_file_path = f"{consts.MONKEY_ISLAND_ABS_PATH}\\cc\\{consts.SERVER_CONFIG_FILENAME}"
else:
server_file_path = f"{consts.MONKEY_ISLAND_ABS_PATH}/cc/{consts.SERVER_CONFIG_FILENAME}"
assert consts.DEFAULT_SERVER_CONFIG_PATH == server_file_path

View File

@ -1,12 +0,0 @@
import platform
import monkey_island.cc.server_utils.consts as consts
def test_default_server_config_file_path():
if platform.system() == "Windows":
server_file_path = f"{consts.DEFAULT_DATA_DIR}\\{consts.SERVER_CONFIG_FILENAME}"
else:
server_file_path = f"{consts.DEFAULT_DATA_DIR}/{consts.SERVER_CONFIG_FILENAME}"
assert consts.DEFAULT_SERVER_CONFIG_PATH == server_file_path