Skip to content

Commit 6c9fa0c

Browse files
committed
feat: remove origin from config and automate detection
1 parent e500426 commit 6c9fa0c

File tree

5 files changed

+4
-9
lines changed

5 files changed

+4
-9
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ axum = { version = "0.8.3", default-features = false, features = [
3232
] }
3333
grhooks-config = { version = "0.1.0", path = "crates/config" }
3434
grhooks-core = { version = "0.1.0", path = "crates/core" }
35+
grhooks-origin = { version = "0.1.0", path = "crates/origin" }
3536
notify = "8.0.0"
3637
serde_json.workspace = true
3738
tokio = { version = "1.44.1", default-features = false, features = ["full"] }

crates/config/src/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@ use std::collections::HashSet;
44
use std::path::PathBuf;
55

66
use clap::{Arg, Command};
7-
use grhooks_origin::Origin;
87
use serde::Deserialize;
98

10-
pub use grhooks_origin;
11-
129
#[derive(Clone, Debug, Deserialize)]
1310
pub struct WebhookConfig {
1411
pub path: String,
15-
#[serde(default = "Origin::default")]
16-
pub origin: Origin,
1712
pub secret: Option<String>,
1813
pub events: HashSet<String>,
1914
pub shell: Option<Vec<String>>,

src/errors.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use axum::http::StatusCode;
22
use axum::response::{IntoResponse, Response};
3-
use grhooks_config::grhooks_origin;
43

54
#[derive(Debug)]
65
pub enum HeaderValidationError {

src/validator.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use axum::{
33
middleware::Next,
44
response::Response,
55
};
6-
use grhooks_config::grhooks_origin::{Error as OriginError, Origin, WebhookOrigin};
76
use grhooks_core::render_secret;
7+
use grhooks_origin::{Origin, WebhookOrigin};
88

99
use crate::{GlobalConfig, errors::HeaderValidationError};
1010

@@ -34,8 +34,7 @@ pub async fn validate_signature_middleware(
3434
.find(|w| w.path == path)
3535
.ok_or(HeaderValidationError::WebhookNotFound)?;
3636

37-
let validator = webhook_config.origin;
38-
let event_type = validator.extract_event_type(&headers)?;
37+
let event_type = origin.extract_event_type(&headers)?;
3938

4039
if let Some(secret) = &webhook_config.secret {
4140
let secret = render_secret(secret, &event_type);

0 commit comments

Comments
 (0)