Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

brokkr-models::models::webhooks Rust

Webhook models for event notifications.

This module provides models for webhook subscriptions and deliveries, enabling external systems to receive notifications when events occur in Brokkr.

Structs

brokkr-models::models::webhooks::BrokkrEvent

pub

Derives: Debug, Clone, Serialize, Deserialize, ToSchema

A Brokkr event that can trigger webhook deliveries.

Fields

NameTypeDescription
idUuidUnique identifier for this event (idempotency key).
event_typeStringEvent type (e.g., “deployment.applied”).
timestampDateTime < Utc >When the event occurred.
dataserde_json :: ValueEvent-specific data.

Methods

new pub
#![allow(unused)]
fn main() {
fn new (event_type : & str , data : serde_json :: Value) -> Self
}

Creates a new event.

Source
#![allow(unused)]
fn main() {
    pub fn new(event_type: &str, data: serde_json::Value) -> Self {
        Self {
            id: Uuid::new_v4(),
            event_type: event_type.to_string(),
            timestamp: Utc::now(),
            data,
        }
    }
}

brokkr-models::models::webhooks::WebhookFilters

pub

Derives: Debug, Clone, Default, Serialize, Deserialize, ToSchema

Filters for webhook subscriptions.

Fields

NameTypeDescription
agent_idOption < Uuid >Filter by specific agent ID.
stack_idOption < Uuid >Filter by specific stack ID.
labelsOption < std :: collections :: HashMap < String , String > >Filter by labels (all must match).

brokkr-models::models::webhooks::WebhookSubscription

pub

Derives: Debug, Clone, Queryable, Selectable, Identifiable, Serialize, Deserialize, ToSchema

A webhook subscription record from the database.

Fields

NameTypeDescription
idUuidUnique identifier for the subscription.
nameStringHuman-readable name for the subscription.
url_encryptedVec < u8 >Encrypted webhook URL.
auth_header_encryptedOption < Vec < u8 > >Encrypted Authorization header value.
event_typesVec < Option < String > >Event types to subscribe to (supports wildcards like “deployment.*”).
filtersOption < String >JSON-encoded filters.
target_labelsOption < Vec < Option < String > > >Labels for delivery targeting (NULL = broker delivers).
enabledboolWhether the subscription is active.
max_retriesi32Maximum delivery retry attempts.
timeout_secondsi32HTTP request timeout in seconds.
created_atDateTime < Utc >When the subscription was created.
updated_atDateTime < Utc >When the subscription was last updated.
created_byOption < String >Who created the subscription.

brokkr-models::models::webhooks::NewWebhookSubscription

pub

Derives: Debug, Clone, Insertable, Serialize, Deserialize

A new webhook subscription to be inserted.

Fields

NameTypeDescription
nameStringHuman-readable name.
url_encryptedVec < u8 >Encrypted webhook URL.
auth_header_encryptedOption < Vec < u8 > >Encrypted Authorization header value.
event_typesVec < Option < String > >Event types to subscribe to.
filtersOption < String >JSON-encoded filters.
target_labelsOption < Vec < Option < String > > >Labels for delivery targeting (NULL = broker delivers).
enabledboolWhether the subscription is active (defaults to true).
max_retriesi32Maximum retry attempts (defaults to 5).
timeout_secondsi32HTTP timeout in seconds (defaults to 30).
created_byOption < String >Who created the subscription.

Methods

new pub
#![allow(unused)]
fn main() {
fn new (name : String , url_encrypted : Vec < u8 > , auth_header_encrypted : Option < Vec < u8 > > , event_types : Vec < String > , filters : Option < WebhookFilters > , target_labels : Option < Vec < String > > , created_by : Option < String > ,) -> Result < Self , String >
}

Creates a new webhook subscription.

Parameters:

NameTypeDescription
name-Human-readable name for the subscription.
url_encrypted-Pre-encrypted webhook URL.
auth_header_encrypted-Pre-encrypted Authorization header (optional).
event_types-List of event types to subscribe to.
filters-Optional filters as WebhookFilters struct.
target_labels-Optional labels for delivery targeting.
created_by-Who is creating the subscription.

Returns:

A Result containing the new subscription or an error.

Source
#![allow(unused)]
fn main() {
    pub fn new(
        name: String,
        url_encrypted: Vec<u8>,
        auth_header_encrypted: Option<Vec<u8>>,
        event_types: Vec<String>,
        filters: Option<WebhookFilters>,
        target_labels: Option<Vec<String>>,
        created_by: Option<String>,
    ) -> Result<Self, String> {
        // Validate name
        if name.trim().is_empty() {
            return Err("Name cannot be empty".to_string());
        }
        if name.len() > 255 {
            return Err("Name cannot exceed 255 characters".to_string());
        }

        // Validate event types
        if event_types.is_empty() {
            return Err("At least one event type is required".to_string());
        }

        // Serialize filters to JSON if provided
        let filters_json = filters
            .map(|f| serde_json::to_string(&f))
            .transpose()
            .map_err(|e| format!("Failed to serialize filters: {}", e))?;

        Ok(Self {
            name,
            url_encrypted,
            auth_header_encrypted,
            event_types: event_types.into_iter().map(Some).collect(),
            filters: filters_json,
            target_labels: target_labels.map(|labels| labels.into_iter().map(Some).collect()),
            enabled: true,
            max_retries: 5,
            timeout_seconds: 30,
            created_by,
        })
    }
}

brokkr-models::models::webhooks::UpdateWebhookSubscription

pub

Derives: Debug, Clone, Default, AsChangeset

Changeset for updating a webhook subscription.

Fields

NameTypeDescription
nameOption < String >New name.
url_encryptedOption < Vec < u8 > >New encrypted URL.
auth_header_encryptedOption < Option < Vec < u8 > > >New encrypted auth header.
event_typesOption < Vec < Option < String > > >New event types.
filtersOption < Option < String > >New filters.
target_labelsOption < Option < Vec < Option < String > > > >New target labels for delivery.
enabledOption < bool >Enable/disable.
max_retriesOption < i32 >New max retries.
timeout_secondsOption < i32 >New timeout.

brokkr-models::models::webhooks::WebhookDelivery

pub

Derives: Debug, Clone, Queryable, Selectable, Identifiable, Serialize, Deserialize, ToSchema

A webhook delivery record from the database.

Fields

NameTypeDescription
idUuidUnique identifier for the delivery.
subscription_idUuidThe subscription this delivery belongs to.
event_typeStringThe event type being delivered.
event_idUuidThe event ID (idempotency key).
payloadStringJSON-encoded event payload.
target_labelsOption < Vec < Option < String > > >Labels for delivery targeting (copied from subscription).
statusStringDelivery status: pending, acquired, success, failed, dead.
acquired_byOption < Uuid >Agent ID that acquired this delivery (NULL = broker).
acquired_untilOption < DateTime < Utc > >TTL for the acquisition - release if exceeded.
attemptsi32Number of delivery attempts.
last_attempt_atOption < DateTime < Utc > >When the last delivery attempt was made.
next_retry_atOption < DateTime < Utc > >When to retry after failure.
last_errorOption < String >Error message from last failed attempt.
created_atDateTime < Utc >When the delivery was created.
completed_atOption < DateTime < Utc > >When the delivery completed (success or dead).

brokkr-models::models::webhooks::NewWebhookDelivery

pub

Derives: Debug, Clone, Insertable, Serialize, Deserialize

A new webhook delivery to be inserted.

Fields

NameTypeDescription
subscription_idUuidThe subscription to deliver to.
event_typeStringThe event type.
event_idUuidThe event ID.
payloadStringJSON-encoded payload.
target_labelsOption < Vec < Option < String > > >Labels for delivery targeting (copied from subscription).
statusStringInitial status (pending).

Methods

new pub
#![allow(unused)]
fn main() {
fn new (subscription_id : Uuid , event : & BrokkrEvent , target_labels : Option < Vec < Option < String > > > ,) -> Result < Self , String >
}

Creates a new webhook delivery.

Parameters:

NameTypeDescription
subscription_id-The subscription to deliver to.
event-The event to deliver.
target_labels-Labels for delivery targeting (from subscription).

Returns:

A Result containing the new delivery or an error.

Source
#![allow(unused)]
fn main() {
    pub fn new(
        subscription_id: Uuid,
        event: &BrokkrEvent,
        target_labels: Option<Vec<Option<String>>>,
    ) -> Result<Self, String> {
        if subscription_id.is_nil() {
            return Err("Subscription ID cannot be nil".to_string());
        }

        let payload = serde_json::to_string(event)
            .map_err(|e| format!("Failed to serialize event: {}", e))?;

        Ok(Self {
            subscription_id,
            event_type: event.event_type.clone(),
            event_id: event.id,
            payload,
            target_labels,
            status: DELIVERY_STATUS_PENDING.to_string(),
        })
    }
}

brokkr-models::models::webhooks::UpdateWebhookDelivery

pub

Derives: Debug, Clone, Default, AsChangeset

Changeset for updating a webhook delivery.

Fields

NameTypeDescription
statusOption < String >New status.
acquired_byOption < Option < Uuid > >Agent that acquired this delivery.
acquired_untilOption < Option < DateTime < Utc > > >TTL for the acquisition.
attemptsOption < i32 >Increment attempts.
last_attempt_atOption < DateTime < Utc > >When last attempted.
next_retry_atOption < Option < DateTime < Utc > > >When to retry.
last_errorOption < Option < String > >Error message.
completed_atOption < DateTime < Utc > >When completed.