diff options
author | Quentin <quentin@dufour.io> | 2021-09-17 10:06:51 +0200 |
---|---|---|
committer | Quentin <quentin@dufour.io> | 2021-09-17 10:06:51 +0200 |
commit | 2bbc9109991f8bb79a09a965a1d2779e1749b25b (patch) | |
tree | 57dcb5b115b854d651ac6f952466d4109bac2d45 /src/config/options.rs | |
parent | fa25c54e47decf9f323ba0c614f4d9de106626d5 (diff) | |
parent | bf226d077ef2bea0567a7b36b4d25ce2d0b5191c (diff) | |
download | diplonat-2bbc9109991f8bb79a09a965a1d2779e1749b25b.tar.gz diplonat-2bbc9109991f8bb79a09a965a1d2779e1749b25b.zip |
Merge pull request 'added rustfmt, a guide about this, and a CI job to enforce code quality' (#10) from adrien/diplonat:meta/formating into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/diplonat/pulls/10
Diffstat (limited to 'src/config/options.rs')
-rw-r--r-- | src/config/options.rs | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/src/config/options.rs b/src/config/options.rs index 36da475..f62d14c 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -11,66 +11,68 @@ use crate::config::RuntimeConfig; /// Base configuration options #[derive(Clone, Default, Deserialize)] pub struct ConfigOptsBase { - /// This node's private IP address [default: None] - pub private_ip: Option<String>, - /// Expiration time for IGD rules [default: 60] - pub expiration_time: Option<u16>, - /// Refresh time for IGD and Firewall rules [default: 300] - pub refresh_time: Option<u16>, + /// This node's private IP address [default: None] + pub private_ip: Option<String>, + /// Expiration time for IGD rules [default: 60] + pub expiration_time: Option<u16>, + /// Refresh time for IGD and Firewall rules [default: 300] + pub refresh_time: Option<u16>, } /// ACME configuration options #[derive(Clone, Default, Deserialize)] pub struct ConfigOptsAcme { - /// Whether ACME is enabled [default: false] - #[serde(default)] - pub enable: bool, + /// Whether ACME is enabled [default: false] + #[serde(default)] + pub enable: bool, - /// The default domain holder's e-mail [default: None] - pub email: Option<String>, + /// The default domain holder's e-mail [default: None] + pub email: Option<String>, } /// Consul configuration options #[derive(Clone, Default, Deserialize)] pub struct ConfigOptsConsul { - /// Consul's node name [default: None] - pub node_name: Option<String>, - /// Consul's REST URL [default: "http://127.0.0.1:8500"] - pub url: Option<String>, + /// Consul's node name [default: None] + pub node_name: Option<String>, + /// Consul's REST URL [default: "http://127.0.0.1:8500"] + pub url: Option<String>, } /// Model of all potential configuration options pub struct ConfigOpts { - pub base: ConfigOptsBase, - pub acme: ConfigOptsAcme, - pub consul: ConfigOptsConsul, + pub base: ConfigOptsBase, + pub acme: ConfigOptsAcme, + pub consul: ConfigOptsConsul, } impl ConfigOpts { - pub fn from_env() -> Result<RuntimeConfig> { - let base: ConfigOptsBase = envy::prefixed("DIPLONAT_").from_env()?; - let consul: ConfigOptsConsul = envy::prefixed("DIPLONAT_CONSUL_").from_env()?; - let acme: ConfigOptsAcme = envy::prefixed("DIPLONAT_ACME_").from_env()?; + pub fn from_env() -> Result<RuntimeConfig> { + let base: ConfigOptsBase = envy::prefixed("DIPLONAT_").from_env()?; + let consul: ConfigOptsConsul = envy::prefixed("DIPLONAT_CONSUL_").from_env()?; + let acme: ConfigOptsAcme = envy::prefixed("DIPLONAT_ACME_").from_env()?; - RuntimeConfig::new(Self { - base: base, - consul: consul, - acme: acme, - }) - } + RuntimeConfig::new(Self { + base: base, + consul: consul, + acme: acme, + }) + } - // Currently only used in tests - #[allow(dead_code)] - pub fn from_iter<Iter: Clone>(iter: Iter) -> Result<RuntimeConfig> - 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())?; + // Currently only used in tests + #[allow(dead_code)] + pub fn from_iter<Iter: Clone>(iter: Iter) -> Result<RuntimeConfig> + 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())?; - RuntimeConfig::new(Self { - base: base, - consul: consul, - acme: acme, - }) - } -}
\ No newline at end of file + RuntimeConfig::new(Self { + base: base, + consul: consul, + acme: acme, + }) + } +} |