def configure(config, action, config_file, config_root, temp, filesystem): """Manage the nucypher .ini configuration file""" def __destroy(configuration): if temp: raise NodeConfiguration.ConfigurationError("Cannot destroy a temporary node configuration") click.confirm("Permanently destroy all nucypher files, configurations, known nodes, certificates and keys?", abort=True) shutil.rmtree(configuration.config_root, ignore_errors=True) click.echo("Deleted configuration files at {}".format(node_configuration.config_root)) def __initialize(configuration): if temp: click.echo("Using temporary storage area") click.confirm("Initialize new nucypher configuration?", abort=True) configuration.write_defaults() click.echo("Created configuration files at {}".format(node_configuration.config_root)) if config_root: node_configuration = NodeConfiguration(temp=False, config_root=config_root, auto_initialize=False) elif temp: node_configuration = NodeConfiguration(temp=temp, auto_initialize=False) 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(auto_initialize=False) # Fully Default # # Action switch # if action == "init": __initialize(node_configuration) elif action == "destroy": __destroy(node_configuration) elif action == "reset": __destroy(node_configuration) __initialize(node_configuration) elif action == "validate": is_valid = True # Until there is a reason to believe otherwise try: if filesystem: # Check runtime directory is_valid = NodeConfiguration.check_config_tree_exists(config_root=node_configuration.config_root) if config_file: is_valid = validate_configuration_file(filepath=node_configuration.config_file_location) except NodeConfiguration.InvalidConfiguration: is_valid = False finally: result = 'Valid' if is_valid else 'Invalid' click.echo('{} is {}'.format(node_configuration.config_root, result))
def temp_config_root(temp_dir_path): """ User is responsible for closing the file given at the path. """ default_node_config = NodeConfiguration(dev_mode=True, config_root=temp_dir_path, import_seed_registry=False) yield default_node_config.config_root default_node_config.cleanup()
def temp_config_root(temp_dir_path): """ User is responsible for closing the file given at the path. """ default_node_config = NodeConfiguration(temp=True, auto_initialize=False, config_root=temp_dir_path) yield default_node_config.config_root default_node_config.cleanup()