Island: Remove unreferenced EnvironmentConfig

This commit is contained in:
Mike Salvatore 2021-11-19 08:39:01 -05:00
parent 138e3ecee6
commit 38a898824a
3 changed files with 0 additions and 89 deletions

View File

@ -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

View File

@ -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")

View File

@ -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"]