Compare commits

..

1 commit

Author SHA1 Message Date
2e8ebbcbc7 WIP: test(git): make repository more testable
All checks were successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
2024-05-18 18:49:43 +01:00

View file

@ -2,7 +2,7 @@ use std::net::SocketAddr;
use actix::prelude::*;
use tracing::{info, warn};
use tracing::{debug, info};
use crate::actors::webhook::message::WebhookMessage;
@ -25,24 +25,17 @@ pub async fn start(
// query: String,
headers: warp::http::HeaderMap,
body: bytes::Bytes| async move {
info!("POST received");
let bytes = body.to_vec();
let request_data = String::from_utf8_lossy(&bytes).to_string();
let id = ulid::Ulid::new().to_string();
match headers.get("Authorization") {
Some(auhorisation) => {
info!(id, path, "Received webhook");
debug!(id, path, "Received webhook");
let authorisation = auhorisation
.to_str()
.map_err(|e| {
warn!("Invalid value in authorization: {:?}", e);
warp::reject()
})? // valid characters
.map_err(|_| warp::reject())? // valid characters
.strip_prefix("Basic ")
.ok_or_else(|| {
warn!("Authorization must be 'Basic'");
warp::reject()
})? // must start with "Basic "
.ok_or_else(warp::reject)? // must start with "Basic "
.to_string();
let message = WebhookMessage::new(
id,
@ -52,19 +45,10 @@ pub async fn start(
);
recipient
.try_send(message)
.map(|_| {
info!("Message sent ok");
warp::reply::with_status("OK", warp::http::StatusCode::OK)
})
.map_err(|e| {
warn!("Unknown error: {:?}", e);
warp::reject()
})
}
_ => {
warn!("No Authorization header");
Err(warp::reject())
.map(|_| warp::reply::with_status("OK", warp::http::StatusCode::OK))
.map_err(|_| warp::reject())
}
_ => Err(warp::reject()),
}
},
);