Add signature verification middleware.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use axum::http::StatusCode;
|
||||
use axum::middleware;
|
||||
use axum::routing::get;
|
||||
use axum::routing::post;
|
||||
use axum::Json;
|
||||
@@ -15,6 +16,7 @@ use tracing_subscriber::layer::SubscriberExt;
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
|
||||
use self::webhook::hook;
|
||||
use self::webhook::verify_signature;
|
||||
|
||||
mod hook_push;
|
||||
mod webhook;
|
||||
@@ -35,15 +37,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.expect("Set KUBECONFIG to a valid kubernetes config.");
|
||||
|
||||
let app = Router::new()
|
||||
.route("/health", get(health))
|
||||
.route("/hook", post(hook))
|
||||
.layer(middleware::from_fn(verify_signature))
|
||||
.route("/health", get(health))
|
||||
.layer((
|
||||
TraceLayer::new_for_http(),
|
||||
// Add a timeout layer so graceful shutdown can't wait forever.
|
||||
TimeoutLayer::new(Duration::from_secs(600)),
|
||||
));
|
||||
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await?;
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:9988").await?;
|
||||
tracing::info!("listening on {}", listener.local_addr().unwrap());
|
||||
axum::serve(listener, app)
|
||||
.with_graceful_shutdown(shutdown_signal())
|
||||
|
||||
Reference in New Issue
Block a user