diff --git a/src/cli.rs b/src/cli.rs index 187583d..e8ad500 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,6 +1,7 @@ use crate::{ init::{ConfigFormat, Launcher}, supervise::Properties, + utils::ZEROTIER_LOCAL_URL, }; use std::{path::PathBuf, time::Duration}; @@ -72,9 +73,9 @@ pub struct StartArgs { #[clap(long = "tls-key", value_name = "PATH")] pub tls_key: Option, - /// Provide a different URL for contacting the local zerotier-one service. - #[clap(long = "local-url", value_name = "LOCAL_URL")] - pub local_url: Option, + /// Provide a different URL for contacting the local zerotier-one service. Default: + #[clap(long = "local-url", value_name = "LOCAL_URL", default_value = ZEROTIER_LOCAL_URL)] + pub local_url: String, /// Log Level to print [off, trace, debug, error, warn, info] #[clap(short = 'l', long = "log-level", value_name = "LEVEL")] diff --git a/src/init.rs b/src/init.rs index 81006ae..2268120 100644 --- a/src/init.rs +++ b/src/init.rs @@ -26,7 +26,7 @@ pub struct Launcher { pub tls_key: Option, pub wildcard: bool, pub log_level: Option, - pub local_url: Option, + pub local_url: String, #[serde(skip_deserializing)] pub network_id: Option, } @@ -66,7 +66,7 @@ impl Default for Launcher { wildcard: false, network_id: None, log_level: None, - local_url: None, + local_url: ZEROTIER_LOCAL_URL.to_string(), } } } diff --git a/src/server.rs b/src/server.rs index 85ce84f..50569e2 100644 --- a/src/server.rs +++ b/src/server.rs @@ -42,11 +42,7 @@ impl Server { info!("Configuring DoT Listener"); let tls = TcpListener::bind(SocketAddr::new(ip, 853)).await?; - match sf.register_tls_listener( - tls, - tcp_timeout, - ((certs, cert_chain), key), - ) { + match sf.register_tls_listener(tls, tcp_timeout, ((certs, cert_chain), key)) { Ok(_) => {} Err(e) => tracing::error!("Cannot start DoT listener: {}", e), } diff --git a/src/utils.rs b/src/utils.rs index 5e816b6..8a5ce2f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -150,7 +150,7 @@ pub fn parse_member_name(name: Option, domain_name: Name) -> Option, + local_url: String, ) -> Result { let client = local_client_from_file(authtoken_path, local_url)?; @@ -166,7 +166,7 @@ pub async fn get_member_name( fn local_client_from_file( authtoken_path: &Path, - local_url: Option, + local_url: String, ) -> Result { let authtoken = std::fs::read_to_string(authtoken_path)?; local_client(authtoken, local_url) @@ -174,25 +174,19 @@ fn local_client_from_file( pub fn local_client( authtoken: String, - local_url: Option, + local_url: String, ) -> Result { let mut headers = HeaderMap::new(); headers.insert("X-ZT1-Auth", HeaderValue::from_str(&authtoken)?); - let local_url = if let Some(url) = local_url { + let local_url = if let Ok(url) = std::env::var("ZEROTIER_LOCAL_URL") { if url.len() > 0 { url } else { - ZEROTIER_LOCAL_URL.to_string() - } - } else if let Ok(url) = std::env::var("ZEROTIER_LOCAL_URL") { - if url.len() > 0 { - url - } else { - ZEROTIER_LOCAL_URL.to_string() + local_url } } else { - ZEROTIER_LOCAL_URL.to_string() + local_url }; Ok(zerotier_one_api::Client::new_with_client( @@ -209,7 +203,7 @@ pub fn local_client( pub async fn get_listen_ips( authtoken_path: &Path, network_id: &str, - local_url: Option, + local_url: String, ) -> Result, anyhow::Error> { let client = local_client_from_file(authtoken_path, local_url)?;