From 15c0c731e9e7bfc6b8d4f795dc03f41345f181d1 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Mon, 3 Feb 2020 15:24:31 +0000 Subject: [PATCH] Saving mixnode's config on init --- mixnode/src/commands/init.rs | 28 ++++++++++++++++++++++++++-- mixnode/src/config/mod.rs | 17 +++++++++++++++++ mixnode/src/main.rs | 1 + 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/mixnode/src/commands/init.rs b/mixnode/src/commands/init.rs index 0b06f75d05..6b42e22025 100644 --- a/mixnode/src/commands/init.rs +++ b/mixnode/src/commands/init.rs @@ -1,5 +1,29 @@ -use clap::{App, Arg}; +use clap::{App, Arg, ArgMatches}; +use config::NymConfig; pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { - App::new("init").about("Initialise the mixnode") + App::new("init").about("Initialise the mixnode").arg( + Arg::with_name("id") + .long("id") + .help("Id of the nym-mixnode we want to create config for.") + .takes_value(true) + .required(true), + ) +} + +pub fn execute(matches: &ArgMatches) { + println!("Initialising mixnode..."); + + let id = matches.value_of("id").unwrap(); // required for now + let mut config = crate::config::Config::new(id); + + // overriding config defaults here + + let config_save_location = config.get_config_file_save_location(); + config + .save_to_file(None) + .expect("Failed to save the config file"); + println!("Saved configuration file to {:?}", config_save_location); + + println!("Mixnode configuration completed.\n\n\n") } diff --git a/mixnode/src/config/mod.rs b/mixnode/src/config/mod.rs index 35fefb5473..21d5234ce2 100644 --- a/mixnode/src/config/mod.rs +++ b/mixnode/src/config/mod.rs @@ -75,6 +75,23 @@ impl Config { self.mixnode.id = id; self } + + // getters + pub fn get_config_file_save_location(&self) -> PathBuf { + self.config_directory().join(Self::config_file_name()) + } + + pub fn get_private_identity_key_file(&self) -> PathBuf { + self.mixnode.private_identity_key_file.clone() + } + + pub fn get_public_identity_key_file(&self) -> PathBuf { + self.mixnode.public_identity_key_file.clone() + } + + pub fn get_directory_server(&self) -> String { + self.mixnode.directory_server.clone() + } } #[derive(Debug, Deserialize, PartialEq, Serialize)] diff --git a/mixnode/src/main.rs b/mixnode/src/main.rs index 4e80538187..4541f60850 100644 --- a/mixnode/src/main.rs +++ b/mixnode/src/main.rs @@ -27,6 +27,7 @@ fn main() { fn execute(matches: ArgMatches) { match matches.subcommand() { + ("init", Some(m)) => commands::init::execute(m), ("run", Some(m)) => node::runner::start(m), _ => println!("{}", usage()), }