diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index c041886..84acca1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,8 +4,12 @@ use std::net::SocketAddrV4; use igd::aio::search_gateway; use igd::PortMappingProtocol; +use consul::catalog::Catalog; +use consul::{Client, Config}; + struct DiplonatConfig { private_ip: String, + consul_node_name: String, refresh_time: u32, expiration_time: u32 } @@ -28,12 +32,19 @@ fn fetch_configuration() -> Result<DiplonatConfig, String> { Ok(val) => val.parse().unwrap(), Err(e) => return Err(format!("unable to fetch environment variable {}: {}", env_expiration_time,e)) }; + + let env_consul_node_name = "DIPLONAT_CONSUL_NODE_NAME"; + let consul_node_name = match env::var(env_consul_node_name) { + Ok(val) => val, + Err(e) => return Err(format!("unable to fetch environment variable {}: {}", env_consul_node_name,e)) + }; if refresh_time * 2 > expiration_time { return Err(format!("Expiration time (currently: {}s) must be twice bigger than refresh time (currently: {}s)", expiration_time, refresh_time)) } - let config = DiplonatConfig { private_ip: private_ip, refresh_time: refresh_time, expiration_time: expiration_time }; + let config = DiplonatConfig { private_ip: private_ip, refresh_time: refresh_time, expiration_time: expiration_time, consul_node_name: consul_node_name }; + println!("\tConsul node name: {}", config.consul_node_name); println!("\tPrivate IP address: {}", config.private_ip); println!("\tRefresh time: {} seconds", config.refresh_time); println!("\tExpiration time: {} seconds", config.expiration_time); @@ -47,6 +58,13 @@ async fn main() { Err(e) => return println!("unable to build configuration: {}", e), }; + let consul_config = Config::new().unwrap(); + let consul_client = Client::new(consul_config); + + match consul_client.nodes(None) { + Ok(v) => println!("ok: {:?}", v), + Err(err) => println!("err: {}", err), + }; let gateway = match search_gateway(Default::default()).await { Ok(g) => g, |