Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

refactor: extract deliver_webhook into shared webhook module

FABIOTESS31dc2dc47378
diff --git a/src/lib.rs b/src/lib.rs
index ac3c05aa..d6e1ec35 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -11,6 +11,7 @@ pub mod inputs;
pub mod lineage;
pub mod monitor;
pub mod plan;
+pub mod webhook;
pub mod mapping;
pub mod marketplace;
pub mod ontology;
diff --git a/src/monitor.rs b/src/monitor.rs
index 96bf24b3..ce07292d 100644
--- a/src/monitor.rs
+++ b/src/monitor.rs
@@ -2,7 +2,7 @@ use crate::graph::GraphStore;
use crate::state::StateDb;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
-use std::time::Duration;
+
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum WatcherAction {
@@ -103,7 +103,7 @@ impl Monitor {
"timestamp": chrono::Utc::now().to_rfc3339(),
});
tokio::spawn(async move {
- let _ = deliver_webhook(&url, headers.as_deref(), &payload).await;
+ let _ = crate::webhook::deliver_webhook(&url, headers.as_deref(), &payload).await;
});
}
}
@@ -219,28 +219,3 @@ impl Monitor {
}
}
}
-
-/// Fire-and-forget webhook delivery with 10s timeout.
-async fn deliver_webhook(
- url: &str,
- headers_json: Option<&str>,
- payload: &serde_json::Value,
-) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
- let client = reqwest::Client::builder()
- .timeout(Duration::from_secs(10))
- .build()?;
- let mut req = client.post(url).json(payload);
- if let Some(hdr_json) = headers_json {
- if let Ok(map) = serde_json::from_str::<std::collections::HashMap<String, String>>(hdr_json) {
- for (k, v) in map {
- req = req.header(&k, &v);
- }
- }
- }
- let resp = req.send().await?;
- let status = resp.status();
- if !status.is_success() {
- eprintln!("Webhook to {} returned {}", url, status);
- }
- Ok(())
-}
diff --git a/src/webhook.rs b/src/webhook.rs
new file mode 100644
index 00000000..65aebca8
--- /dev/null
+++ b/src/webhook.rs
@@ -0,0 +1,26 @@
+use std::time::Duration;
+
+/// Fire-and-forget webhook delivery with 10s timeout.
+pub async fn deliver_webhook(
+ url: &str,
+ headers_json: Option<&str>,
+ payload: &serde_json::Value,
+) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
+ let client = reqwest::Client::builder()
+ .timeout(Duration::from_secs(10))
+ .build()?;
+ let mut req = client.post(url).json(payload);
+ if let Some(hdr_json) = headers_json {
+ if let Ok(map) = serde_json::from_str::<std::collections::HashMap<String, String>>(hdr_json) {
+ for (k, v) in map {
+ req = req.header(&k, &v);
+ }
+ }
+ }
+ let resp = req.send().await?;
+ let status = resp.status();
+ if !status.is_success() {
+ eprintln!("Webhook to {} returned {}", url, status);
+ }
+ Ok(())
+}