diff --git a/Cargo.lock b/Cargo.lock index 0d49e91..c6fc347 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1228,6 +1228,7 @@ dependencies = [ "base64 0.12.3", "blake3", "chrono", + "clap", "dashmap", "futures", "handlebars", diff --git a/crates/ptth_relay/Cargo.toml b/crates/ptth_relay/Cargo.toml index d41d751..fe3fb13 100644 --- a/crates/ptth_relay/Cargo.toml +++ b/crates/ptth_relay/Cargo.toml @@ -11,6 +11,7 @@ license = "AGPL-3.0" base64 = "0.12.3" blake3 = "0.3.7" chrono = {version = "0.4.19", features = ["serde"]} +clap = "2.33.3" dashmap = "3.11.10" futures = "0.3.7" handlebars = "3.5.1" diff --git a/crates/ptth_relay/src/main.rs b/crates/ptth_relay/src/main.rs index abe446d..0d676da 100644 --- a/crates/ptth_relay/src/main.rs +++ b/crates/ptth_relay/src/main.rs @@ -7,6 +7,7 @@ use std::{ sync::Arc, }; +use clap::{App, SubCommand}; use tracing::{info}; use tracing_subscriber::{ fmt, @@ -29,12 +30,33 @@ async fn main () -> Result <(), Box > { .init () ; + let matches = App::new ("ptth_relay") + .author ("Trish") + .about ("Relay server for the PTTH backwards HTTP server") + .subcommand (SubCommand::with_name ("hash-api-key")) + .get_matches (); + + if matches.subcommand_matches ("hash-api-key").is_some () { + use std::io; + use ptth_relay::key_validity::BlakeHashWrapper; + + println! ("Enter key (it will be visible in the terminal)"); + + let mut key = String::new (); + io::stdin ().read_line (&mut key)?; + + println! ("{}", BlakeHashWrapper::from_key (key.trim_end ().as_bytes ()).encode_base64 ()); + return Ok (()); + } + let config_path = PathBuf::from ("config/ptth_relay.toml"); let config = Config::from_file (&config_path).await?; - match read_git_version ().await { - Some (x) => info! ("ptth_relay Git version: {:?}", x), - None => info! ("ptth_relay not built from Git"), + if let Some (x) = read_git_version ().await { + info! ("ptth_relay Git version: {:?}", x); + } + else { + info! ("ptth_relay not built from Git"); } let (shutdown_rx, forced_shutdown) = ptth_core::graceful_shutdown::init_with_force ();