aboutsummaryrefslogtreecommitdiff
path: root/src/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/config')
-rw-r--r--src/config/options_test.rs4
-rw-r--r--src/config/runtime.rs13
2 files changed, 11 insertions, 6 deletions
diff --git a/src/config/options_test.rs b/src/config/options_test.rs
index 655fb01..8e05c90 100644
--- a/src/config/options_test.rs
+++ b/src/config/options_test.rs
@@ -26,7 +26,7 @@ fn all_valid_options() -> HashMap<String, String> {
);
opts.insert(
"DIPLONAT_PRIVATE_IP".to_string(),
- "172.123.43.555".to_string(),
+ "172.123.43.55".to_string(),
);
opts.insert("DIPLONAT_REFRESH_TIME".to_string(), "10".to_string());
opts.insert(
@@ -118,7 +118,7 @@ fn ok_from_iter_all_valid_options() {
);
assert_eq!(rt_config.firewall.refresh_time, refresh_time);
assert_eq!(
- &rt_config.igd.private_ip.unwrap(),
+ &rt_config.igd.private_ip.unwrap().to_string(),
opts.get(&"DIPLONAT_PRIVATE_IP".to_string()).unwrap()
);
assert_eq!(rt_config.igd.expiration_time, expiration_time);
diff --git a/src/config/runtime.rs b/src/config/runtime.rs
index bffea52..45a29c3 100644
--- a/src/config/runtime.rs
+++ b/src/config/runtime.rs
@@ -1,9 +1,9 @@
use std::fs::File;
use std::io::Read;
-use std::net::{SocketAddr, ToSocketAddrs};
+use std::net::{Ipv4Addr, SocketAddr, ToSocketAddrs};
use std::time::Duration;
-use anyhow::{anyhow, bail, Result};
+use anyhow::{anyhow, bail, Context, Result};
use crate::config::{ConfigOpts, ConfigOptsAcme, ConfigOptsBase, ConfigOptsConsul};
@@ -31,7 +31,7 @@ pub struct RuntimeConfigFirewall {
#[derive(Debug)]
pub struct RuntimeConfigIgd {
- pub private_ip: Option<String>,
+ pub private_ip: Option<Ipv4Addr>,
pub expiration_time: Duration,
pub refresh_time: Duration,
}
@@ -137,7 +137,12 @@ impl RuntimeConfigFirewall {
impl RuntimeConfigIgd {
pub(super) fn new(opts: &ConfigOptsBase) -> Result<Self> {
- let private_ip = opts.private_ip.clone();
+ let private_ip = opts
+ .private_ip
+ .as_ref()
+ .map(|x| x.parse())
+ .transpose()
+ .context("parse private_ip")?;
let expiration_time = Duration::from_secs(
opts.expiration_time
.unwrap_or(super::EXPIRATION_TIME)