Split `get_from_dict()` into 2 functions as per usage

This commit is contained in:
Shreya 2021-05-03 23:28:55 +05:30
parent d2083149dd
commit 02f3b15c64
2 changed files with 12 additions and 3 deletions

View File

@ -38,7 +38,7 @@ class EnvironmentConfig:
self._load_from_dict(data)
def _load_from_dict(self, dict_data: Dict):
user_creds = UserCreds.get_from_dict(dict_data)
user_creds = UserCreds.get_from_dict_server_config(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

View File

@ -28,7 +28,7 @@ class UserCreds:
return User(1, self.username, self.password_hash)
@staticmethod
def get_from_dict(data_dict: Dict) -> UserCreds:
def get_from_dict_new_registration(data_dict: Dict) -> UserCreds:
creds = UserCreds()
if "user" in data_dict:
creds.username = data_dict["user"]
@ -38,7 +38,16 @@ class UserCreds:
).decode()
return creds
@staticmethod
def get_from_dict_server_config(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)
return UserCreds.get_from_dict(cred_dict)
return UserCreds.get_from_dict_new_registration(cred_dict)