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