[#114] Add yaml configuration controllers

Signed-off-by: Andrey Berezin <a.berezin@yadro.com>
This commit is contained in:
Andrey Berezin 2023-11-10 22:43:13 +03:00 committed by Andrey Berezin
parent f8562da7e0
commit 72bd467c53
9 changed files with 244 additions and 22 deletions

View file

@ -120,6 +120,15 @@ class NodeBase(HumanReadableABC):
ConfigAttributes.WALLET_CONFIG,
)
@property
def config_dir(self) -> str:
return self._get_attribute(ConfigAttributes.CONFIG_DIR)
@property
def main_config_path(self) -> str:
return self._get_attribute(ConfigAttributes.CONFIG_PATH)
# TODO: Deprecated
def get_config(self, config_file_path: Optional[str] = None) -> tuple[str, dict]:
if config_file_path is None:
config_file_path = self._get_attribute(ConfigAttributes.CONFIG_PATH)
@ -132,6 +141,7 @@ class NodeBase(HumanReadableABC):
config = yaml.safe_load(config_text)
return config_file_path, config
# TODO: Deprecated
def save_config(self, new_config: dict, config_file_path: Optional[str] = None) -> None:
if config_file_path is None:
config_file_path = self._get_attribute(ConfigAttributes.CONFIG_PATH)
@ -146,9 +156,7 @@ class NodeBase(HumanReadableABC):
storage_wallet_pass = self.get_wallet_password()
return wallet_utils.get_wallet_public_key(storage_wallet_path, storage_wallet_pass)
def _get_attribute(
self, attribute_name: str, default_attribute_name: Optional[str] = None
) -> str:
def _get_attribute(self, attribute_name: str, default_attribute_name: Optional[str] = None) -> str:
config = self.host.get_service_config(self.name)
if attribute_name not in config.attributes: