From 59920da8f5f2ce05fae2b3d3e21a6d8d73cf567e Mon Sep 17 00:00:00 2001 From: jstuczyn Date: Fri, 30 Oct 2020 10:55:39 +0000 Subject: [PATCH 1/2] Removed `--config` parameter in `run` commands --- clients/native/src/commands/run.rs | 9 +-------- clients/native/src/commands/upgrade.rs | 2 +- clients/socks5/src/commands/run.rs | 4 +--- clients/socks5/src/commands/upgrade.rs | 2 +- common/config/src/lib.rs | 17 ++--------------- gateway/src/commands/run.rs | 4 +--- gateway/src/commands/upgrade.rs | 2 +- mixnode/src/commands/run.rs | 10 +--------- mixnode/src/commands/upgrade.rs | 2 +- 9 files changed, 10 insertions(+), 42 deletions(-) diff --git a/clients/native/src/commands/run.rs b/clients/native/src/commands/run.rs index de577842057..84392b891c3 100644 --- a/clients/native/src/commands/run.rs +++ b/clients/native/src/commands/run.rs @@ -28,11 +28,6 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { .required(true) ) // the rest of arguments are optional, they are used to override settings in config file - .arg(Arg::with_name("config") - .long("config") - .help("Custom path to the nym-mixnet-client configuration file") - .takes_value(true) - ) .arg(Arg::with_name("directory") .long("directory") .help("Address of the directory server the client is getting topology from") @@ -69,9 +64,7 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { pub fn execute(matches: &ArgMatches) { let id = matches.value_of("id").unwrap(); - let mut config = - Config::load_from_file(matches.value_of("config").map(|path| path.into()), Some(id)) - .expect("Failed to load config file"); + let mut config = Config::load_from_file(id).expect("Failed to load config file"); config = override_config(config, matches); diff --git a/clients/native/src/commands/upgrade.rs b/clients/native/src/commands/upgrade.rs index 47802b1eab8..dca5c6038e5 100644 --- a/clients/native/src/commands/upgrade.rs +++ b/clients/native/src/commands/upgrade.rs @@ -129,7 +129,7 @@ pub fn execute(matches: &ArgMatches) { let id = matches.value_of("id").unwrap(); - let mut existing_config = Config::load_from_file(None, Some(id)).unwrap_or_else(|err| { + let mut existing_config = Config::load_from_file(id).unwrap_or_else(|err| { eprintln!("failed to load existing config file! - {:?}", err); process::exit(1) }); diff --git a/clients/socks5/src/commands/run.rs b/clients/socks5/src/commands/run.rs index 04f76a4d768..2ba67efebec 100644 --- a/clients/socks5/src/commands/run.rs +++ b/clients/socks5/src/commands/run.rs @@ -70,9 +70,7 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { pub fn execute(matches: &ArgMatches) { let id = matches.value_of("id").unwrap(); - let mut config = - Config::load_from_file(matches.value_of("config").map(|path| path.into()), Some(id)) - .expect("Failed to load config file"); + let mut config = Config::load_from_file(id).expect("Failed to load config file"); config = override_config(config, matches); diff --git a/clients/socks5/src/commands/upgrade.rs b/clients/socks5/src/commands/upgrade.rs index 3e70b0b3190..8415c521628 100644 --- a/clients/socks5/src/commands/upgrade.rs +++ b/clients/socks5/src/commands/upgrade.rs @@ -129,7 +129,7 @@ pub fn execute(matches: &ArgMatches) { let id = matches.value_of("id").unwrap(); - let mut existing_config = Config::load_from_file(None, Some(id)).unwrap_or_else(|err| { + let mut existing_config = Config::load_from_file(id).unwrap_or_else(|err| { eprintln!("failed to load existing config file! - {:?}", err); process::exit(1) }); diff --git a/common/config/src/lib.rs b/common/config/src/lib.rs index b6158d26723..7a5f1405b37 100644 --- a/common/config/src/lib.rs +++ b/common/config/src/lib.rs @@ -68,21 +68,8 @@ pub trait NymConfig: Default + Serialize + DeserializeOwned { ) } - // Hopefully should get simplified by https://github.com/nymtech/nym/issues/385 - // so that `custom_location` could be completely removed - fn load_from_file(custom_location: Option, id: Option<&str>) -> io::Result { - if custom_location.is_none() && id.is_none() { - return Err(io::Error::new( - io::ErrorKind::InvalidInput, - "Both custom location and id are unspecified!", - )); - } - - // unwrap on id can't fail as we just checked whether at least one of custom location or id - // is not None - let config_contents = fs::read_to_string( - custom_location.unwrap_or_else(|| Self::default_config_file_path(id.unwrap())), - )?; + fn load_from_file(id: &str) -> io::Result { + let config_contents = fs::read_to_string(Self::default_config_file_path(id))?; toml::from_str(&config_contents) .map_err(|toml_err| io::Error::new(io::ErrorKind::Other, toml_err)) diff --git a/gateway/src/commands/run.rs b/gateway/src/commands/run.rs index 89d2a22af35..d6cce43b9ee 100644 --- a/gateway/src/commands/run.rs +++ b/gateway/src/commands/run.rs @@ -157,9 +157,7 @@ pub fn execute(matches: &ArgMatches) { println!("Starting gateway {}...", id); - let mut config = - Config::load_from_file(matches.value_of("config").map(|path| path.into()), Some(id)) - .expect("Failed to load config file"); + let mut config = Config::load_from_file(id).expect("Failed to load config file"); config = override_config(config, matches); diff --git a/gateway/src/commands/upgrade.rs b/gateway/src/commands/upgrade.rs index 7ef4ba9253d..c736eea6537 100644 --- a/gateway/src/commands/upgrade.rs +++ b/gateway/src/commands/upgrade.rs @@ -127,7 +127,7 @@ pub fn execute(matches: &ArgMatches) { let id = matches.value_of("id").unwrap(); - let mut existing_config = Config::load_from_file(None, Some(id)).unwrap_or_else(|err| { + let mut existing_config = Config::load_from_file(id).unwrap_or_else(|err| { eprintln!("failed to load existing config file! - {:?}", err); process::exit(1) }); diff --git a/mixnode/src/commands/run.rs b/mixnode/src/commands/run.rs index c1159e1d267..9bf8ba390b5 100644 --- a/mixnode/src/commands/run.rs +++ b/mixnode/src/commands/run.rs @@ -36,12 +36,6 @@ pub fn command_args<'a, 'b>() -> App<'a, 'b> { .help("Optional geographical location of this node") .takes_value(true), ) - .arg( - Arg::with_name("config") - .long("config") - .help("Custom path to the nym-mixnode configuration file") - .takes_value(true), - ) .arg( Arg::with_name("layer") .long("layer") @@ -132,9 +126,7 @@ pub fn execute(matches: &ArgMatches) { println!("Starting mixnode {}...", id); - let mut config = - Config::load_from_file(matches.value_of("config").map(|path| path.into()), Some(id)) - .expect("Failed to load config file"); + let mut config = Config::load_from_file(id).expect("Failed to load config file"); config = override_config(config, matches); diff --git a/mixnode/src/commands/upgrade.rs b/mixnode/src/commands/upgrade.rs index 58faeab53fa..89c7374e8c6 100644 --- a/mixnode/src/commands/upgrade.rs +++ b/mixnode/src/commands/upgrade.rs @@ -164,7 +164,7 @@ pub fn execute(matches: &ArgMatches) { let id = matches.value_of("id").unwrap(); - let mut existing_config = Config::load_from_file(None, Some(id)).unwrap_or_else(|err| { + let mut existing_config = Config::load_from_file(id).unwrap_or_else(|err| { eprintln!("failed to load existing config file! - {:?}", err); process::exit(1) }); From bb0e7f8922650483f1443210132e612e6083ec4b Mon Sep 17 00:00:00 2001 From: jstuczyn Date: Fri, 30 Oct 2020 11:02:24 +0000 Subject: [PATCH 2/2] Removed old tests that were doing disk IO --- Cargo.lock | 4 ---- clients/native/Cargo.toml | 1 - clients/native/src/client/config/mod.rs | 20 -------------------- clients/socks5/Cargo.toml | 3 --- clients/socks5/src/client/config/mod.rs | 21 --------------------- gateway/Cargo.toml | 3 --- gateway/src/config/mod.rs | 20 -------------------- mixnode/Cargo.toml | 3 --- mixnode/src/config/mod.rs | 20 -------------------- 9 files changed, 95 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 98b497bf50a..d2f4f235cee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1549,7 +1549,6 @@ dependencies = [ "serde", "serde_json", "sled 0.33.0", - "tempfile", "tokio", "tokio-tungstenite", "topology", @@ -1602,7 +1601,6 @@ dependencies = [ "rand", "serde", "sled 0.31.0", - "tempfile", "tokio", "tokio-tungstenite", "tokio-util", @@ -1632,7 +1630,6 @@ dependencies = [ "pemstore", "pretty_env_logger", "serde", - "tempfile", "tokio", "tokio-util", "topology", @@ -1663,7 +1660,6 @@ dependencies = [ "serde", "snafu", "socks5-requests", - "tempfile", "tokio", "topology", "validator-client", diff --git a/clients/native/Cargo.toml b/clients/native/Cargo.toml index 90e899446d2..c0fd7e81da7 100644 --- a/clients/native/Cargo.toml +++ b/clients/native/Cargo.toml @@ -43,5 +43,4 @@ validator-client = { path = "../../common/client-libs/validator-client" } version-checker = { path = "../../common/version-checker" } [dev-dependencies] -tempfile = "3.1.0" serde_json = "1.0" # for the "textsend" example \ No newline at end of file diff --git a/clients/native/src/client/config/mod.rs b/clients/native/src/client/config/mod.rs index c16dc1c6b00..e86f4aa212a 100644 --- a/clients/native/src/client/config/mod.rs +++ b/clients/native/src/client/config/mod.rs @@ -132,23 +132,3 @@ impl Default for Socket { } } } - -#[cfg(test)] -mod client_config { - use super::*; - - #[test] - fn after_saving_default_config_the_loaded_one_is_identical() { - // need to figure out how to do something similar but without touching the disk - // or the file system at all... - let temp_location = tempfile::tempdir().unwrap().path().join("config.toml"); - let default_config = Config::new("foomp".to_string()); - default_config - .save_to_file(Some(temp_location.clone())) - .unwrap(); - - let loaded_config = Config::load_from_file(Some(temp_location), None).unwrap(); - - assert_eq!(default_config, loaded_config); - } -} diff --git a/clients/socks5/Cargo.toml b/clients/socks5/Cargo.toml index 19121cd5c65..bc994e95077 100644 --- a/clients/socks5/Cargo.toml +++ b/clients/socks5/Cargo.toml @@ -34,6 +34,3 @@ topology = { path = "../../common/topology" } proxy-helpers = { path = "../../common/socks5/proxy-helpers" } validator-client = { path = "../../common/client-libs/validator-client" } version-checker = { path = "../../common/version-checker" } - -[dev-dependencies] -tempfile = "3.1.0" \ No newline at end of file diff --git a/clients/socks5/src/client/config/mod.rs b/clients/socks5/src/client/config/mod.rs index 093588e2f37..705c7615f89 100644 --- a/clients/socks5/src/client/config/mod.rs +++ b/clients/socks5/src/client/config/mod.rs @@ -128,24 +128,3 @@ impl Default for Socks5 { } } } - -#[cfg(test)] -mod client_config { - use super::*; - - #[test] - fn after_saving_default_config_the_loaded_one_is_identical() { - // need to figure out how to do something similar but without touching the disk - // or the file system at all... - let temp_location = tempfile::tempdir().unwrap().path().join("config.toml"); - let fake_address = "CytBseW6yFXUMzz4SGAKdNLGR7q3sJLLYxyBGvutNEQV.4QXYyEVc5fUDjmmi8PrHN9tdUFV4PCvSJE1278cHyvoe@FioFa8nMmPpQnYi7JyojoTuwGLeyNS8BF4ChPr29zUML"; - let default_config = Config::new("foomp", fake_address); - default_config - .save_to_file(Some(temp_location.clone())) - .unwrap(); - - let loaded_config = Config::load_from_file(Some(temp_location), None).unwrap(); - - assert_eq!(default_config, loaded_config); - } -} diff --git a/gateway/Cargo.toml b/gateway/Cargo.toml index 488d8e279cd..a3450495953 100644 --- a/gateway/Cargo.toml +++ b/gateway/Cargo.toml @@ -37,6 +37,3 @@ version-checker = { path = "../common/version-checker" } [dependencies.tungstenite] version = "0.11" default-features = false - -[dev-dependencies] -tempfile = "3.1.0" \ No newline at end of file diff --git a/gateway/src/config/mod.rs b/gateway/src/config/mod.rs index 9d82fd8269a..a5ab1e96ebe 100644 --- a/gateway/src/config/mod.rs +++ b/gateway/src/config/mod.rs @@ -680,23 +680,3 @@ impl Default for Debug { } } } - -#[cfg(test)] -mod gateway_config { - use super::*; - - #[test] - fn after_saving_default_config_the_loaded_one_is_identical() { - // need to figure out how to do something similar but without touching the disk - // or the file system at all... - let temp_location = tempfile::tempdir().unwrap().path().join("config.toml"); - let default_config = Config::default().with_id("foomp".to_string()); - default_config - .save_to_file(Some(temp_location.clone())) - .unwrap(); - - let loaded_config = Config::load_from_file(Some(temp_location), None).unwrap(); - - assert_eq!(default_config, loaded_config); - } -} diff --git a/mixnode/Cargo.toml b/mixnode/Cargo.toml index bd55bd6da3c..5b72f61a005 100644 --- a/mixnode/Cargo.toml +++ b/mixnode/Cargo.toml @@ -31,6 +31,3 @@ pemstore = { path = "../common/pemstore" } topology = { path = "../common/topology" } validator-client = { path = "../common/client-libs/validator-client" } version-checker = { path = "../common/version-checker" } - -[dev-dependencies] -tempfile = "3.1.0" \ No newline at end of file diff --git a/mixnode/src/config/mod.rs b/mixnode/src/config/mod.rs index 78fa77df955..9af0c4f1133 100644 --- a/mixnode/src/config/mod.rs +++ b/mixnode/src/config/mod.rs @@ -522,23 +522,3 @@ impl Default for Debug { } } } - -#[cfg(test)] -mod mixnode_config { - use super::*; - - #[test] - fn after_saving_default_config_the_loaded_one_is_identical() { - // need to figure out how to do something similar but without touching the disk - // or the file system at all... - let temp_location = tempfile::tempdir().unwrap().path().join("config.toml"); - let default_config = Config::default().with_id("foomp".to_string()); - default_config - .save_to_file(Some(temp_location.clone())) - .unwrap(); - - let loaded_config = Config::load_from_file(Some(temp_location), None).unwrap(); - - assert_eq!(default_config, loaded_config); - } -}