Make token config mandatory

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2024-07-10 02:09:53 +02:00
parent d0cb431546
commit 2ef603151e
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2
2 changed files with 5 additions and 5 deletions

View file

@ -58,7 +58,7 @@ struct Config {
/// Token to match the one provided by the Webhook service /// Token to match the one provided by the Webhook service
#[serde(rename = "webhook-token")] #[serde(rename = "webhook-token")]
webhook_token: Option<String>, webhook_token: String,
/// HTTP Webhook listening address and port, e.g., 127.0.0.1:1234 or [::1]:1234 /// HTTP Webhook listening address and port, e.g., 127.0.0.1:1234 or [::1]:1234
#[serde(default = "default_addr")] #[serde(default = "default_addr")]
@ -140,8 +140,8 @@ async fn main() -> Result<!, Error> {
); );
let tcp_bind = TcpListener::bind(config.addr).await?; let tcp_bind = TcpListener::bind(config.addr).await?;
let token: Option<&'static String> = let token: &'static String =
unsafe { core::mem::transmute(config.webhook_token.as_ref()) }; unsafe { core::mem::transmute::<&String, &'static String>(&config.webhook_token) };
let value_tx = Arc::new(Mutex::new(value_tx)); let value_tx = Arc::new(Mutex::new(value_tx));
loop { loop {

View file

@ -36,7 +36,7 @@ fn error_res<E: std::fmt::Debug>(e: E) -> Result<Response<Full<Bytes>>, Infallib
Ok(res) Ok(res)
} }
async fn webhooks_inner(req: Request<Incoming>, token: Option<&String>) -> Result<WebHook, Error> { async fn webhooks_inner(req: Request<Incoming>, token: &str) -> Result<WebHook, Error> {
match req.method() { match req.method() {
&Method::POST => (), &Method::POST => (),
_ => return Err(Error::MethodMismatch), _ => return Err(Error::MethodMismatch),
@ -64,7 +64,7 @@ async fn webhooks_inner(req: Request<Incoming>, token: Option<&String>) -> Resul
pub async fn webhooks( pub async fn webhooks(
req: Request<Incoming>, req: Request<Incoming>,
token: Option<&String>, token: &str,
value_tx: Arc<Mutex<UnboundedSender<WebHook>>>, value_tx: Arc<Mutex<UnboundedSender<WebHook>>>,
) -> Result<Response<Full<Bytes>>, Infallible> { ) -> Result<Response<Full<Bytes>>, Infallible> {
match webhooks_inner(req, token).await { match webhooks_inner(req, token).await {