mirror of https://github.com/nucypher/nucypher.git
Update ursula recover to update keystore path entry in existing ursula configuration file.
Co-authored-by: KPrasch <kieranprasch@gmail.com>pull/3554/head
parent
680cd0129e
commit
8ff2c9e6b3
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import click
|
||||
from constant_sorrow.constants import NO_PASSWORD
|
||||
|
@ -80,7 +81,7 @@ def unlock_nucypher_keystore(emitter: StdoutEmitter, password: str, character_co
|
|||
return True
|
||||
|
||||
|
||||
def recover_keystore(emitter) -> None:
|
||||
def recover_keystore(emitter) -> Path:
|
||||
emitter.message('This procedure will recover your nucypher keystore from mnemonic seed words. '
|
||||
'You will need to provide the entire mnemonic (space seperated) in the correct '
|
||||
'order and choose a new password.', color='cyan')
|
||||
|
@ -92,3 +93,5 @@ def recover_keystore(emitter) -> None:
|
|||
__password = get_nucypher_password(emitter=emitter, confirm=True)
|
||||
keystore = Keystore.restore(words=__words, password=__password)
|
||||
emitter.message(f'Recovered nucypher keystore {keystore.id} to \n {keystore.keystore_path}', color='green')
|
||||
|
||||
return keystore.keystore_path
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import click
|
||||
|
@ -53,6 +54,7 @@ from nucypher.cli.types import EIP55_CHECKSUM_ADDRESS, NETWORK_PORT, OPERATOR_IP
|
|||
from nucypher.cli.utils import make_cli_character, setup_emitter
|
||||
from nucypher.config.characters import UrsulaConfiguration
|
||||
from nucypher.config.constants import (
|
||||
DEFAULT_CONFIG_ROOT,
|
||||
NUCYPHER_ENVVAR_OPERATOR_ETH_PASSWORD,
|
||||
TEMPORARY_DOMAIN_NAME,
|
||||
)
|
||||
|
@ -382,11 +384,30 @@ def init(general_config, config_options, force, config_root, key_material):
|
|||
@ursula.command()
|
||||
@group_config_options
|
||||
@group_general_config
|
||||
def recover(general_config, config_options):
|
||||
@option_config_file
|
||||
def recover(general_config, config_options, config_file):
|
||||
# TODO: Combine with work in PR #2682
|
||||
# TODO: Integrate regeneration of configuration files
|
||||
emitter = setup_emitter(general_config, config_options.operator_address)
|
||||
recover_keystore(emitter=emitter)
|
||||
|
||||
new_keystore_path = recover_keystore(emitter=emitter)
|
||||
|
||||
# update/create ursula config
|
||||
ursula_config_file = config_file or DEFAULT_CONFIG_ROOT / "ursula.json"
|
||||
if not ursula_config_file.exists():
|
||||
emitter.error(
|
||||
f"Ursula configuration file not found - {ursula_config_file.absolute()}"
|
||||
)
|
||||
click.Abort()
|
||||
|
||||
with open(ursula_config_file, "r+") as f:
|
||||
ursula_config = json.load(f)
|
||||
ursula_config["keystore_path"] = str(new_keystore_path.absolute())
|
||||
f.seek(0)
|
||||
json.dump(ursula_config, f, indent=2)
|
||||
|
||||
emitter.echo(
|
||||
f"Updated ursula.json to use keystore filepath: {new_keystore_path.absolute()}"
|
||||
)
|
||||
|
||||
|
||||
@ursula.command()
|
||||
|
|
Loading…
Reference in New Issue