From ab5db8adeda9a517210f80a94987a6df7afb00fc Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 14 Jul 2024 16:13:06 -0400 Subject: [PATCH] Add a webhook endpoint. --- src/main.rs | 6 ++ src/webhook.rs | 12 +++ test_webhook.bash | 224 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 242 insertions(+) create mode 100644 src/webhook.rs create mode 100755 test_webhook.bash diff --git a/src/main.rs b/src/main.rs index f679429..3ac9486 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use axum::http::StatusCode; use axum::routing::get; +use axum::routing::post; use axum::Json; use axum::Router; use serde::Serialize; @@ -7,6 +8,10 @@ use tower_http::trace::TraceLayer; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; +use self::webhook::hook; + +mod webhook; + #[tokio::main] async fn main() -> Result<(), Box> { tracing_subscriber::registry() @@ -19,6 +24,7 @@ async fn main() -> Result<(), Box> { .init(); let app = Router::new() .route("/health", get(health)) + .route("/hook", post(hook)) .layer(TraceLayer::new_for_http()); let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await?; diff --git a/src/webhook.rs b/src/webhook.rs new file mode 100644 index 0000000..a1010a2 --- /dev/null +++ b/src/webhook.rs @@ -0,0 +1,12 @@ +use axum::http::StatusCode; +use axum::Json; +use serde::Serialize; + +pub(crate) async fn hook() -> (StatusCode, Json) { + (StatusCode::OK, Json(HookResponse { ok: true })) +} + +#[derive(Serialize)] +pub(crate) struct HookResponse { + ok: bool, +} diff --git a/test_webhook.bash b/test_webhook.bash new file mode 100755 index 0000000..9c89f06 --- /dev/null +++ b/test_webhook.bash @@ -0,0 +1,224 @@ +#!/usr/bin/env bash +# +set -euo pipefail +IFS=$'\n\t' +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +function main() { + local payload + payload=$(cat <