Skip to content

Commit

Permalink
Retool CLI to use a default parameter, propagate that instead of swit…
Browse files Browse the repository at this point in the history
…ching on an Option<>

Simply a better patch!

Signed-off-by: Erik Hollensbe <git@hollensbe.org>
  • Loading branch information
erikh committed Mar 6, 2023
1 parent aedcdeb commit 572954e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
7 changes: 4 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
init::{ConfigFormat, Launcher},
supervise::Properties,
utils::ZEROTIER_LOCAL_URL,
};
use std::{path::PathBuf, time::Duration};

Expand Down Expand Up @@ -72,9 +73,9 @@ pub struct StartArgs {
#[clap(long = "tls-key", value_name = "PATH")]
pub tls_key: Option<PathBuf>,

/// Provide a different URL for contacting the local zerotier-one service.
#[clap(long = "local-url", value_name = "LOCAL_URL")]
pub local_url: Option<String>,
/// 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")]
Expand Down
4 changes: 2 additions & 2 deletions src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Launcher {
pub tls_key: Option<PathBuf>,
pub wildcard: bool,
pub log_level: Option<crate::log::LevelFilter>,
pub local_url: Option<String>,
pub local_url: String,
#[serde(skip_deserializing)]
pub network_id: Option<String>,
}
Expand Down Expand Up @@ -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(),
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
20 changes: 7 additions & 13 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub fn parse_member_name(name: Option<String>, domain_name: Name) -> Option<Name
pub async fn get_member_name(
authtoken_path: &Path,
domain_name: Name,
local_url: Option<String>,
local_url: String,
) -> Result<LowerName, anyhow::Error> {
let client = local_client_from_file(authtoken_path, local_url)?;

Expand All @@ -166,33 +166,27 @@ pub async fn get_member_name(

fn local_client_from_file(
authtoken_path: &Path,
local_url: Option<String>,
local_url: String,
) -> Result<zerotier_one_api::Client, anyhow::Error> {
let authtoken = std::fs::read_to_string(authtoken_path)?;
local_client(authtoken, local_url)
}

pub fn local_client(
authtoken: String,
local_url: Option<String>,
local_url: String,
) -> Result<zerotier_one_api::Client, anyhow::Error> {
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(
Expand All @@ -209,7 +203,7 @@ pub fn local_client(
pub async fn get_listen_ips(
authtoken_path: &Path,
network_id: &str,
local_url: Option<String>,
local_url: String,
) -> Result<Vec<String>, anyhow::Error> {
let client = local_client_from_file(authtoken_path, local_url)?;

Expand Down

0 comments on commit 572954e

Please sign in to comment.