Skip to main content

WebhookRegistry

Struct WebhookRegistry 

Source
pub struct WebhookRegistry {
    pub max_retry_attempts: u32,
    /* private fields */
}
Expand description

Webhook registry — manages webhook CRUD and delivery logging.

Fields§

§max_retry_attempts: u32

Max retry attempts before dead-lettering (default 5).

Implementations§

Source§

impl WebhookRegistry

Source

pub fn new() -> Self

Create a new empty registry.

Source

pub fn register( &mut self, name: &str, url: &str, events: Vec<String>, secret: Option<String>, ) -> String

Register a new webhook. Returns the assigned ID.

Source

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.

Source

pub fn unregister(&mut self, id: &str) -> bool

Unregister a webhook by ID. Returns true if found and removed.

Source

pub fn get(&self, id: &str) -> Option<&WebhookConfig>

Get a webhook by ID.

Source

pub fn toggle(&mut self, id: &str) -> Option<bool>

Toggle active state. Returns new state if found.

Source

pub fn get_filters(&self, id: &str) -> Option<&Vec<String>>

Get the event filters for a webhook.

Source

pub fn set_filters(&mut self, id: &str, events: Vec<String>) -> bool

Set the event filters for a webhook. Returns true if found.

Source

pub fn list(&self) -> Vec<WebhookSummary>

List all webhooks as summaries (secrets masked).

Source

pub fn match_topic(&self, topic: &str) -> Vec<String>

Check which webhooks match a given event topic. Returns IDs of matching active webhooks.

Source

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).

Source

pub fn record_delivery(&mut self, delivery: WebhookDelivery)

Record a delivery result (used after actual HTTP attempt).

Source

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).

Source

pub fn recent_deliveries( &self, limit: usize, webhook_id: Option<&str>, ) -> Vec<&WebhookDelivery>

Get recent deliveries, optionally filtered by webhook ID.

Source

pub fn stats(&self) -> WebhookStats

Aggregate statistics.

Source

pub fn count(&self) -> usize

Number of registered webhooks.

Source

pub fn active_count(&self) -> usize

Number of active webhooks.

Source

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).

Source

pub fn drain_due_retries(&mut self) -> Vec<RetryEntry>

Get due retries (next_retry_at <= now). Removes them from the queue.

Source

pub fn retry_queue(&self) -> &[RetryEntry]

View the retry queue (read-only).

Source

pub fn dead_letters(&self) -> &[DeadLetterEntry]

View the dead letter queue (read-only).

Source

pub fn retry_queue_len(&self) -> usize

Number of entries in the retry queue.

Source

pub fn dead_letters_len(&self) -> usize

Number of entries in the dead letter queue.

Source

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 recomputes HMAC-SHA256(secret, body) and compares. Use Self::verify_signature for 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.

Source

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.

Source

pub fn set_template(&mut self, id: &str, template: Option<String>) -> bool

Set a payload template for a webhook. Returns true if webhook found.

Source

pub fn get_template(&self, id: &str) -> Option<Option<&str>>

Get the payload template for a webhook.

Source

pub fn render_payload( &self, webhook_id: &str, topic: &str, payload: &Value, source: &str, ) -> Value

Render a payload using a webhook’s template (if set).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more