def update_secure_config(cls, key, new_value): if new_value is None: return if encrypted_file_exists(key): unlink(encrypted_file_path(key)) encrypt_n_save_config_value(key, new_value, cls.password) cls._secure_configs[key] = new_value
async def save_to_yml(yml_path: str, cm: Dict[str, ConfigVar]): """ Write current config saved a single config map into each a single yml file """ try: with open(yml_path) as stream: data = yaml_parser.load(stream) or {} for key in cm: cvar = cm.get(key) if cvar.is_secure: if cvar.value is not None and not encrypted_config_file_exists( cvar): from hummingbot.client.config.in_memory_config_map import in_memory_config_map password = in_memory_config_map.get("password").value encrypt_n_save_config_value(cvar, password) if key in data: data.pop(key) elif type(cvar.value) == Decimal: data[key] = float(cvar.value) else: data[key] = cvar.value with open(yml_path, "w+") as outfile: yaml_parser.dump(data, outfile) except Exception as e: logging.getLogger().error("Error writing configs: %s" % (str(e), ), exc_info=True)
async def _encrypt_n_save_config_value(self, # type: HummingbotApplication cvar: ConfigVar): if in_memory_config_map.get("password").value is None: in_memory_config_map.get("password").value = await self._one_password_config() password = in_memory_config_map.get("password").value if encrypted_config_file_exists(cvar): unlink(get_encrypted_config_path(cvar)) encrypt_n_save_config_value(cvar, password)
def setUp(self): self._exit_stack: ExitStack = ExitStack() self._temp_folder: str = self._exit_stack.enter_context( tempfile.TemporaryDirectory()) settings.CONF_FILE_PATH = self._temp_folder global_config_map["key_file_path"].value = self._temp_folder encrypt_n_save_config_value("test_key_1", "test_value_1", "a") encrypt_n_save_config_value("test_key_2", "test_value_2", "a")
def setUp(self): settings.CONF_FILE_PATH = temp_folder global_config_map["key_file_path"].value = temp_folder os.makedirs(settings.CONF_FILE_PATH, exist_ok=False) encrypt_n_save_config_value("test_key_1", "test_value_1", "a") encrypt_n_save_config_value("test_key_2", "test_value_2", "a")