Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/no run config flag #405

Merged
merged 4 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion clients/native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 0 additions & 20 deletions clients/native/src/client/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
10 changes: 1 addition & 9 deletions clients/native/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,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")
Expand Down Expand Up @@ -90,10 +85,7 @@ fn version_check(cfg: &Config) -> bool {
pub fn execute(matches: &ArgMatches) {
let id = matches.value_of("id").unwrap();

let mut config = match Config::load_from_file(
matches.value_of("config").map(|path| path.into()),
Some(id),
) {
let mut config = match Config::load_from_file(id) {
Ok(cfg) => cfg,
Err(err) => {
error!("Failed to load config for {}. Are you sure you have run `init` before? (Error was: {})", id, err);
Expand Down
2 changes: 1 addition & 1 deletion clients/native/src/commands/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
Expand Down
3 changes: 0 additions & 3 deletions clients/socks5/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
21 changes: 0 additions & 21 deletions clients/socks5/src/client/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
5 changes: 1 addition & 4 deletions clients/socks5/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ fn version_check(cfg: &Config) -> bool {
pub fn execute(matches: &ArgMatches) {
let id = matches.value_of("id").unwrap();

let mut config = match Config::load_from_file(
matches.value_of("config").map(|path| path.into()),
Some(id),
) {
let mut config = match Config::load_from_file(id) {
Ok(cfg) => cfg,
Err(err) => {
error!("Failed to load config for {}. Are you sure you have run `init` before? (Error was: {})", id, err);
Expand Down
2 changes: 1 addition & 1 deletion clients/socks5/src/commands/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
Expand Down
17 changes: 2 additions & 15 deletions common/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>, id: Option<&str>) -> io::Result<Self> {
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<Self> {
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))
Expand Down
3 changes: 0 additions & 3 deletions gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,3 @@ version-checker = { path = "../common/version-checker" }
[dependencies.tungstenite]
version = "0.11"
default-features = false

[dev-dependencies]
tempfile = "3.1.0"
5 changes: 1 addition & 4 deletions gateway/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@ pub fn execute(matches: &ArgMatches) {

println!("Starting gateway {}...", id);

let mut config = match Config::load_from_file(
matches.value_of("config").map(|path| path.into()),
Some(id),
) {
let mut config = match Config::load_from_file(id) {
Ok(cfg) => cfg,
Err(err) => {
error!("Failed to load config for {}. Are you sure you have run `init` before? (Error was: {})", id, err);
Expand Down
2 changes: 1 addition & 1 deletion gateway/src/commands/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
Expand Down
20 changes: 0 additions & 20 deletions gateway/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
3 changes: 0 additions & 3 deletions mixnode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
11 changes: 1 addition & 10 deletions mixnode/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,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")
Expand Down Expand Up @@ -153,10 +147,7 @@ pub fn execute(matches: &ArgMatches) {

println!("Starting mixnode {}...", id);

let mut config = match Config::load_from_file(
matches.value_of("config").map(|path| path.into()),
Some(id),
) {
let mut config = match Config::load_from_file(id) {
Ok(cfg) => cfg,
Err(err) => {
error!("Failed to load config for {}. Are you sure you have run `init` before? (Error was: {})", id, err);
Expand Down
2 changes: 1 addition & 1 deletion mixnode/src/commands/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
Expand Down
20 changes: 0 additions & 20 deletions mixnode/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,23 +509,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);
}
}