def verify_or_create_private_keys(ctx: Context) -> None: """ Verify or create private keys. :param ctx: Context """ path = Path(DEFAULT_AEA_CONFIG_FILE) agent_loader = ConfigLoader("aea-config_schema.json", AgentConfig) fp = path.open(mode="r", encoding="utf-8") aea_conf = agent_loader.load(fp) for identifier, _value in aea_conf.private_key_paths.read_all(): if identifier not in registry.supported_crypto_ids: ValueError("Unsupported identifier in private key paths.") for identifier, private_key_path in IDENTIFIER_TO_KEY_FILES.items(): config_private_key_path = aea_conf.private_key_paths.read(identifier) if config_private_key_path is None: create_private_key(identifier) aea_conf.private_key_paths.update(identifier, private_key_path) else: try: _try_validate_private_key_path(identifier, private_key_path) except FileNotFoundError: # pragma: no cover raise click.ClickException( "File {} for private key {} not found.".format( repr(private_key_path), identifier, ) ) # update aea config path = Path(DEFAULT_AEA_CONFIG_FILE) fp = path.open(mode="w", encoding="utf-8") agent_loader.dump(aea_conf, fp) ctx.agent_config = aea_conf
def _verify_or_create_private_keys(aea_project_path: Path) -> None: """Verify or create private keys.""" path_to_configuration = aea_project_path / DEFAULT_AEA_CONFIG_FILE agent_loader = ConfigLoader("aea-config_schema.json", AgentConfig) fp_read = path_to_configuration.open(mode="r", encoding="utf-8") agent_configuration = agent_loader.load(fp_read) for identifier, _value in agent_configuration.private_key_paths.read_all(): if identifier not in SUPPORTED_CRYPTOS: ValueError("Unsupported identifier in private key paths.") fetchai_private_key_path = agent_configuration.private_key_paths.read(FETCHAI) if fetchai_private_key_path is None: _create_fetchai_private_key( private_key_file=str(aea_project_path / FETCHAI_PRIVATE_KEY_FILE) ) agent_configuration.private_key_paths.update(FETCHAI, FETCHAI_PRIVATE_KEY_FILE) else: try: _try_validate_fet_private_key_path( str(aea_project_path / fetchai_private_key_path), exit_on_error=False ) except FileNotFoundError: # pragma: no cover logger.error( "File {} for private key {} not found.".format( repr(fetchai_private_key_path), FETCHAI, ) ) raise ethereum_private_key_path = agent_configuration.private_key_paths.read(ETHEREUM) if ethereum_private_key_path is None: _create_ethereum_private_key( private_key_file=str(aea_project_path / ETHEREUM_PRIVATE_KEY_FILE) ) agent_configuration.private_key_paths.update( ETHEREUM, ETHEREUM_PRIVATE_KEY_FILE ) else: try: _try_validate_ethereum_private_key_path( str(aea_project_path / ethereum_private_key_path), exit_on_error=False ) except FileNotFoundError: # pragma: no cover logger.error( "File {} for private key {} not found.".format( repr(ethereum_private_key_path), ETHEREUM, ) ) raise fp_write = path_to_configuration.open(mode="w", encoding="utf-8") agent_loader.dump(agent_configuration, fp_write)
def _verify_or_create_private_keys(ctx: Context) -> None: """ Verify or create private keys. :param ctx: Context """ path = Path(DEFAULT_AEA_CONFIG_FILE) agent_loader = ConfigLoader("aea-config_schema.json", AgentConfig) fp = path.open(mode="r", encoding="utf-8") aea_conf = agent_loader.load(fp) for identifier, _value in aea_conf.private_key_paths.read_all(): if identifier not in SUPPORTED_CRYPTOS: ValueError("Unsupported identifier in private key paths.") fetchai_private_key_path = aea_conf.private_key_paths.read(FETCHAI) if fetchai_private_key_path is None: _create_fetchai_private_key() aea_conf.private_key_paths.update(FETCHAI, FETCHAI_PRIVATE_KEY_FILE) else: try: _try_validate_fet_private_key_path(fetchai_private_key_path) except FileNotFoundError: # pragma: no cover logger.error("File {} for private key {} not found.".format( repr(fetchai_private_key_path), FETCHAI, )) sys.exit(1) ethereum_private_key_path = aea_conf.private_key_paths.read(ETHEREUM) if ethereum_private_key_path is None: _create_ethereum_private_key() aea_conf.private_key_paths.update(ETHEREUM, ETHEREUM_PRIVATE_KEY_FILE) else: try: _try_validate_ethereum_private_key_path(ethereum_private_key_path) except FileNotFoundError: # pragma: no cover logger.error("File {} for private key {} not found.".format( repr(ethereum_private_key_path), ETHEREUM, )) sys.exit(1) # update aea config path = Path(DEFAULT_AEA_CONFIG_FILE) fp = path.open(mode="w", encoding="utf-8") agent_loader.dump(aea_conf, fp) ctx.agent_config = aea_conf
def verify_or_create_private_keys( aea_project_path: Path, exit_on_error: bool = True, ) -> AgentConfig: """ Verify or create private keys. :param ctx: Context """ path_to_aea_config = aea_project_path / DEFAULT_AEA_CONFIG_FILE agent_loader = ConfigLoader("aea-config_schema.json", AgentConfig) fp = path_to_aea_config.open(mode="r", encoding="utf-8") aea_conf = agent_loader.load(fp) for identifier, _value in aea_conf.private_key_paths.read_all(): if identifier not in crypto_registry.supported_ids: # pragma: nocover ValueError("Unsupported identifier in private key paths.") for identifier, private_key_path in IDENTIFIER_TO_KEY_FILES.items(): config_private_key_path = aea_conf.private_key_paths.read(identifier) if config_private_key_path is None: if identifier == aea_conf.default_ledger: # pragma: nocover create_private_key( identifier, private_key_file=str(aea_project_path / private_key_path), ) aea_conf.private_key_paths.update(identifier, private_key_path) else: try: try_validate_private_key_path( identifier, str(aea_project_path / private_key_path), exit_on_error=exit_on_error, ) except FileNotFoundError: # pragma: no cover raise ValueError( "File {} for private key {} not found.".format( repr(private_key_path), identifier, )) # update aea config fp = path_to_aea_config.open(mode="w", encoding="utf-8") agent_loader.dump(aea_conf, fp) return aea_conf
def _verify_or_create_private_keys(ctx: Context) -> None: """ Verify or create private keys. :param ctx: Context """ path = Path(DEFAULT_AEA_CONFIG_FILE) agent_loader = ConfigLoader("aea-config_schema.json", AgentConfig) fp = open(str(path), mode="r", encoding="utf-8") aea_conf = agent_loader.load(fp) for identifier, value in aea_conf.private_key_paths.read_all(): if identifier not in SUPPORTED_CRYPTOS: ValueError("Unsupported identifier in private key paths.") default_private_key_config = aea_conf.private_key_paths.read(DEFAULT) if default_private_key_config is None: _create_default_private_key() default_private_key_config = PrivateKeyPathConfig( DEFAULT, DEFAULT_PRIVATE_KEY_FILE) aea_conf.private_key_paths.create(default_private_key_config.ledger, default_private_key_config) else: default_private_key_config = cast(PrivateKeyPathConfig, default_private_key_config) try: _try_validate_private_key_pem_path(default_private_key_config.path) except FileNotFoundError: logger.error("File {} for private key {} not found.".format( repr(default_private_key_config.path), default_private_key_config.ledger)) sys.exit(1) fetchai_private_key_config = aea_conf.private_key_paths.read(FETCHAI) if fetchai_private_key_config is None: _create_fetchai_private_key() fetchai_private_key_config = PrivateKeyPathConfig( FETCHAI, FETCHAI_PRIVATE_KEY_FILE) aea_conf.private_key_paths.create(fetchai_private_key_config.ledger, fetchai_private_key_config) else: fetchai_private_key_config = cast(PrivateKeyPathConfig, fetchai_private_key_config) try: _try_validate_fet_private_key_path(fetchai_private_key_config.path) except FileNotFoundError: logger.error("File {} for private key {} not found.".format( repr(fetchai_private_key_config.path), fetchai_private_key_config.ledger)) sys.exit(1) ethereum_private_key_config = aea_conf.private_key_paths.read(ETHEREUM) if ethereum_private_key_config is None: _create_ethereum_private_key() ethereum_private_key_config = PrivateKeyPathConfig( ETHEREUM, ETHEREUM_PRIVATE_KEY_FILE) aea_conf.private_key_paths.create(ethereum_private_key_config.ledger, ethereum_private_key_config) else: ethereum_private_key_config = cast(PrivateKeyPathConfig, ethereum_private_key_config) try: _try_validate_ethereum_private_key_path( ethereum_private_key_config.path) except FileNotFoundError: logger.error("File {} for private key {} not found.".format( repr(ethereum_private_key_config.path), ethereum_private_key_config.ledger)) sys.exit(1) # update aea config path = Path(DEFAULT_AEA_CONFIG_FILE) fp = open(str(path), mode="w", encoding="utf-8") agent_loader.dump(aea_conf, fp) ctx.agent_config = aea_conf