From 990244c3ac7605457b9253ce1f5e7d61a7377c7b Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 11 May 2021 13:16:24 -0400 Subject: [PATCH] island: Return config dict from load_server_config() As the number of configuration items will increase in the future, return the config dict instead of individual config properties. --- monkey/monkey_island.py | 4 ++-- monkey/monkey_island/config_loader.py | 10 +++++----- monkey/tests/monkey_island/test_config_loader.py | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/monkey/monkey_island.py b/monkey/monkey_island.py index 8a2e0608b..51f2e1a11 100644 --- a/monkey/monkey_island.py +++ b/monkey/monkey_island.py @@ -18,9 +18,9 @@ if "__main__" == __name__: try: server_config_path = os.path.expanduser(island_args.server_config) - data_dir, log_level = config_loader.load_server_config(server_config_path) + config = config_loader.load_server_config(server_config_path) - setup_logging(data_dir, log_level) + setup_logging(config["data_dir"], config["log_level"]) except OSError as ex: print(f"Error opening server config file: {ex}") diff --git a/monkey/monkey_island/config_loader.py b/monkey/monkey_island/config_loader.py index 8f0a7d19b..357cacbb8 100644 --- a/monkey/monkey_island/config_loader.py +++ b/monkey/monkey_island/config_loader.py @@ -9,12 +9,12 @@ 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( + config = json.loads(config_content) + config["data_dir"] = os.path.abspath( os.path.expanduser( - os.path.expandvars(data["data_dir"] if "data_dir" in data else DEFAULT_DATA_DIR) + os.path.expandvars(config["data_dir"] if "data_dir" in config else DEFAULT_DATA_DIR) ) ) - log_level = data["log_level"] if "log_level" in data else DEFAULT_LOG_LEVEL + config["log_level"] = config["log_level"] if "log_level" in config else DEFAULT_LOG_LEVEL - return data_dir, log_level + return config diff --git a/monkey/tests/monkey_island/test_config_loader.py b/monkey/tests/monkey_island/test_config_loader.py index ac2e35377..f65bfe197 100644 --- a/monkey/tests/monkey_island/test_config_loader.py +++ b/monkey/tests/monkey_island/test_config_loader.py @@ -4,7 +4,7 @@ from monkey_island import config_loader def test_load_server_config_from_file(test_server_config, mock_home_env): - (data_dir, log_level) = config_loader.load_server_config(test_server_config) + config = config_loader.load_server_config(test_server_config) - assert data_dir == os.path.join(mock_home_env, ".monkey_island") - assert log_level == "NOTICE" + assert config["data_dir"] == os.path.join(mock_home_env, ".monkey_island") + assert config["log_level"] == "NOTICE"