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
#[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
#[serde(default = "default_addr")]
@ -140,8 +140,8 @@ async fn main() -> Result<!, Error> {
);
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 {

View file

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