Compare commits
15 commits
dev/hermit
...
main
Author | SHA1 | Date | |
---|---|---|---|
faba2949d2 | |||
57d4f10b41 | |||
35b31b2a15 | |||
71153b28ec | |||
f6ec8af944 | |||
55c5134840 | |||
f38c70373c | |||
f25ee6b943 | |||
976c25ba1a | |||
81be79d46d | |||
f195162ce5 | |||
0312a600ed | |||
f7aea10c6b | |||
620fa520ce | |||
856cdc9457 |
7 changed files with 718 additions and 1078 deletions
37
.woodpecker.yml
Normal file
37
.woodpecker.yml
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
pipeline:
|
||||||
|
fmt:
|
||||||
|
group: default
|
||||||
|
image: rust_full
|
||||||
|
commands:
|
||||||
|
- cargo fmt --all -- --check
|
||||||
|
|
||||||
|
clippy:
|
||||||
|
group: default
|
||||||
|
image: rust_full
|
||||||
|
commands:
|
||||||
|
- cargo clippy --all-features
|
||||||
|
|
||||||
|
test:
|
||||||
|
group: default
|
||||||
|
image: rust_full
|
||||||
|
commands:
|
||||||
|
- cargo test
|
||||||
|
|
||||||
|
build:
|
||||||
|
group: default
|
||||||
|
image: rust_full
|
||||||
|
commands:
|
||||||
|
- cargo build
|
||||||
|
- cargo build --release
|
||||||
|
|
||||||
|
build-deb:
|
||||||
|
group: default
|
||||||
|
image: rust_full
|
||||||
|
commands:
|
||||||
|
- cargo deb
|
||||||
|
|
||||||
|
doc:
|
||||||
|
group: default
|
||||||
|
image: rust_full
|
||||||
|
commands:
|
||||||
|
- cargo doc
|
1692
Cargo.lock
generated
1692
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
37
Cargo.toml
37
Cargo.toml
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "webhookey"
|
name = "webhookey"
|
||||||
version = "0.1.5"
|
version = "0.1.6"
|
||||||
authors = ["finga <webhookey@onders.org>"]
|
authors = ["finga <webhookey@onders.org>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
|
@ -11,34 +11,23 @@ description = "Trigger scripts via http(s) requests"
|
||||||
tls = ["rocket/tls"]
|
tls = ["rocket/tls"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
anyhow = "1.0"
|
||||||
|
clap = { version = "4.3", features = ["derive"] }
|
||||||
|
dirs = "4.0"
|
||||||
|
env_logger = "0.9"
|
||||||
|
hex = "0.4"
|
||||||
|
hmac = "0.12"
|
||||||
|
ipnet = { version = "2.3", features = ["serde"] }
|
||||||
|
log = "0.4"
|
||||||
|
regex = "1.5"
|
||||||
rocket = "0.5.0-rc.1"
|
rocket = "0.5.0-rc.1"
|
||||||
|
run_script = "0.9"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde_yaml = "0.8"
|
|
||||||
serde_regex = "1.1"
|
serde_regex = "1.1"
|
||||||
regex = "1.5"
|
serde_yaml = "0.8"
|
||||||
dirs = "4.0"
|
sha2 = "0.10"
|
||||||
anyhow = "1.0"
|
|
||||||
log = "0.4"
|
|
||||||
env_logger = "0.9"
|
|
||||||
hmac = "0.11"
|
|
||||||
sha2 = "0.9"
|
|
||||||
hex = "0.4"
|
|
||||||
ipnet = { version = "2.3", features = ["serde"] }
|
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
run_script = "0.9"
|
|
||||||
clap = "3.0.0-beta.5"
|
|
||||||
|
|
||||||
[target.'cfg(target_os = "hermit")'.dependencies.hermit-sys]
|
|
||||||
version = "0.1.*"
|
|
||||||
default-features = false
|
|
||||||
features = ["smoltcp"]
|
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
opt-level = 3
|
|
||||||
|
|
||||||
[profile.dev]
|
|
||||||
opt-level = 1
|
|
||||||
|
|
||||||
[package.metadata.deb]
|
[package.metadata.deb]
|
||||||
extended-description = "Webhookey receives requests in form of a so called Webhook as for example sent by Gitea. Those requests are matched against configured filters, if a filter matches, values from the header and the body can be passed to scripts as parameters which are then executed subsequently."
|
extended-description = "Webhookey receives requests in form of a so called Webhook as for example sent by Gitea. Those requests are matched against configured filters, if a filter matches, values from the header and the body can be passed to scripts as parameters which are then executed subsequently."
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
# Webhookey
|
# Webhookey
|
||||||
|
![status-badge](https://ci.onders.org/api/badges/finga/webhookey/status.svg?branch=main)
|
||||||
|
|
||||||
Webhookey is a web server listening for
|
Webhookey is a web server listening for
|
||||||
[webhooks](https://en.wikipedia.org/wiki/Webhook) as for example sent
|
[webhooks](https://en.wikipedia.org/wiki/Webhook) as for example sent
|
||||||
by Gitea's webhooks. Further, Webhookey allows you to specify rules
|
by Gitea's webhooks. Further, Webhookey allows you to specify rules
|
||||||
|
|
12
src/cli.rs
12
src/cli.rs
|
@ -1,4 +1,4 @@
|
||||||
use clap::{crate_authors, crate_version, AppSettings, Parser};
|
use clap::Parser;
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
|
@ -7,16 +7,10 @@ pub enum Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[clap(
|
|
||||||
version = crate_version!(),
|
|
||||||
author = crate_authors!(", "),
|
|
||||||
global_setting = AppSettings::InferSubcommands,
|
|
||||||
global_setting = AppSettings::PropagateVersion,
|
|
||||||
)]
|
|
||||||
pub struct Opts {
|
pub struct Opts {
|
||||||
/// Provide a path to the configuration file
|
/// Provide a path to the configuration file
|
||||||
#[clap(short, long, value_name = "FILE")]
|
#[arg(short, long, value_name = "FILE")]
|
||||||
pub config: Option<String>,
|
pub config: Option<String>,
|
||||||
#[clap(subcommand)]
|
#[command(subcommand)]
|
||||||
pub command: Option<Command>,
|
pub command: Option<Command>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
Config, Metrics, WebhookeyError,
|
Config, Metrics, WebhookeyError,
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, bail, Result};
|
use anyhow::{anyhow, bail, Result};
|
||||||
use hmac::{Hmac, Mac, NewMac};
|
use hmac::{Hmac, Mac};
|
||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
use rocket::{
|
use rocket::{
|
||||||
data::{FromData, ToByteUnit},
|
data::{FromData, ToByteUnit},
|
||||||
|
@ -44,7 +44,8 @@ fn validate_request(secret: &str, signature: &str, data: &[u8]) -> Result<()> {
|
||||||
.map_err(|e| anyhow!("Could not create hasher with secret: {}", e))?;
|
.map_err(|e| anyhow!("Could not create hasher with secret: {}", e))?;
|
||||||
mac.update(data);
|
mac.update(data);
|
||||||
let raw_signature = hex::decode(signature.as_bytes())?;
|
let raw_signature = hex::decode(signature.as_bytes())?;
|
||||||
mac.verify(&raw_signature).map_err(|e| anyhow!("{}", e))
|
mac.verify_slice(&raw_signature)
|
||||||
|
.map_err(|e| anyhow!("{}", e))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
@ -87,7 +88,7 @@ impl Hook {
|
||||||
if let Some('}') = command_template.next() {
|
if let Some('}') = command_template.next() {
|
||||||
let expr = token.trim().split(' ').collect::<Vec<&str>>();
|
let expr = token.trim().split(' ').collect::<Vec<&str>>();
|
||||||
|
|
||||||
let replaced = match expr.get(0) {
|
let replaced = match expr.first() {
|
||||||
Some(&"header") => get_header_field(
|
Some(&"header") => get_header_field(
|
||||||
headers,
|
headers,
|
||||||
expr.get(1).ok_or_else(|| {
|
expr.get(1).ok_or_else(|| {
|
||||||
|
@ -315,6 +316,8 @@ pub async fn receive_hook<'a>(
|
||||||
.fetch_add(1, Ordering::Relaxed);
|
.fetch_add(1, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
metrics.hooks_successful.fetch_add(1, Ordering::Relaxed);
|
||||||
});
|
});
|
||||||
|
|
||||||
Status::Ok
|
Status::Ok
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
#[cfg(target_os = "hermit")]
|
|
||||||
extern crate hermit_sys;
|
|
||||||
|
|
||||||
mod cli;
|
mod cli;
|
||||||
mod config;
|
mod config;
|
||||||
mod filters;
|
mod filters;
|
||||||
|
@ -26,9 +23,9 @@ pub enum WebhookeyError {
|
||||||
#[error("Could not evaluate filter request")]
|
#[error("Could not evaluate filter request")]
|
||||||
InvalidFilter,
|
InvalidFilter,
|
||||||
#[error("IO Error")]
|
#[error("IO Error")]
|
||||||
Io(std::io::Error),
|
Io(#[from] std::io::Error),
|
||||||
#[error("Serde Error")]
|
#[error("Serde Error")]
|
||||||
Serde(serde_json::Error),
|
Serde(#[from] serde_json::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_string(data: &serde_json::Value) -> Result<String, WebhookeyError> {
|
pub fn get_string(data: &serde_json::Value) -> Result<String, WebhookeyError> {
|
||||||
|
|
Loading…
Reference in a new issue