From 38a898824a384cccba1491341dbd1c308763305a Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Fri, 19 Nov 2021 08:39:01 -0500 Subject: [PATCH] Island: Remove unreferenced EnvironmentConfig --- .../cc/environment/environment_config.py | 49 ------------------- .../monkey_island/cc/environment/conftest.py | 8 --- .../cc/environment/test_environment_config.py | 32 ------------ 3 files changed, 89 deletions(-) delete mode 100644 monkey/monkey_island/cc/environment/environment_config.py delete mode 100644 monkey/tests/unit_tests/monkey_island/cc/environment/conftest.py delete mode 100644 monkey/tests/unit_tests/monkey_island/cc/environment/test_environment_config.py diff --git a/monkey/monkey_island/cc/environment/environment_config.py b/monkey/monkey_island/cc/environment/environment_config.py deleted file mode 100644 index 9eba1fd6f..000000000 --- a/monkey/monkey_island/cc/environment/environment_config.py +++ /dev/null @@ -1,49 +0,0 @@ -from __future__ import annotations - -import json -import os -from typing import Dict - - -class EnvironmentConfig: - def __init__(self, file_path): - self._server_config_path = os.path.expanduser(file_path) - self.server_config = None - self.aws = None - - self._load_from_file(self._server_config_path) - - def _load_from_file(self, file_path): - file_path = os.path.expanduser(file_path) - - with open(file_path, "r") as f: - config_content = f.read() - - self._load_from_json(config_content) - - def _load_from_json(self, config_json: str): - data = json.loads(config_json) - self._load_from_dict(data["environment"]) - - def _load_from_dict(self, dict_data: Dict): - aws = dict_data["aws"] if "aws" in dict_data else None - - self.server_config = dict_data["server_config"] - self.aws = aws - - def save_to_file(self): - with open(self._server_config_path, "r") as f: - config = json.load(f) - - config["environment"] = self.to_dict() - - with open(self._server_config_path, "w") as f: - f.write(json.dumps(config, indent=2)) - - def to_dict(self) -> Dict: - config_dict = { - "server_config": self.server_config, - } - if self.aws: - config_dict.update({"aws": self.aws}) - return config_dict diff --git a/monkey/tests/unit_tests/monkey_island/cc/environment/conftest.py b/monkey/tests/unit_tests/monkey_island/cc/environment/conftest.py deleted file mode 100644 index 2faa9c090..000000000 --- a/monkey/tests/unit_tests/monkey_island/cc/environment/conftest.py +++ /dev/null @@ -1,8 +0,0 @@ -import os - -import pytest - - -@pytest.fixture(scope="module") -def no_credentials(server_configs_dir): - return os.path.join(server_configs_dir, "server_config_no_credentials.json") diff --git a/monkey/tests/unit_tests/monkey_island/cc/environment/test_environment_config.py b/monkey/tests/unit_tests/monkey_island/cc/environment/test_environment_config.py deleted file mode 100644 index 403d24263..000000000 --- a/monkey/tests/unit_tests/monkey_island/cc/environment/test_environment_config.py +++ /dev/null @@ -1,32 +0,0 @@ -import json -import os -import shutil - -import pytest - -from monkey_island.cc.environment.environment_config import EnvironmentConfig - - -@pytest.fixture -def config_file(tmpdir): - return os.path.join(tmpdir, "test_config.json") - - -def test_get_with_no_credentials(no_credentials): - config_dict = EnvironmentConfig(no_credentials).to_dict() - - assert len(config_dict.keys()) == 1 - assert config_dict["server_config"] == "password" - - -def test_save_to_file(config_file, no_credentials): - shutil.copyfile(no_credentials, config_file) - - environment_config = EnvironmentConfig(config_file) - environment_config.aws = "test_aws" - environment_config.save_to_file() - - with open(config_file, "r") as f: - from_file = json.load(f) - - assert environment_config.to_dict() == from_file["environment"]