From 2ef603151e948cc443ae825d355a515ef93dee13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 10 Jul 2024 02:09:53 +0200 Subject: [PATCH] Make token config mandatory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/main.rs | 6 +++--- src/web.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 07813dd..e691bca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,7 +58,7 @@ struct Config { /// Token to match the one provided by the Webhook service #[serde(rename = "webhook-token")] - webhook_token: Option, + webhook_token: String, /// HTTP Webhook listening address and port, e.g., 127.0.0.1:1234 or [::1]:1234 #[serde(default = "default_addr")] @@ -140,8 +140,8 @@ async fn main() -> Result { ); let tcp_bind = TcpListener::bind(config.addr).await?; - let token: Option<&'static String> = - unsafe { core::mem::transmute(config.webhook_token.as_ref()) }; + let token: &'static String = + unsafe { core::mem::transmute::<&String, &'static String>(&config.webhook_token) }; let value_tx = Arc::new(Mutex::new(value_tx)); loop { diff --git a/src/web.rs b/src/web.rs index 0892754..a4d4add 100644 --- a/src/web.rs +++ b/src/web.rs @@ -36,7 +36,7 @@ fn error_res(e: E) -> Result>, Infallib Ok(res) } -async fn webhooks_inner(req: Request, token: Option<&String>) -> Result { +async fn webhooks_inner(req: Request, token: &str) -> Result { match req.method() { &Method::POST => (), _ => return Err(Error::MethodMismatch), @@ -64,7 +64,7 @@ async fn webhooks_inner(req: Request, token: Option<&String>) -> Resul pub async fn webhooks( req: Request, - token: Option<&String>, + token: &str, value_tx: Arc>>, ) -> Result>, Infallible> { match webhooks_inner(req, token).await {