aboutsummaryrefslogtreecommitdiff
path: root/src/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/config')
-rw-r--r--src/config/options.rs4
-rw-r--r--src/config/options_test.rs16
-rw-r--r--src/config/runtime.rs10
3 files changed, 13 insertions, 17 deletions
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: Clone>(iter: Iter) -> Result<RuntimeConfig>
- where Iter: IntoIterator<Item = (String, String)> {
+ where
+ Iter: IntoIterator<Item = (String, String)>,
+ {
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/options_test.rs b/src/config/options_test.rs
index 790a14e..6b91235 100644
--- a/src/config/options_test.rs
+++ b/src/config/options_test.rs
@@ -11,10 +11,6 @@ use crate::config::*;
fn minimal_valid_options() -> HashMap<String, String> {
let mut opts = HashMap::new();
opts.insert(
- "DIPLONAT_PRIVATE_IP".to_string(),
- "172.123.43.555".to_string(),
- );
- opts.insert(
"DIPLONAT_CONSUL_NODE_NAME".to_string(),
"consul_node".to_string(),
);
@@ -24,6 +20,10 @@ fn minimal_valid_options() -> HashMap<String, String> {
fn all_valid_options() -> HashMap<String, String> {
let mut opts = minimal_valid_options();
opts.insert("DIPLONAT_EXPIRATION_TIME".to_string(), "30".to_string());
+ opts.insert(
+ "DIPLONAT_PRIVATE_IP".to_string(),
+ "172.123.43.555".to_string(),
+ );
opts.insert("DIPLONAT_REFRESH_TIME".to_string(), "10".to_string());
opts.insert(
"DIPLONAT_CONSUL_URL".to_string(),
@@ -40,7 +40,6 @@ fn all_valid_options() -> HashMap<String, String> {
#[test]
#[should_panic]
fn err_empty_env() {
- std::env::remove_var("DIPLONAT_PRIVATE_IP");
std::env::remove_var("DIPLONAT_CONSUL_NODE_NAME");
ConfigOpts::from_env().unwrap();
}
@@ -60,10 +59,7 @@ fn ok_from_iter_minimal_valid_options() {
rt_config.firewall.refresh_time,
Duration::from_secs(REFRESH_TIME.into())
);
- assert_eq!(
- &rt_config.igd.private_ip,
- opts.get(&"DIPLONAT_PRIVATE_IP".to_string()).unwrap()
- );
+ assert!(rt_config.igd.private_ip.is_none());
assert_eq!(
rt_config.igd.expiration_time,
Duration::from_secs(EXPIRATION_TIME.into())
@@ -120,7 +116,7 @@ fn ok_from_iter_all_valid_options() {
);
assert_eq!(rt_config.firewall.refresh_time, refresh_time);
assert_eq!(
- &rt_config.igd.private_ip,
+ &rt_config.igd.private_ip.unwrap(),
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 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<String>,
pub expiration_time: Duration,
pub refresh_time: Duration,
}
@@ -59,7 +59,7 @@ impl RuntimeConfig {
impl RuntimeConfigAcme {
pub fn new(opts: ConfigOptsAcme) -> Result<Option<Self>> {
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<Self> {
- 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 {