From a552202a6534e63990e448b88e713572ca696775 Mon Sep 17 00:00:00 2001 From: James McMurray Date: Fri, 22 Mar 2024 21:22:37 +0100 Subject: [PATCH] Fix network interface parsing from config file --- Cargo.toml | 2 +- src/args_config.rs | 19 ++++++++++++++++--- src/list.rs | 6 ++---- vopono_core/Cargo.toml | 4 ++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4cfef28..4cfc540 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 "] edition = "2021" license = "GPL-3.0-or-later" diff --git a/src/args_config.rs b/src/args_config.rs index 876f84a..1f440ce 100644 --- a/src/args_config.rs +++ b/src/args_config.rs @@ -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") @@ -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::::Ok(x), diff --git a/src/list.rs b/src/list.rs index 3855cdd..5240862 100644 --- a/src/list.rs +++ b/src/list.rs @@ -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 = DateTime::from_naive_utc_and_offset(naive, Utc); let diff = now - datetime; println!( "{}\t{}\t{}\t{}\t{}", @@ -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 = DateTime::from_naive_utc_and_offset(naive, Utc); let diff = now - datetime; println!( "{}\t{}\t{}\t{}\t{}", diff --git a/vopono_core/Cargo.toml b/vopono_core/Cargo.toml index 7abe156..99403e8 100644 --- a/vopono_core/Cargo.toml +++ b/vopono_core/Cargo.toml @@ -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 "] license = "GPL-3.0-or-later" @@ -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",