def create_character(self, emitter, config_file, debug): felix_config = self.config_options.create_config(emitter, config_file) try: # Authenticate unlock_nucypher_keyring( emitter, character_configuration=felix_config, password=get_nucypher_password(confirm=False)) client_password = get_client_password( checksum_address=felix_config.checksum_address, envvar=NUCYPHER_ENVVAR_WORKER_ETH_PASSWORD) # Produce Felix FELIX = felix_config.produce(domain=self.config_options.domain, client_password=client_password) FELIX.make_web_app( ) # attach web application, but dont start service return FELIX except Exception as e: if debug: raise else: emitter.echo(str(e), color='red', bold=True) raise click.Abort
def make_cli_character(character_config, emitter, unlock_keystore: bool = True, unlock_signer: bool = True, teacher_uri: str = None, min_stake: int = 0, json_ipc: bool = False, **config_args ) -> Character: # # Pre-Init # # Handle KEYSTORE if unlock_keystore: unlock_nucypher_keystore(emitter, character_configuration=character_config, password=get_nucypher_password(emitter=emitter, confirm=False)) # Handle Signer/Wallet if unlock_signer: unlock_signer_account(config=character_config, json_ipc=json_ipc) # Handle Teachers # TODO: Is this still relevant? Is it better to DRY this up by doing it later? sage_nodes = list() # # Character Init # # Produce Character if teacher_uri: maybe_sage_node = character_config.known_node_class.from_teacher_uri( teacher_uri=teacher_uri, min_stake=min_stake, federated_only=character_config.federated_only, network_middleware=character_config.network_middleware, registry=character_config.registry ) sage_nodes.append(maybe_sage_node) CHARACTER = character_config(known_nodes=sage_nodes, network_middleware=character_config.network_middleware, **config_args) # # Post-Init # if CHARACTER.controller is not NO_CONTROL_PROTOCOL: CHARACTER.controller.emitter = emitter # Federated if character_config.federated_only: emitter.message(FEDERATED_WARNING, color='yellow') emitter.message(f"Loaded {CHARACTER.__class__.__name__} {CHARACTER.checksum_address} ({CHARACTER.domain})", color='green') return CHARACTER
def generate_config(self, emitter: StdoutEmitter, config_root: str) -> AliceConfiguration: opts = self.config_options if opts.dev: raise click.BadArgumentUsage("Cannot create a persistent development character") if not opts.provider_uri and not opts.federated_only: raise click.BadOptionUsage( option_name='--provider', message="--provider is required to create a new decentralized alice.") pay_with = opts.pay_with if not pay_with and not opts.federated_only: pay_with = select_client_account(emitter=emitter, provider_uri=opts.provider_uri, signer_uri=opts.signer_uri, show_eth_balance=True, network=opts.domain) return AliceConfiguration.generate( password=get_nucypher_password(confirm=True), config_root=config_root, checksum_address=pay_with, domain=opts.domain, federated_only=opts.federated_only, provider_uri=opts.provider_uri, signer_uri=opts.signer_uri, registry_filepath=opts.registry_filepath, poa=self.poa, light=self.light, m=self.m, n=self.n, duration_periods=self.duration_periods)
def make_cli_character( character_config, emitter, unlock_keyring: bool = True, teacher_uri: str = None, min_stake: int = 0, # We not using this anymore? Where is it hooked up? **config_args ) -> Character: # # Pre-Init # # Handle Keyring if unlock_keyring: unlock_nucypher_keyring(emitter, character_configuration=character_config, password=get_nucypher_password(confirm=False)) # Handle Teachers # TODO: Is this still relevant? Is it better to DRY this up by doing it later? sage_nodes = list() # # Character Init # # Produce Character if teacher_uri: maybe_sage_node = character_config.known_node_class.from_teacher_uri( teacher_uri=teacher_uri, min_stake=0, # TODO: Where to get this? federated_only=character_config.federated_only, network_middleware=character_config.network_middleware, registry=character_config.registry) sage_nodes.append(maybe_sage_node) CHARACTER = character_config( known_nodes=sage_nodes, network_middleware=character_config.network_middleware, **config_args) # # Post-Init # if CHARACTER.controller is not NO_CONTROL_PROTOCOL: CHARACTER.controller.emitter = emitter # TODO: set it on object creation? Or not set at all? # Federated if character_config.federated_only: emitter.message(FEDERATED_WARNING, color='yellow') emitter.message( f"Loaded {CHARACTER.__class__.__name__} {CHARACTER.checksum_address} ({CHARACTER.domain})", color='green') return CHARACTER
def test_get_nucypher_password(mock_stdin, mock_account, confirm, capsys): mock_stdin.password(INSECURE_DEVELOPMENT_PASSWORD, confirm=confirm) result = get_nucypher_password(confirm=confirm) assert result == INSECURE_DEVELOPMENT_PASSWORD assert mock_stdin.empty() captured = capsys.readouterr() assert COLLECT_NUCYPHER_PASSWORD in captured.out if confirm: prompt = COLLECT_NUCYPHER_PASSWORD + f" ({NucypherKeyring.MINIMUM_PASSWORD_LENGTH} character minimum)" assert prompt in captured.out
def generate_config(self, config_root, discovery_port): return FelixConfiguration.generate( password=get_nucypher_password(confirm=True), config_root=config_root, rest_host=self.host, rest_port=discovery_port, db_filepath=self.db_filepath, domain=self.domain, checksum_address=self.checksum_address, registry_filepath=self.registry_filepath, provider_uri=self.provider_uri, signer_uri=self.signer_uri, poa=self.poa)
def make_cli_character(character_config, emitter, unlock_keyring: bool = True, teacher_uri: str = None, min_stake: int = 0, load_preferred_teachers: bool = True, **config_args) -> Character: # # Pre-Init # # Handle Keyring if unlock_keyring: unlock_nucypher_keyring(emitter, character_configuration=character_config, password=get_nucypher_password(confirm=False)) # Handle Teachers teacher_nodes = list() if load_preferred_teachers: teacher_nodes = load_seednodes(emitter, teacher_uris=[teacher_uri] if teacher_uri else None, min_stake=min_stake, federated_only=character_config.federated_only, network_domains=character_config.domains, network_middleware=character_config.network_middleware, registry=character_config.registry) # # Character Init # # Produce Character CHARACTER = character_config(known_nodes=teacher_nodes, network_middleware=character_config.network_middleware, **config_args) # # Post-Init # if CHARACTER.controller is not NO_CONTROL_PROTOCOL: CHARACTER.controller.emitter = emitter # TODO: set it on object creation? Or not set at all? # Federated if character_config.federated_only: emitter.message(FEDERATED_WARNING, color='yellow') return CHARACTER
def generate_config(self, emitter: StdoutEmitter, config_root: Path, key_material: str) -> AliceConfiguration: opts = self.config_options if opts.dev: raise click.BadArgumentUsage( "Cannot create a persistent development character") if not opts.eth_provider_uri and not opts.federated_only: raise click.BadOptionUsage( option_name='--eth-provider', message=click.style( "--eth-provider is required to create a new decentralized alice.", fg="red")) pay_with = opts.pay_with if not pay_with and not opts.federated_only: pay_with = select_client_account( emitter=emitter, eth_provider_uri=opts.eth_provider_uri, signer_uri=opts.signer_uri, show_eth_balance=True, network=opts.domain) return AliceConfiguration.generate( password=get_nucypher_password(emitter=emitter, confirm=True), key_material=bytes.fromhex(key_material) if key_material else None, config_root=config_root, checksum_address=pay_with, domain=opts.domain, federated_only=opts.federated_only, eth_provider_uri=opts.eth_provider_uri, signer_uri=opts.signer_uri, registry_filepath=opts.registry_filepath, poa=self.poa, light=self.light, threshold=self.threshold, shares=self.shares, duration=self.duration, payment_provider=opts.payment_provider, payment_network=opts.payment_network, payment_method=opts.payment_method, )
def generate_config(self, emitter, config_root, force, key_material): if self.dev: raise RuntimeError( 'Persistent configurations cannot be created in development mode.' ) if (not self.operator_address) and not self.federated_only: prompt = "Select operator account" self.operator_address = select_client_account( emitter=emitter, prompt=prompt, eth_provider_uri=self.eth_provider_uri, signer_uri=self.signer_uri) # Resolve rest host if not self.rest_host: self.rest_host = collect_operator_ip_address(emitter, network=self.domain, force=force) return UrsulaConfiguration.generate( password=get_nucypher_password(emitter=emitter, confirm=True), key_material=bytes.fromhex(key_material) if key_material else None, config_root=config_root, rest_host=self.rest_host, rest_port=self.rest_port, db_filepath=self.db_filepath, domain=self.domain, federated_only=self.federated_only, operator_address=self.operator_address, registry_filepath=self.registry_filepath, policy_registry_filepath=self.policy_registry_filepath, eth_provider_uri=self.eth_provider_uri, signer_uri=self.signer_uri, gas_strategy=self.gas_strategy, max_gas_price=self.max_gas_price, poa=self.poa, light=self.light, availability_check=self.availability_check, payment_method=self.payment_method, payment_provider=self.payment_provider, payment_network=self.payment_network)
def generate_config(self, emitter: StdoutEmitter, config_root: str) -> BobConfiguration: checksum_address = self.checksum_address if not checksum_address and not self.federated_only: checksum_address = select_client_account(emitter=emitter, signer_uri=self.signer_uri, provider_uri=self.provider_uri) # TODO: See #1888 return BobConfiguration.generate( password=get_nucypher_password(confirm=True), config_root=config_root, checksum_address=checksum_address, domains=self.domains, federated_only=self.federated_only, registry_filepath=self.registry_filepath, provider_uri=self.provider_uri, signer_uri=self.signer_uri, gas_strategy=self.gas_strategy, )
def generate_config(self, emitter, config_root, force): if self.dev: raise RuntimeError( 'Persistent configurations cannot be created in development mode.' ) worker_address = self.worker_address if (not worker_address) and not self.federated_only: if not worker_address: prompt = "Select worker account" worker_address = select_client_account( emitter=emitter, prompt=prompt, provider_uri=self.provider_uri, signer_uri=self.signer_uri) rest_host = self.rest_host if not rest_host: rest_host = os.environ.get(NUCYPHER_ENVVAR_WORKER_IP_ADDRESS) if not rest_host: # TODO: Something less centralized... :-( # TODO: Ask Ursulas instead rest_host = determine_external_ip_address(emitter, force=force) return UrsulaConfiguration.generate( password=get_nucypher_password(confirm=True), config_root=config_root, rest_host=rest_host, rest_port=self.rest_port, db_filepath=self.db_filepath, domains=self.domains, federated_only=self.federated_only, worker_address=worker_address, registry_filepath=self.registry_filepath, provider_process=self.eth_node, provider_uri=self.provider_uri, signer_uri=self.signer_uri, gas_strategy=self.gas_strategy, poa=self.poa, light=self.light, availability_check=self.availability_check)
def generate_config(self, emitter, config_root, force): if self.dev: raise RuntimeError( 'Persistent configurations cannot be created in development mode.' ) worker_address = self.worker_address if (not worker_address) and not self.federated_only: if not worker_address: prompt = "Select worker account" worker_address = select_client_account( emitter=emitter, prompt=prompt, provider_uri=self.provider_uri, signer_uri=self.signer_uri) # Resolve rest host if not self.rest_host: self.rest_host = collect_worker_ip_address(emitter, network=self.domain, force=force) return UrsulaConfiguration.generate( password=get_nucypher_password(confirm=True), config_root=config_root, rest_host=self.rest_host, rest_port=self.rest_port, db_filepath=self.db_filepath, domain=self.domain, federated_only=self.federated_only, worker_address=worker_address, registry_filepath=self.registry_filepath, provider_uri=self.provider_uri, signer_uri=self.signer_uri, gas_strategy=self.gas_strategy, max_gas_price=self.max_gas_price, poa=self.poa, light=self.light, availability_check=self.availability_check)
def generate_config(self, emitter: StdoutEmitter, config_root: Path, key_material: str) -> BobConfiguration: checksum_address = self.checksum_address if not checksum_address and not self.federated_only: checksum_address = select_client_account( emitter=emitter, signer_uri=self.signer_uri, provider_uri=self.provider_uri) # TODO: See #1888 return BobConfiguration.generate( password=get_nucypher_password(emitter=emitter, confirm=True), key_material=bytes.fromhex(key_material) if key_material else None, config_root=config_root, checksum_address=checksum_address, domain=self.domain, federated_only=self.federated_only, registry_filepath=self.registry_filepath, provider_uri=self.provider_uri, signer_uri=self.signer_uri, gas_strategy=self.gas_strategy, max_gas_price=self.max_gas_price, lonely=self.lonely)