forked from p15670423/monkey
Split `get_from_dict()` into 2 functions as per usage
This commit is contained in:
parent
d2083149dd
commit
02f3b15c64
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue