Compare commits

..

2 commits

Author SHA1 Message Date
ce4e92fdda WIP: fix invalid webhook authorisations
All checks were successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
2024-05-21 08:37:49 +01:00
572da0d761 WIP: mock repository
All checks were successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
2024-05-20 17:35:36 +01:00
4 changed files with 25 additions and 11 deletions

View file

@ -3,7 +3,7 @@ resolver = "2"
members = ["crates/cli", "crates/server", "crates/config", "crates/git"]
[workspace.package]
version = "0.5.1"
version = "0.5.0"
edition = "2021"
[workspace.lints.clippy]

View file

@ -194,6 +194,9 @@ impl Handler<WebhookMessage> for RepoActor {
);
return;
}
let id = msg.id();
let span = tracing::info_span!("handle", ?id);
let _guard = span.enter();
let body = msg.body();
match serde_json::from_str::<Push>(body.as_str()) {
Err(err) => warn!(?err, ?body, "Not a 'push'"),

View file

@ -1,18 +1,23 @@
//
use actix::prelude::*;
use git_next_config::RepoAlias;
use ulid::Ulid;
use crate::actors::repo::webhook::WebhookAuth;
#[derive(Message, Debug, Clone, derive_more::Constructor)]
#[rtype(result = "()")]
pub struct WebhookMessage {
id: Id,
// forge // TODO: differentiate between multiple forges
repo_alias: RepoAlias,
authorisation: WebhookAuth,
body: Body,
}
impl WebhookMessage {
pub const fn id(&self) -> &Id {
&self.id
}
pub const fn repo_alias(&self) -> &RepoAlias {
&self.repo_alias
}
@ -24,6 +29,9 @@ impl WebhookMessage {
}
}
#[derive(Clone, Copy, Debug, derive_more::Constructor)]
pub struct Id(Ulid);
#[derive(Clone, Debug, derive_more::Constructor)]
pub struct Body(String);
impl Body {

View file

@ -4,6 +4,7 @@ use actix::prelude::*;
use git_next_config::RepoAlias;
use tracing::{info, warn};
use ulid::Ulid;
use warp::reject::Rejection;
use crate::actors::{repo::webhook::WebhookAuth, webhook::message::WebhookMessage};
@ -33,16 +34,14 @@ pub async fn start(
let repo_alias = RepoAlias::new(path);
let bytes = body.to_vec();
let body = message::Body::new(String::from_utf8_lossy(&bytes).to_string());
headers.get("Authorization").map_or_else(
|| {
warn!("No Authorization header");
Err(warp::reject())
},
|authorisation_header| {
info!(?repo_alias, ?authorisation_header, "Received webhook",);
let id = message::Id::new(Ulid::new());
match headers.get("Authorization") {
Some(authorisation_header) => {
info!(?id, ?repo_alias, ?authorisation_header, "Received webhook",);
match parse_auth(authorisation_header) {
Ok(authorisation) => {
let message = WebhookMessage::new(repo_alias, authorisation, body);
let message =
WebhookMessage::new(id, repo_alias, authorisation, body);
recipient
.try_send(message)
.map(|_| {
@ -59,8 +58,12 @@ pub async fn start(
Err(warp::reject())
}
}
},
)
}
_ => {
warn!("No Authorization header");
Err(warp::reject())
}
}
},
);