pub struct WebhookRegistry {
pub max_retry_attempts: u32,
/* private fields */
}Expand description
Webhook registry — manages webhook CRUD and delivery logging.
Fields§
§max_retry_attempts: u32Max retry attempts before dead-lettering (default 5).
Implementations§
Source§impl WebhookRegistry
impl WebhookRegistry
Sourcepub fn register(
&mut self,
name: &str,
url: &str,
events: Vec<String>,
secret: Option<String>,
) -> String
pub fn register( &mut self, name: &str, url: &str, events: Vec<String>, secret: Option<String>, ) -> String
Register a new webhook. Returns the assigned ID.
Sourcepub fn register_with_template(
&mut self,
name: &str,
url: &str,
events: Vec<String>,
secret: Option<String>,
template: Option<String>,
) -> String
pub fn register_with_template( &mut self, name: &str, url: &str, events: Vec<String>, secret: Option<String>, template: Option<String>, ) -> String
Register a new webhook with optional payload template. Returns the assigned ID.
Sourcepub fn unregister(&mut self, id: &str) -> bool
pub fn unregister(&mut self, id: &str) -> bool
Unregister a webhook by ID. Returns true if found and removed.
Sourcepub fn get(&self, id: &str) -> Option<&WebhookConfig>
pub fn get(&self, id: &str) -> Option<&WebhookConfig>
Get a webhook by ID.
Sourcepub fn toggle(&mut self, id: &str) -> Option<bool>
pub fn toggle(&mut self, id: &str) -> Option<bool>
Toggle active state. Returns new state if found.
Sourcepub fn get_filters(&self, id: &str) -> Option<&Vec<String>>
pub fn get_filters(&self, id: &str) -> Option<&Vec<String>>
Get the event filters for a webhook.
Sourcepub fn set_filters(&mut self, id: &str, events: Vec<String>) -> bool
pub fn set_filters(&mut self, id: &str, events: Vec<String>) -> bool
Set the event filters for a webhook. Returns true if found.
Sourcepub fn list(&self) -> Vec<WebhookSummary>
pub fn list(&self) -> Vec<WebhookSummary>
List all webhooks as summaries (secrets masked).
Sourcepub fn match_topic(&self, topic: &str) -> Vec<String>
pub fn match_topic(&self, topic: &str) -> Vec<String>
Check which webhooks match a given event topic. Returns IDs of matching active webhooks.
Sourcepub fn dispatch(
&mut self,
topic: &str,
_payload: &Value,
_source: &str,
) -> DispatchResult
pub fn dispatch( &mut self, topic: &str, _payload: &Value, _source: &str, ) -> DispatchResult
Dispatch an event: find matching webhooks and record pending deliveries. Returns dispatch result with matched webhook IDs. Actual HTTP delivery is NOT performed here (that’s async/external).
Sourcepub fn record_delivery(&mut self, delivery: WebhookDelivery)
pub fn record_delivery(&mut self, delivery: WebhookDelivery)
Record a delivery result (used after actual HTTP attempt).
Sourcepub fn record_completed(
&mut self,
webhook_id: &str,
topic: &str,
status_code: u16,
latency_ms: u64,
error: Option<String>,
attempt: u32,
)
pub fn record_completed( &mut self, webhook_id: &str, topic: &str, status_code: u16, latency_ms: u64, error: Option<String>, attempt: u32, )
Record a completed delivery (success or failure after HTTP attempt).
Sourcepub fn recent_deliveries(
&self,
limit: usize,
webhook_id: Option<&str>,
) -> Vec<&WebhookDelivery>
pub fn recent_deliveries( &self, limit: usize, webhook_id: Option<&str>, ) -> Vec<&WebhookDelivery>
Get recent deliveries, optionally filtered by webhook ID.
Sourcepub fn stats(&self) -> WebhookStats
pub fn stats(&self) -> WebhookStats
Aggregate statistics.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Number of active webhooks.
Sourcepub fn enqueue_retry(
&mut self,
webhook_id: &str,
topic: &str,
error: &str,
attempt: u32,
) -> bool
pub fn enqueue_retry( &mut self, webhook_id: &str, topic: &str, error: &str, attempt: u32, ) -> bool
Enqueue a failed delivery for retry with exponential backoff. Returns true if enqueued, false if max attempts exceeded (dead-lettered).
Sourcepub fn drain_due_retries(&mut self) -> Vec<RetryEntry>
pub fn drain_due_retries(&mut self) -> Vec<RetryEntry>
Get due retries (next_retry_at <= now). Removes them from the queue.
Sourcepub fn retry_queue(&self) -> &[RetryEntry]
pub fn retry_queue(&self) -> &[RetryEntry]
View the retry queue (read-only).
Sourcepub fn dead_letters(&self) -> &[DeadLetterEntry]
pub fn dead_letters(&self) -> &[DeadLetterEntry]
View the dead letter queue (read-only).
Sourcepub fn retry_queue_len(&self) -> usize
pub fn retry_queue_len(&self) -> usize
Number of entries in the retry queue.
Sourcepub fn dead_letters_len(&self) -> usize
pub fn dead_letters_len(&self) -> usize
Number of entries in the dead letter queue.
Sourcepub fn compute_signature(secret: &str, payload: &[u8]) -> String
pub fn compute_signature(secret: &str, payload: &[u8]) -> String
Compute the HMAC-SHA256 signature of a payload, hex-encoded
and prefixed sha256= — the GitHub / Stripe webhook-signature
convention that every off-the-shelf verification library
(hmac in Python, crypto.createHmac in Node, etc.) expects.
secret— the webhook’s shared secret, used verbatim as the HMAC key. HMAC accepts a key of any length (RFC 2104 hashes keys longer than the block size + zero-pads shorter ones), so no key-length precondition is imposed on adopters.payload— the EXACT request-body bytes the receiver will see; the receiver recomputesHMAC-SHA256(secret, body)and compares. UseSelf::verify_signaturefor the receiving side — it does the comparison in constant time.
The output is "sha256=" followed by 64 lowercase hex digits
(256-bit digest). This is a real keyed MAC: without the secret
an attacker cannot forge a signature for a chosen payload.
Sourcepub fn verify_signature(secret: &str, payload: &[u8], provided: &str) -> bool
pub fn verify_signature(secret: &str, payload: &[u8], provided: &str) -> bool
Verify a webhook signature against a payload, in constant time.
Recomputes HMAC-SHA256(secret, payload) and compares it
against provided — the value an inbound caller supplied
(e.g. an X-Axon-Signature header) — using a constant-time
equality check. The constant-time compare denies a network
attacker the timing side-channel that a byte-by-byte
== comparison would leak (which would let them recover the
correct signature one byte at a time).
Returns true iff provided is exactly the correct
signature. A length mismatch returns false immediately —
the signature LENGTH is public (it is always
"sha256=" + 64 hex), so short-circuiting on it leaks
nothing secret.
Sourcepub fn set_template(&mut self, id: &str, template: Option<String>) -> bool
pub fn set_template(&mut self, id: &str, template: Option<String>) -> bool
Set a payload template for a webhook. Returns true if webhook found.
Auto Trait Implementations§
impl Freeze for WebhookRegistry
impl RefUnwindSafe for WebhookRegistry
impl Send for WebhookRegistry
impl Sync for WebhookRegistry
impl Unpin for WebhookRegistry
impl UnsafeUnpin for WebhookRegistry
impl UnwindSafe for WebhookRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more