From 6391941f83888e8e0ab6b06bfe225bbbba1da7a3 Mon Sep 17 00:00:00 2001 From: David Main <51991544+StriderDM@users.noreply.github.com> Date: Fri, 27 Aug 2021 08:57:20 +0200 Subject: [PATCH] feat: base_node prompt user to create id if not found (#3245) Description Prompt user to create id if not found Motivation and Context Improvement to base node startup, specifically on first run. How Has This Been Tested? Manually --- .../src/identity_management.rs | 29 ++++++++++++------- common/src/configuration/bootstrap.rs | 2 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/applications/tari_app_utilities/src/identity_management.rs b/applications/tari_app_utilities/src/identity_management.rs index df42bbe6cc..f526ecc75d 100644 --- a/applications/tari_app_utilities/src/identity_management.rs +++ b/applications/tari_app_utilities/src/identity_management.rs @@ -24,12 +24,14 @@ use crate::utilities::ExitCodes; use log::*; use rand::rngs::OsRng; use std::{clone::Clone, fs, path::Path, string::ToString, sync::Arc}; +use tari_common::configuration::bootstrap::prompt; use tari_comms::{multiaddr::Multiaddr, peer_manager::PeerFeatures, NodeIdentity}; use tari_core::transactions::types::PrivateKey; use tari_crypto::{ keys::SecretKey, tari_utilities::{hex::Hex, message_format::MessageFormat}, }; + pub const LOG_TARGET: &str = "tari_application"; /// Loads the node identity, or creates a new one if the --create-id flag was specified @@ -51,17 +53,22 @@ pub fn setup_node_identity>( Ok(id) => Ok(Arc::new(id)), Err(e) => { if !create_id { - error!( - target: LOG_TARGET, - "Node identity information not found. {}. You can update the configuration file to point to a \ - valid node identity file, or re-run the node with the --create-id flag to create a new identity.", - e - ); - return Err(ExitCodes::ConfigError(format!( - "Node identity information not found. {}. You can update the configuration file to point to a \ - valid node identity file, or re-run the node with the --create-id flag to create a new identity.", - e - ))); + let prompt = prompt("Node identity does not exist.\nWould you like to to create one (Y/n)?"); + if !prompt { + error!( + target: LOG_TARGET, + "Node identity information not found. {}. You can update the configuration file to point to a \ + valid node identity file, or re-run the node with the --create-id flag to create a new \ + identity.", + e + ); + return Err(ExitCodes::ConfigError(format!( + "Node identity information not found. {}. You can update the configuration file to point to a \ + valid node identity file, or re-run the node with the --create-id flag to create a new \ + identity.", + e + ))); + }; } debug!(target: LOG_TARGET, "Node id not found. {}. Creating new ID", e); diff --git a/common/src/configuration/bootstrap.rs b/common/src/configuration/bootstrap.rs index aee62a9cae..22c801b9fd 100644 --- a/common/src/configuration/bootstrap.rs +++ b/common/src/configuration/bootstrap.rs @@ -315,7 +315,7 @@ impl ConfigBootstrap { } } -fn prompt(question: &str) -> bool { +pub fn prompt(question: &str) -> bool { println!("{}", question); let mut input = "".to_string(); io::stdin().read_line(&mut input).unwrap();