From 3b9e75634aa06b6df0519e5d44fd6e5281712d09 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sat, 25 Dec 2021 19:19:19 +0100 Subject: Allow Diplonat to automatically detect it's private IP --- src/config/options.rs | 4 +++- src/config/runtime.rs | 10 ++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/config') diff --git a/src/config/options.rs b/src/config/options.rs index b8dccf7..f62d14c 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -62,7 +62,9 @@ impl ConfigOpts { // Currently only used in tests #[allow(dead_code)] pub fn from_iter(iter: Iter) -> Result - where Iter: IntoIterator { + where + Iter: IntoIterator, + { let base: ConfigOptsBase = envy::prefixed("DIPLONAT_").from_iter(iter.clone())?; let consul: ConfigOptsConsul = envy::prefixed("DIPLONAT_CONSUL_").from_iter(iter.clone())?; let acme: ConfigOptsAcme = envy::prefixed("DIPLONAT_ACME_").from_iter(iter.clone())?; diff --git a/src/config/runtime.rs b/src/config/runtime.rs index eeb34f6..a1582e4 100644 --- a/src/config/runtime.rs +++ b/src/config/runtime.rs @@ -27,7 +27,7 @@ pub struct RuntimeConfigFirewall { #[derive(Debug)] pub struct RuntimeConfigIgd { - pub private_ip: String, + pub private_ip: Option, pub expiration_time: Duration, pub refresh_time: Duration, } @@ -59,7 +59,7 @@ impl RuntimeConfig { impl RuntimeConfigAcme { pub fn new(opts: ConfigOptsAcme) -> Result> { if !opts.enable { - return Ok(None) + return Ok(None); } let email = opts.email.expect( @@ -91,9 +91,7 @@ impl RuntimeConfigFirewall { impl RuntimeConfigIgd { pub(super) fn new(opts: ConfigOptsBase) -> Result { - let private_ip = opts - .private_ip - .expect("'DIPLONAT_PRIVATE_IP' environment variable is required"); + let private_ip = opts.private_ip; let expiration_time = Duration::from_secs( opts .expiration_time @@ -108,7 +106,7 @@ impl RuntimeConfigIgd { (currently: {}s)", expiration_time.as_secs(), refresh_time.as_secs() - )) + )); } Ok(Self { -- cgit v1.2.3