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
| Name | Type | Description |
|---|---|---|
id | Uuid | Unique identifier for this event (idempotency key). |
event_type | String | Event type (e.g., “deployment.applied”). |
timestamp | DateTime < Utc > | When the event occurred. |
data | serde_json :: Value | Event-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
| Name | Type | Description |
|---|---|---|
agent_id | Option < Uuid > | Filter by specific agent ID. |
stack_id | Option < Uuid > | Filter by specific stack ID. |
labels | Option < 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
| Name | Type | Description |
|---|---|---|
id | Uuid | Unique identifier for the subscription. |
name | String | Human-readable name for the subscription. |
url_encrypted | Vec < u8 > | Encrypted webhook URL. |
auth_header_encrypted | Option < Vec < u8 > > | Encrypted Authorization header value. |
event_types | Vec < Option < String > > | Event types to subscribe to (supports wildcards like “deployment.*”). |
filters | Option < String > | JSON-encoded filters. |
target_labels | Option < Vec < Option < String > > > | Labels for delivery targeting (NULL = broker delivers). |
enabled | bool | Whether the subscription is active. |
max_retries | i32 | Maximum delivery retry attempts. |
timeout_seconds | i32 | HTTP request timeout in seconds. |
created_at | DateTime < Utc > | When the subscription was created. |
updated_at | DateTime < Utc > | When the subscription was last updated. |
created_by | Option < 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
| Name | Type | Description |
|---|---|---|
name | String | Human-readable name. |
url_encrypted | Vec < u8 > | Encrypted webhook URL. |
auth_header_encrypted | Option < Vec < u8 > > | Encrypted Authorization header value. |
event_types | Vec < Option < String > > | Event types to subscribe to. |
filters | Option < String > | JSON-encoded filters. |
target_labels | Option < Vec < Option < String > > > | Labels for delivery targeting (NULL = broker delivers). |
enabled | bool | Whether the subscription is active (defaults to true). |
max_retries | i32 | Maximum retry attempts (defaults to 5). |
timeout_seconds | i32 | HTTP timeout in seconds (defaults to 30). |
created_by | Option < 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:
| Name | Type | Description |
|---|---|---|
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
| Name | Type | Description |
|---|---|---|
name | Option < String > | New name. |
url_encrypted | Option < Vec < u8 > > | New encrypted URL. |
auth_header_encrypted | Option < Option < Vec < u8 > > > | New encrypted auth header. |
event_types | Option < Vec < Option < String > > > | New event types. |
filters | Option < Option < String > > | New filters. |
target_labels | Option < Option < Vec < Option < String > > > > | New target labels for delivery. |
enabled | Option < bool > | Enable/disable. |
max_retries | Option < i32 > | New max retries. |
timeout_seconds | Option < 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
| Name | Type | Description |
|---|---|---|
id | Uuid | Unique identifier for the delivery. |
subscription_id | Uuid | The subscription this delivery belongs to. |
event_type | String | The event type being delivered. |
event_id | Uuid | The event ID (idempotency key). |
payload | String | JSON-encoded event payload. |
target_labels | Option < Vec < Option < String > > > | Labels for delivery targeting (copied from subscription). |
status | String | Delivery status: pending, acquired, success, failed, dead. |
acquired_by | Option < Uuid > | Agent ID that acquired this delivery (NULL = broker). |
acquired_until | Option < DateTime < Utc > > | TTL for the acquisition - release if exceeded. |
attempts | i32 | Number of delivery attempts. |
last_attempt_at | Option < DateTime < Utc > > | When the last delivery attempt was made. |
next_retry_at | Option < DateTime < Utc > > | When to retry after failure. |
last_error | Option < String > | Error message from last failed attempt. |
created_at | DateTime < Utc > | When the delivery was created. |
completed_at | Option < 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
| Name | Type | Description |
|---|---|---|
subscription_id | Uuid | The subscription to deliver to. |
event_type | String | The event type. |
event_id | Uuid | The event ID. |
payload | String | JSON-encoded payload. |
target_labels | Option < Vec < Option < String > > > | Labels for delivery targeting (copied from subscription). |
status | String | Initial 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:
| Name | Type | Description |
|---|---|---|
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
| Name | Type | Description |
|---|---|---|
status | Option < String > | New status. |
acquired_by | Option < Option < Uuid > > | Agent that acquired this delivery. |
acquired_until | Option < Option < DateTime < Utc > > > | TTL for the acquisition. |
attempts | Option < i32 > | Increment attempts. |
last_attempt_at | Option < DateTime < Utc > > | When last attempted. |
next_retry_at | Option < Option < DateTime < Utc > > > | When to retry. |
last_error | Option < Option < String > > | Error message. |
completed_at | Option < DateTime < Utc > > | When completed. |