mirror of https://github.com/nucypher/nucypher.git
Additional work letting cli command fallback on Nocdeconfiguration defaults
parent
0c4db097ee
commit
a8b931ad33
48
cli/main.py
48
cli/main.py
|
@ -92,7 +92,8 @@ class NucypherClickConfig:
|
|||
"""Initialize contract agency and set them on config"""
|
||||
|
||||
if simulation is True:
|
||||
self.blockchain.interface._registry._swap_registry(filepath=self.sim_registry_filepath) # TODO: Public API for mirroring existing registry
|
||||
# TODO: Public API for mirroring existing registry
|
||||
self.blockchain.interface._registry._swap_registry(filepath=self.sim_registry_filepath)
|
||||
|
||||
self.token_agent = NucypherTokenAgent(blockchain=self.blockchain)
|
||||
self.miner_agent = MinerAgent(token_agent=self.token_agent)
|
||||
|
@ -133,15 +134,18 @@ def cli(config, verbose, version, config_file):
|
|||
def configure(config, action, config_file, config_root, temp):
|
||||
"""Manage the nucypher .ini configuration file"""
|
||||
|
||||
if temp:
|
||||
node_configuration = NodeConfiguration(temp=temp, auto_initialize=True)
|
||||
elif config_root:
|
||||
if config_root:
|
||||
node_configuration = NodeConfiguration(config_root=config_root)
|
||||
else:
|
||||
elif temp:
|
||||
node_configuration = NodeConfiguration(temp=temp, auto_initialize=True)
|
||||
elif config_file:
|
||||
click.echo("Using configuration file at: {}".format(config_file))
|
||||
node_configuration = NodeConfiguration.from_configuration_file(filepath=config_file)
|
||||
else:
|
||||
node_configuration = NodeConfiguration()
|
||||
|
||||
click.echo("Using configuration directory: {}".format(node_configuration.config_root))
|
||||
filepaths = node_configuration._generate_runtime_filepaths(commit=False)
|
||||
click.echo("Running in directory: {}".format(config_root or filepaths['config_root']))
|
||||
|
||||
def __destroy():
|
||||
click.confirm("Permanently destroy all nucypher configurations, known nodes, certificates and keys?", abort=True)
|
||||
|
@ -665,15 +669,15 @@ def status(config, provider, contracts, network):
|
|||
|
||||
|
||||
@cli.command()
|
||||
@click.option('--config-file', type=click.Path())
|
||||
@click.option('--federated-only', is_flag=True, default=False)
|
||||
@click.option('--dev', is_flag=True, default=False)
|
||||
@click.option('--rest-host', type=str, default='localhost')
|
||||
@click.option('--rest-port', type=int, default=UrsulaConfiguration.DEFAULT_REST_PORT)
|
||||
@click.option('--federated-only', is_flag=True)
|
||||
@click.option('--rest-host', type=str)
|
||||
@click.option('--rest-port', type=int)
|
||||
@click.option('--db-name', type=str)
|
||||
@click.option('--checksum-address', type=str)
|
||||
@click.option('--teacher-uri', type=str)
|
||||
@click.option('--metadata-dir', type=click.Path())
|
||||
@click.option('--config-file', type=click.Path())
|
||||
def run_ursula(rest_port,
|
||||
rest_host,
|
||||
db_name,
|
||||
|
@ -703,7 +707,7 @@ def run_ursula(rest_port,
|
|||
ursula_config = UrsulaConfiguration.from_configuration_file(filepath=config_file)
|
||||
else:
|
||||
ursula_config = UrsulaConfiguration(temp=temp,
|
||||
auto_initialize=temp,
|
||||
auto_initialize=dev,
|
||||
rest_host=rest_host,
|
||||
rest_port=rest_port,
|
||||
db_name=db_name,
|
||||
|
@ -719,27 +723,33 @@ def run_ursula(rest_port,
|
|||
ursula = ursula_config.produce()
|
||||
if teacher_uri:
|
||||
|
||||
# TODO: Validate and handle teacher URI paring here
|
||||
if 'http' not in teacher_uri:
|
||||
teacher_uri = 'https://'+teacher_uri
|
||||
url = urlparse(url=teacher_uri)
|
||||
host, port = url.hostname, url.port
|
||||
|
||||
teacher_config = UrsulaConfiguration(temp=True,
|
||||
auto_initialize=True,
|
||||
rest_host=host,
|
||||
rest_port=port,
|
||||
is_me=False,
|
||||
federated_only=federated_only,
|
||||
known_nodes=(ursula, ))
|
||||
teacher = teacher_config.produce()
|
||||
|
||||
# Know each other
|
||||
# ursula.remember_node(teacher)
|
||||
teacher_ursula = teacher_config.produce()
|
||||
|
||||
ursula.start_learning_loop() # Enter learning loop
|
||||
ursula.get_deployer().run() # Run TLS Deployer
|
||||
|
||||
if not federated_only:
|
||||
ursula.stake() # Start staking daemon
|
||||
try:
|
||||
ursula.start_learning_loop() # Enter learning loop
|
||||
ursula.get_deployer().run() # Run TLS Deployer (Reactor)
|
||||
if not federated_only: # TODO: Resume / Init
|
||||
ursula.stake() # Start staking daemon
|
||||
finally:
|
||||
# Cleanup
|
||||
if ursula_config.temp:
|
||||
click.echo("Cleaning up temporary runtime files and directories")
|
||||
ursula_config.cleanup()
|
||||
click.echo("Exited gracefully") # TODO: Integrate with other graceful shutdown functionality
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -394,9 +394,9 @@ class Ursula(Character, VerifiableNode, Miner):
|
|||
# Ursula
|
||||
rest_host,
|
||||
rest_port,
|
||||
certificate=None,
|
||||
certificate=None, # TODO: from_certificate classmethod instead, use only filepath..?
|
||||
certificate_filepath: str = None,
|
||||
db_name=None,
|
||||
db_name=None, # TODO: deprecate db_name, use only filepath.?
|
||||
db_filepath: str = None,
|
||||
is_me=True,
|
||||
interface_signature=None,
|
||||
|
@ -422,7 +422,8 @@ class Ursula(Character, VerifiableNode, Miner):
|
|||
|
||||
self._work_orders = []
|
||||
|
||||
Character.__init__(self, is_me=is_me,
|
||||
Character.__init__(self,
|
||||
is_me=is_me,
|
||||
checksum_address=checksum_address,
|
||||
always_be_learning=always_be_learning,
|
||||
federated_only=federated_only,
|
||||
|
@ -492,7 +493,7 @@ class Ursula(Character, VerifiableNode, Miner):
|
|||
# Unless the caller passed a crypto power, we'll make our own TLSHostingPower for this stranger.
|
||||
rest_server = ProxyRESTServer(
|
||||
rest_host=rest_host,
|
||||
rest_port=rest_port,
|
||||
rest_port=rest_port
|
||||
)
|
||||
if certificate or certificate_filepath:
|
||||
tls_hosting_power = TLSHostingPower(rest_server=rest_server,
|
||||
|
|
|
@ -5,10 +5,12 @@ from os.path import abspath
|
|||
from constant_sorrow import constants
|
||||
from cryptography.hazmat.primitives.asymmetric import ec
|
||||
from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurve
|
||||
from cryptography.x509 import Certificate
|
||||
|
||||
from nucypher.blockchain.eth.agents import EthereumContractAgent
|
||||
from nucypher.config.constants import DEFAULT_CONFIG_FILE_LOCATION
|
||||
from nucypher.config.node import NodeConfiguration
|
||||
from nucypher.crypto.powers import CryptoPower
|
||||
|
||||
|
||||
class UrsulaConfiguration(NodeConfiguration):
|
||||
|
|
Loading…
Reference in New Issue