Skip to content

Commit

Permalink
Fix network interface parsing from config file
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmcm committed Mar 22, 2024
1 parent 1d5fc3f commit a552202
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "vopono"
description = "Launch applications via VPN tunnels using temporary network namespaces"
version = "0.10.9"
version = "0.10.10"
authors = ["James McMurray <jamesmcm03@gmail.com>"]
edition = "2021"
license = "GPL-3.0-or-later"
Expand Down
19 changes: 16 additions & 3 deletions src/args_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ macro_rules! command_else_config_option {
$config
.get(stringify!($field_id))
.or($config.get(&stringify!($field_id).replace('_', "-")))
.map_err(|_e| anyhow!("Failed to read config file"))
.map_err(|e| {
log::debug!("{:?}", e);
anyhow!("Failed to read config file")
})
.ok()
})
};
}

macro_rules! command_else_config_bool {
// Get bool ident from command - command.expr
// If None then read from Config .get("expr")
Expand Down Expand Up @@ -148,8 +152,17 @@ impl ArgsConfig {
}

// Assign network interface from args or vopono config file
// TODO: Does this work with string from config file?
let interface = command_else_config_option!(interface, command, config);
// Interface must be explicitly read as string
let interface = command.interface.or_else(|| {
config.get_string("interface").ok().and_then(|s| {
NetworkInterface::from_str(&s)
.map_err(|e| {
log::error!("Failed to parse interface from config file: {}", e);
anyhow!("Failed to parse interface from config file: {}", e)
})
.ok()
})
});

let interface: NetworkInterface = match interface {
Some(x) => anyhow::Result::<NetworkInterface>::Ok(x),
Expand Down
6 changes: 2 additions & 4 deletions src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ pub fn print_applications() -> anyhow::Result<()> {
let now = Utc::now();
for ns in keys {
for lock in namespaces.get(ns).unwrap() {
let naive = NaiveDateTime::from_timestamp_opt(lock.start as i64, 0)
let datetime = DateTime::from_timestamp(lock.start as i64, 0)
.ok_or_else(|| anyhow!("Timestamp parsing failed"))?;
let datetime: DateTime<Utc> = DateTime::from_naive_utc_and_offset(naive, Utc);
let diff = now - datetime;
println!(
"{}\t{}\t{}\t{}\t{}",
Expand Down Expand Up @@ -62,9 +61,8 @@ pub fn print_namespaces() -> anyhow::Result<()> {
.map(|x| x.start)
.min()
.unwrap();
let naive = NaiveDateTime::from_timestamp_opt(min_time as i64, 0)
let datetime = DateTime::from_timestamp(min_time as i64, 0)
.ok_or_else(|| anyhow!("Timestamp parsing failed"))?;
let datetime: DateTime<Utc> = DateTime::from_naive_utc_and_offset(naive, Utc);
let diff = now - datetime;
println!(
"{}\t{}\t{}\t{}\t{}",
Expand Down
4 changes: 2 additions & 2 deletions vopono_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "vopono_core"
description = "Library code for running VPN connections in network namespaces"
version = "0.1.9"
version = "0.1.10"
edition = "2021"
authors = ["James McMurray <jamesmcm03@gmail.com>"]
license = "GPL-3.0-or-later"
Expand All @@ -25,7 +25,7 @@ walkdir = "2"
rand = "0.8"
toml = "0.8"
ipnet = { version = "2", features = ["serde"] }
reqwest = { default-features = false, version = "0.11", features = [
reqwest = { default-features = false, version = "0.12", features = [
"blocking",
"json",
"rustls-tls",
Expand Down

0 comments on commit a552202

Please sign in to comment.