aboutsummaryrefslogtreecommitdiff
path: root/src/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/config')
-rw-r--r--src/config/options.rs7
-rw-r--r--src/config/runtime.rs15
2 files changed, 15 insertions, 7 deletions
diff --git a/src/config/options.rs b/src/config/options.rs
index a76cf57..27b1af1 100644
--- a/src/config/options.rs
+++ b/src/config/options.rs
@@ -9,7 +9,7 @@ use crate::config::RuntimeConfig;
// runtime.rs applies business logic and builds RuntimeConfig structs.
/// Base configuration options
-#[derive(Clone, Debug, Default, Deserialize)]
+#[derive(Clone, Default, Deserialize)]
pub struct ConfigOptsBase {
/// This node's private IP address [default: None]
pub private_ip: Option<String>,
@@ -20,7 +20,7 @@ pub struct ConfigOptsBase {
}
/// ACME configuration options
-#[derive(Clone, Debug, Default, Deserialize)]
+#[derive(Clone, Default, Deserialize)]
pub struct ConfigOptsAcme {
/// Whether ACME is enabled [default: false]
#[serde(default)]
@@ -31,7 +31,7 @@ pub struct ConfigOptsAcme {
}
/// Consul configuration options
-#[derive(Clone, Debug, Default, Deserialize)]
+#[derive(Clone, Default, Deserialize)]
pub struct ConfigOptsConsul {
/// Consul's node name [default: None]
pub node_name: Option<String>,
@@ -40,7 +40,6 @@ pub struct ConfigOptsConsul {
}
/// Model of all potential configuration options
-#[derive(Debug)]
pub struct ConfigOpts {
pub base: ConfigOptsBase,
pub acme: ConfigOptsAcme,
diff --git a/src/config/runtime.rs b/src/config/runtime.rs
index 6649d39..58c86b9 100644
--- a/src/config/runtime.rs
+++ b/src/config/runtime.rs
@@ -9,25 +9,30 @@ use crate::config::{ConfigOpts, ConfigOptsAcme, ConfigOptsBase, ConfigOptsConsul
// In this file, we take ConfigOpts and transform them into ready-to-use RuntimeConfig.
// We apply default values and business logic.
+#[derive(Debug)]
pub struct RuntimeConfigAcme {
pub email: String,
}
+#[derive(Debug)]
pub struct RuntimeConfigConsul {
pub node_name: String,
pub url: String,
}
+#[derive(Debug)]
pub struct RuntimeConfigFirewall {
pub refresh_time: Duration,
}
+#[derive(Debug)]
pub struct RuntimeConfigIgd {
pub private_ip: String,
pub expiration_time: Duration,
pub refresh_time: Duration,
}
+#[derive(Debug)]
pub struct RuntimeConfig {
pub acme: Option<RuntimeConfigAcme>,
pub consul: RuntimeConfigConsul,
@@ -57,7 +62,9 @@ impl RuntimeConfigAcme {
return Ok(None);
}
- let email = opts.email.unwrap();
+ let email = opts.email.expect(
+ "'DIPLONAT_ACME_EMAIL' environment variable is required \
+ if 'DIPLONAT_ACME_ENABLE' == 'true'");
Ok(Some(Self {
email,
@@ -67,7 +74,8 @@ impl RuntimeConfigAcme {
impl RuntimeConfigConsul {
pub(super) fn new(opts: ConfigOptsConsul) -> Result<Self> {
- let node_name = opts.node_name.unwrap();
+ let node_name = opts.node_name.expect(
+ "'DIPLONAT_CONSUL_NODE_NAME' environment variable is required");
let url = opts.url.unwrap_or(super::CONSUL_URL.to_string());
Ok(Self {
@@ -90,7 +98,8 @@ impl RuntimeConfigFirewall {
impl RuntimeConfigIgd {
pub(super) fn new(opts: ConfigOptsBase) -> Result<Self> {
- let private_ip = opts.private_ip.unwrap();
+ let private_ip = opts.private_ip.expect(
+ "'DIPLONAT_PRIVATE_IP' environment variable is required");
let expiration_time = Duration::from_secs(
opts.expiration_time.unwrap_or(super::EXPIRATION_TIME).into());
let refresh_time = Duration::from_secs(