#![warn (clippy::pedantic)] use std::{ convert::TryFrom, error::Error, path::PathBuf, sync::Arc, }; use clap::{App, SubCommand}; use tracing_subscriber::{ fmt, fmt::format::FmtSpan, EnvFilter, }; use ptth_relay::{ Config, Relay, run_relay, }; #[tokio::main] async fn main () -> Result <(), Box > { fmt () .with_env_filter (EnvFilter::from_default_env ()) .with_span_events (FmtSpan::CLOSE) .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 mut config = Config::from_file (&config_path).await?; config.webhook_url = std::env::var ("WEBHOOK_URL").ok ().or (config.webhook_url); let (shutdown_rx, forced_shutdown) = ptth_core::graceful_shutdown::init_with_force (); forced_shutdown.wrap_server ( run_relay ( Arc::new (Relay::try_from (config)?), &PathBuf::new (), shutdown_rx, Some (config_path) ) ).await??; Ok (()) }