From 4b3b7af3d20eedeb6ae363487067d92afa302dc5 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 4 May 2021 15:17:36 -0400 Subject: [PATCH] island: Remove coupling between EnvironmentConfig and UserCreds --- .../monkey_island/cc/environment/environment_config.py | 10 ++++++++-- monkey/monkey_island/cc/environment/user_creds.py | 9 --------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/monkey/monkey_island/cc/environment/environment_config.py b/monkey/monkey_island/cc/environment/environment_config.py index 65c6e57b8..1f9602d22 100644 --- a/monkey/monkey_island/cc/environment/environment_config.py +++ b/monkey/monkey_island/cc/environment/environment_config.py @@ -38,13 +38,12 @@ class EnvironmentConfig: self._load_from_dict(data) def _load_from_dict(self, dict_data: Dict): - user_creds = UserCreds.get_from_server_config_dict(dict_data) aws = dict_data["aws"] if "aws" in dict_data else None data_dir = dict_data["data_dir"] if "data_dir" in dict_data else DEFAULT_DATA_DIR self.server_config = dict_data["server_config"] self.deployment = dict_data["deployment"] - self.user_creds = user_creds + self.user_creds = _get_user_credentials_from_config(dict_data) self.aws = aws self.data_dir = data_dir @@ -75,3 +74,10 @@ class EnvironmentConfig: def get_users(self) -> List[User]: auth_user = self.user_creds.to_auth_user() return [auth_user] if auth_user else [] + + +def _get_user_credentials_from_config(dict_data: Dict): + username = dict_data.get("user", "") + password_hash = dict_data.get("password_hash", "") + + return UserCreds(username, password_hash) diff --git a/monkey/monkey_island/cc/environment/user_creds.py b/monkey/monkey_island/cc/environment/user_creds.py index 498511675..6cd483f70 100644 --- a/monkey/monkey_island/cc/environment/user_creds.py +++ b/monkey/monkey_island/cc/environment/user_creds.py @@ -44,15 +44,6 @@ class UserCreds: ).decode() return creds - @staticmethod - def get_from_server_config_dict(data_dict: Dict) -> UserCreds: - creds = UserCreds() - if "user" in data_dict: - creds.username = data_dict["user"] - if "password_hash" in data_dict: - creds.password_hash = data_dict["password_hash"] - return creds - @staticmethod def get_from_json(json_data: bytes) -> UserCreds: cred_dict = json.loads(json_data)