diff --git a/monkey/monkey_island.py b/monkey/monkey_island.py index b0e510d21..8a2e0608b 100644 --- a/monkey/monkey_island.py +++ b/monkey/monkey_island.py @@ -7,26 +7,9 @@ gevent_monkey.patch_all() import json # noqa: E402 import os # noqa: E402 -from monkey_island.cc.server_utils.consts import DEFAULT_DATA_DIR # noqa: E402 +from monkey_island import config_loader # noqa: E402 from monkey_island.cc.server_utils.island_logger import setup_logging # noqa: E402 -DEFAULT_LOG_LEVEL = "INFO" - - -def load_server_config(path): - with open(server_config_path, "r") as f: - config_content = f.read() - data = json.loads(config_content) - data_dir = os.path.abspath( - os.path.expanduser( - os.path.expandvars(data["data_dir"] if "data_dir" in data else DEFAULT_DATA_DIR) - ) - ) - log_level = data["log_level"] if "log_level" in data else DEFAULT_LOG_LEVEL - - return data_dir, log_level - - if "__main__" == __name__: island_args = parse_cli_args() @@ -35,7 +18,7 @@ if "__main__" == __name__: try: server_config_path = os.path.expanduser(island_args.server_config) - data_dir, log_level = load_server_config(server_config_path) + data_dir, log_level = config_loader.load_server_config(server_config_path) setup_logging(data_dir, log_level) diff --git a/monkey/monkey_island/config_loader.py b/monkey/monkey_island/config_loader.py new file mode 100644 index 000000000..8f0a7d19b --- /dev/null +++ b/monkey/monkey_island/config_loader.py @@ -0,0 +1,20 @@ +import json +import os + +from monkey_island.cc.server_utils.consts import DEFAULT_DATA_DIR + +DEFAULT_LOG_LEVEL = "INFO" + + +def load_server_config(server_config_path): + with open(server_config_path, "r") as f: + config_content = f.read() + data = json.loads(config_content) + data_dir = os.path.abspath( + os.path.expanduser( + os.path.expandvars(data["data_dir"] if "data_dir" in data else DEFAULT_DATA_DIR) + ) + ) + log_level = data["log_level"] if "log_level" in data else DEFAULT_LOG_LEVEL + + return data_dir, log_level