Compare commits
2 commits
ce4e92fdda
...
b04c17dc15
Author | SHA1 | Date | |
---|---|---|---|
b04c17dc15 | |||
5176e3e8c7 |
4 changed files with 11 additions and 25 deletions
|
@ -3,7 +3,7 @@ resolver = "2"
|
||||||
members = ["crates/cli", "crates/server", "crates/config", "crates/git"]
|
members = ["crates/cli", "crates/server", "crates/config", "crates/git"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.5.0"
|
version = "0.5.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[workspace.lints.clippy]
|
[workspace.lints.clippy]
|
||||||
|
|
|
@ -194,9 +194,6 @@ impl Handler<WebhookMessage> for RepoActor {
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let id = msg.id();
|
|
||||||
let span = tracing::info_span!("handle", ?id);
|
|
||||||
let _guard = span.enter();
|
|
||||||
let body = msg.body();
|
let body = msg.body();
|
||||||
match serde_json::from_str::<Push>(body.as_str()) {
|
match serde_json::from_str::<Push>(body.as_str()) {
|
||||||
Err(err) => warn!(?err, ?body, "Not a 'push'"),
|
Err(err) => warn!(?err, ?body, "Not a 'push'"),
|
||||||
|
|
|
@ -1,23 +1,18 @@
|
||||||
//
|
//
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
use git_next_config::RepoAlias;
|
use git_next_config::RepoAlias;
|
||||||
use ulid::Ulid;
|
|
||||||
|
|
||||||
use crate::actors::repo::webhook::WebhookAuth;
|
use crate::actors::repo::webhook::WebhookAuth;
|
||||||
|
|
||||||
#[derive(Message, Debug, Clone, derive_more::Constructor)]
|
#[derive(Message, Debug, Clone, derive_more::Constructor)]
|
||||||
#[rtype(result = "()")]
|
#[rtype(result = "()")]
|
||||||
pub struct WebhookMessage {
|
pub struct WebhookMessage {
|
||||||
id: Id,
|
|
||||||
// forge // TODO: differentiate between multiple forges
|
// forge // TODO: differentiate between multiple forges
|
||||||
repo_alias: RepoAlias,
|
repo_alias: RepoAlias,
|
||||||
authorisation: WebhookAuth,
|
authorisation: WebhookAuth,
|
||||||
body: Body,
|
body: Body,
|
||||||
}
|
}
|
||||||
impl WebhookMessage {
|
impl WebhookMessage {
|
||||||
pub const fn id(&self) -> &Id {
|
|
||||||
&self.id
|
|
||||||
}
|
|
||||||
pub const fn repo_alias(&self) -> &RepoAlias {
|
pub const fn repo_alias(&self) -> &RepoAlias {
|
||||||
&self.repo_alias
|
&self.repo_alias
|
||||||
}
|
}
|
||||||
|
@ -29,9 +24,6 @@ impl WebhookMessage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, derive_more::Constructor)]
|
|
||||||
pub struct Id(Ulid);
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, derive_more::Constructor)]
|
#[derive(Clone, Debug, derive_more::Constructor)]
|
||||||
pub struct Body(String);
|
pub struct Body(String);
|
||||||
impl Body {
|
impl Body {
|
||||||
|
|
|
@ -4,7 +4,6 @@ use actix::prelude::*;
|
||||||
|
|
||||||
use git_next_config::RepoAlias;
|
use git_next_config::RepoAlias;
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
use ulid::Ulid;
|
|
||||||
use warp::reject::Rejection;
|
use warp::reject::Rejection;
|
||||||
|
|
||||||
use crate::actors::{repo::webhook::WebhookAuth, webhook::message::WebhookMessage};
|
use crate::actors::{repo::webhook::WebhookAuth, webhook::message::WebhookMessage};
|
||||||
|
@ -34,14 +33,16 @@ pub async fn start(
|
||||||
let repo_alias = RepoAlias::new(path);
|
let repo_alias = RepoAlias::new(path);
|
||||||
let bytes = body.to_vec();
|
let bytes = body.to_vec();
|
||||||
let body = message::Body::new(String::from_utf8_lossy(&bytes).to_string());
|
let body = message::Body::new(String::from_utf8_lossy(&bytes).to_string());
|
||||||
let id = message::Id::new(Ulid::new());
|
headers.get("Authorization").map_or_else(
|
||||||
match headers.get("Authorization") {
|
|| {
|
||||||
Some(authorisation_header) => {
|
warn!("No Authorization header");
|
||||||
info!(?id, ?repo_alias, ?authorisation_header, "Received webhook",);
|
Err(warp::reject())
|
||||||
|
},
|
||||||
|
|authorisation_header| {
|
||||||
|
info!(?repo_alias, ?authorisation_header, "Received webhook",);
|
||||||
match parse_auth(authorisation_header) {
|
match parse_auth(authorisation_header) {
|
||||||
Ok(authorisation) => {
|
Ok(authorisation) => {
|
||||||
let message =
|
let message = WebhookMessage::new(repo_alias, authorisation, body);
|
||||||
WebhookMessage::new(id, repo_alias, authorisation, body);
|
|
||||||
recipient
|
recipient
|
||||||
.try_send(message)
|
.try_send(message)
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
|
@ -58,12 +59,8 @@ pub async fn start(
|
||||||
Err(warp::reject())
|
Err(warp::reject())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
_ => {
|
)
|
||||||
warn!("No Authorization header");
|
|
||||||
Err(warp::reject())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue