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.
This commit is contained in:
parent
5847674d92
commit
990244c3ac
|
@ -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}")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue