diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2020-05-22 18:41:13 +0200 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2020-05-22 18:41:13 +0200 |
commit | e1d0eadb9dc5e2e3bea8bc48f7b33ad9ef632554 (patch) | |
tree | d1e891b87684c7907ff1245ebd5ad403804f6fd9 /src/environment_adapter.rs | |
parent | deeecd93e1fc5545e6e0280d1799436638e84a38 (diff) | |
download | diplonat-e1d0eadb9dc5e2e3bea8bc48f7b33ad9ef632554.tar.gz diplonat-e1d0eadb9dc5e2e3bea8bc48f7b33ad9ef632554.zip |
WIP software
Diffstat (limited to 'src/environment_adapter.rs')
-rw-r--r-- | src/environment_adapter.rs | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/src/environment_adapter.rs b/src/environment_adapter.rs deleted file mode 100644 index e4fad70..0000000 --- a/src/environment_adapter.rs +++ /dev/null @@ -1,50 +0,0 @@ -use std::env; -use tokio::sync::broadcast; -use anyhow::{Result, Context, anyhow}; -use log::*; -use crate::diplonat::*; -use crate::node_state::*; -use std::cell::Cell; - -const epi: &'static str = "DIPLONAT_PRIVATE_IP"; -const ert: &'static str = "DIPLONAT_REFRESH_TIME"; -const eet: &'static str = "DIPLONAT_EXPIRATION_TIME"; -const ecnd: &'static str = "DIPLONAT_CONSUL_NODE_NAME"; -const ecu: &'static str = "DIPLONAT_CONSUL_URL"; - -pub struct EnvironmentAdapter {} - -impl EnvironmentAdapter { - pub async fn new(ns: &Cell<NodeState>, _: &broadcast::Sender<()>) -> Result<Self> { - ns.consul_node_name = Some(match env::var(ecu) { - Ok(e) => e, - Err(_) => "http://127.0.0.1:8500".to_string() - }); - - ns.private_ip = Some(env::var(epi) - .with_context(|| format!("{} env var must be defined, eg: 192.168.0.18", epi))?); - - ns.refresh_time = Some(env::var(ert) - .with_context(|| format!("{} env var must be defined, eg: 60", ert))? - .parse() - .with_context(|| format!("{} env var must be an integer, eg: 60", ert))?); - - ns.expiration_time = Some(env::var(eet) - .with_context(|| format!("{} env var must be defined, eg: 300", eet))? - .parse() - .with_context(|| format!("{} env var must be an integer, eg: 300", eet))?); - - ns.consul_node_name = Some(env::var(ecnd) - .with_context(|| format!("{} env var must be defined", ecnd))?); - - match (ns.refresh_time, ns.expiration_time) { - (Some(rt), Some(et)) if rt * 2 <= et => debug!("Checked refresh time is lower than expiration time"), - (Some(rt), Some(et)) => return Err(anyhow!("Expiration time (currently: {}s) must be twice bigger than refresh time (currently: {}s)", rt, et)), - _ => return Err(anyhow!("Please define refresh time and expiration time")) - } - - return Ok(Self{}); - } -} - - |