webhooks

package
v1.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorCodeRequired      = "REQUIRED"
	ErrorCodeInvalidFormat = "INVALID_FORMAT"
	ErrorCodeTooLong       = "TOO_LONG"
	ErrorCodeTooShort      = "TOO_SHORT"
	ErrorCodeInvalid       = "INVALID"
	ErrorCodeNotFound      = "NOT_FOUND"
	ErrorCodeDuplicate     = "DUPLICATE"
	ErrorCodeForbidden     = "FORBIDDEN"
)

Validation error codes

View Source
const (
	MsgRequired           = "field is required"
	MsgInvalidNamespace   = "namespace must be a valid identifier (alphanumeric, hyphens, underscores)"
	MsgInvalidURL         = "must be a valid HTTP or HTTPS URL"
	MsgInvalidTimeout     = "timeout must be between 1 and 300 seconds"
	MsgInvalidEvent       = "event name must be a valid identifier"
	MsgTooManyEvents      = "maximum 50 events allowed per webhook"
	MsgHeadersTooLarge    = "headers total size must not exceed 8KB"
	MsgPayloadTooLarge    = "payload size must not exceed 1MB"
	MsgInvalidJSON        = "must be valid JSON"
	MsgNamespaceTooLong   = "namespace must not exceed 64 characters"
	MsgDescriptionTooLong = "description must not exceed 500 characters"
)

Common validation messages

Variables

This section is empty.

Functions

func ValidateJSONSchema

func ValidateJSONSchema(schema map[string]any, payload map[string]any) error

ValidateJSONSchema validates a payload against a JSON schema string. Returns a SchemaValidationError with detailed per-field errors on failure.

func ValidateWebhookURL added in v0.2.0

func ValidateWebhookURL(rawURL string, allowPrivateNetworks bool) error

ValidateWebhookURL validates a webhook URL to prevent SSRF attacks. It ensures the URL:

  • Uses http or https scheme only
  • Does not point to loopback, private, or link-local addresses
  • Does not target cloud metadata endpoints
  • Has a valid, non-empty host

All errors returned are *svcerrors.ServiceError with codes.InvalidArgument, so they propagate through toGRPCError to the client as actionable messages.

Types

type HTTPConfigUpdate added in v0.2.0

type HTTPConfigUpdate struct {
	MaxRetries            int
	RetryBackoffSeconds   int
	CaptureResponseBody   bool
	FollowRedirects       bool
	VerifySSL             bool
	RequestTimeoutSeconds int
	ExpectedStatusCodes   []int
	WebhookSecret         string
	UserAgent             string
	ContentType           string
	RateLimitRPS          *float64
}

HTTPConfigUpdate represents HTTP configuration fields that can be updated. Used as an optional parameter in UpdateWebhookConfig to apply http_config changes.

type HealthSummaryData

type HealthSummaryData struct {
	HealthyCount   int `json:"healthy_count"`
	DegradedCount  int `json:"degraded_count"`
	UnhealthyCount int `json:"unhealthy_count"`
	UnknownCount   int `json:"unknown_count"`
	TotalCount     int `json:"total_count"`
}

HealthSummaryData represents health summary information

type IntArray added in v0.2.0

type IntArray []int

IntArray is a wrapper for PostgreSQL integer arrays

func (*IntArray) Scan added in v0.2.0

func (a *IntArray) Scan(value any) error

Scan implements the sql.Scanner interface

func (IntArray) Value added in v0.2.0

func (a IntArray) Value() (driver.Value, error)

Value implements the driver.Valuer interface

type JSONBMap added in v0.2.0

type JSONBMap map[string]any

JSONBMap is a wrapper for PostgreSQL JSONB maps

func (*JSONBMap) Scan added in v0.2.0

func (m *JSONBMap) Scan(value any) error

Scan implements the sql.Scanner interface

func (JSONBMap) Value added in v0.2.0

func (m JSONBMap) Value() (driver.Value, error)

Value implements the driver.Valuer interface

type NamespaceStatsData

type NamespaceStatsData struct {
	TotalWebhooks        int     `json:"total_webhooks"`
	ActiveWebhooks       int     `json:"active_webhooks"`
	TotalDeliveries      int     `json:"total_deliveries"`
	SuccessfulDeliveries int     `json:"successful_deliveries"`
	FailedDeliveries     int     `json:"failed_deliveries"`
	PendingDeliveries    int     `json:"pending_deliveries"`
	SuccessRate          float64 `json:"success_rate"`
}

NamespaceStatsData represents namespace statistics

type SchemaValidationError added in v0.2.0

type SchemaValidationError struct {
	Message string            `json:"message"`
	Details map[string]string `json:"details"` // field path -> error message
}

SchemaValidationError represents a structured schema validation failure with per-field error details that can be displayed to the user.

func (*SchemaValidationError) Error added in v0.2.0

func (e *SchemaValidationError) Error() string

func (*SchemaValidationError) Warnings added in v0.8.0

func (e *SchemaValidationError) Warnings() []string

Warnings returns per-field validation messages suitable for API responses. Each warning is a human-readable string describing a specific validation failure.

type StringArray added in v0.2.0

type StringArray []string

StringArray is a wrapper for PostgreSQL string arrays

func (*StringArray) Scan added in v0.2.0

func (a *StringArray) Scan(value any) error

Scan implements the sql.Scanner interface

func (StringArray) Value added in v0.2.0

func (a StringArray) Value() (driver.Value, error)

Value implements the driver.Valuer interface

type TemplateFunctionInfo added in v0.2.0

type TemplateFunctionInfo struct {
	Name        string
	Description string
}

type ValidationError

type ValidationError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
	Code    string `json:"code"`
}

ValidationError represents a validation error with structured details

func (ValidationError) Error

func (e ValidationError) Error() string

Error implements the error interface

type ValidationErrors

type ValidationErrors struct {
	Errors []ValidationError `json:"errors"`
}

ValidationErrors represents multiple validation errors

func (*ValidationErrors) Add

func (e *ValidationErrors) Add(field, message, code string)

Add adds a validation error

func (ValidationErrors) Error

func (e ValidationErrors) Error() string

Error implements the error interface

func (ValidationErrors) HasErrors

func (e ValidationErrors) HasErrors() bool

HasErrors returns true if there are validation errors

type WebhookHTTPConfig added in v0.2.0

type WebhookHTTPConfig struct {
	MaxRetries          int `db:"max_retries" json:"max_retries"`
	RetryBackoffSeconds int `db:"retry_backoff_seconds" json:"retry_backoff_seconds"`
	// CaptureResponseBody controls the stored response body size limit per delivery attempt.
	// false (default): stores up to 1 KB. true: stores up to 1 MB.
	// The response body is always read regardless of this setting (required for HTTP connection reuse).
	CaptureResponseBody   bool     `db:"capture_response_body" json:"capture_response_body"`
	FollowRedirects       bool     `db:"follow_redirects" json:"follow_redirects"`
	VerifySSL             bool     `db:"verify_ssl" json:"verify_ssl"`
	RequestTimeoutSeconds int      `db:"request_timeout_seconds" json:"request_timeout_seconds"`
	ExpectedStatusCodes   IntArray `db:"expected_status_codes" json:"expected_status_codes"`
	WebhookSecret         string   `db:"webhook_secret" json:"webhook_secret,omitempty"`
	UserAgent             string   `db:"user_agent" json:"user_agent"`
	ContentType           string   `db:"content_type" json:"content_type"`
	RateLimitRPS          *float64 `db:"rate_limit_rps" json:"rate_limit_rps,omitempty"`
}

WebhookHTTPConfig contains HTTP-specific configuration for webhook delivery

func DefaultWebhookHTTPConfig added in v0.2.0

func DefaultWebhookHTTPConfig() WebhookHTTPConfig

DefaultWebhookHTTPConfig returns default HTTP configuration

func (*WebhookHTTPConfig) ApplyConfig added in v0.2.0

func (config *WebhookHTTPConfig) ApplyConfig(other *WebhookHTTPConfig)

ApplyConfig applies configuration from another config, only overriding non-zero/non-empty values

func (WebhookHTTPConfig) GetRequestTimeout added in v0.2.0

func (config WebhookHTTPConfig) GetRequestTimeout() time.Duration

GetRequestTimeout returns the request timeout as a time.Duration

func (WebhookHTTPConfig) GetRetryBackoff added in v0.2.0

func (config WebhookHTTPConfig) GetRetryBackoff() time.Duration

GetRetryBackoff returns the retry backoff as a time.Duration

func (WebhookHTTPConfig) IsSuccessStatusCode added in v0.2.0

func (config WebhookHTTPConfig) IsSuccessStatusCode(statusCode int) bool

IsSuccessStatusCode checks if the given status code is considered successful

func (WebhookHTTPConfig) ValidateConfig added in v0.2.0

func (config WebhookHTTPConfig) ValidateConfig() error

ValidateConfig validates the HTTP configuration

type WebhookHealthData

type WebhookHealthData struct {
	WebhookID            string              `json:"webhook_id"`
	Health               store.WebhookHealth `json:"health"`
	TotalDeliveries      int                 `json:"total_deliveries"`
	SuccessfulDeliveries int                 `json:"successful_deliveries"`
	FailedDeliveries     int                 `json:"failed_deliveries"`
	ConsecutiveFailures  int                 `json:"consecutive_failures"`
	LastSuccessAt        *time.Time          `json:"last_success_at"`
	LastFailureAt        *time.Time          `json:"last_failure_at"`
	SuccessRate          float64             `json:"success_rate"`
	AvgResponseTime      int                 `json:"avg_response_time"` // milliseconds
	CreatedAt            time.Time           `json:"created_at"`
	UpdatedAt            time.Time           `json:"updated_at"`

	// Error category breakdown
	ClientErrors           int `json:"client_errors"`            // 4xx responses
	ServerErrors           int `json:"server_errors"`            // 5xx responses
	TimeoutErrors          int `json:"timeout_errors"`           // Timeouts
	NetworkErrors          int `json:"network_errors"`           // DNS, TLS, connection refused, and other network errors
	UnexpectedStatusErrors int `json:"unexpected_status_errors"` // 2xx/3xx not in expected_status_codes
}

WebhookHealthData represents webhook health information

type WebhookRegistration added in v0.2.0

type WebhookRegistration struct {
	ID          string      `db:"id" json:"id"`
	Namespace   string      `db:"namespace" json:"namespace"`
	Events      StringArray `db:"events" json:"events"`
	URL         string      `db:"url" json:"url"`
	Headers     JSONBMap    `db:"headers" json:"headers"`
	Active      bool        `db:"active" json:"active"`
	Description string      `db:"description" json:"description"`
	Health      string      `db:"health" json:"health"`

	// HTTP Configuration
	HTTPConfig WebhookHTTPConfig `json:"http_config"`

	// Ed25519EncryptedPrivateKey holds the envelope-encrypted Ed25519 private key.
	// Only populated on creation; used to derive the public key for API responses.
	Ed25519EncryptedPrivateKey []byte `json:"-"`

	// SignatureType controls which signing scheme is used: "hmac" (default) or "ed25519".
	SignatureType string `json:"signature_type"`

	CreatedAt time.Time `db:"created_at" json:"created_at"`
	UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
}

WebhookRegistration represents a webhook registration with HTTP configuration

type WebhookRegistrationRequest added in v0.2.0

type WebhookRegistrationRequest struct {
	ID            string             `json:"id,omitempty"`
	Namespace     string             `json:"namespace" validate:"required"`
	Events        []string           `json:"events" validate:"required,min=1"`
	URL           string             `json:"url" validate:"required,url"`
	Headers       map[string]any     `json:"headers,omitempty"`
	SecretHeaders map[string]string  `json:"secret_headers,omitempty"`
	Active        *bool              `json:"active,omitempty"`
	Description   string             `json:"description,omitempty"`
	HTTPConfig    *WebhookHTTPConfig `json:"http_config,omitempty"`
	RateLimitRPS  *float64           `json:"rate_limit_rps,omitempty"`
	SignatureType string             `json:"signature_type,omitempty"` // "hmac" (default) or "ed25519"
}

WebhookRegistrationRequest represents a request to create/update a webhook registration

func (WebhookRegistrationRequest) ToWebhookRegistration added in v0.2.0

func (req WebhookRegistrationRequest) ToWebhookRegistration() (*WebhookRegistration, error)

ToWebhookRegistration converts the request to a WebhookRegistration

type WebhookService

type WebhookService struct {
	// contains filtered or unexported fields
}

func NewWebhookService

func NewWebhookService(queueManager queue.JobInserter, webhookRepo store.RepositoryInterface, cryptoSvc *crypto.Service, opts ...WebhookServiceOption) *WebhookService

func (*WebhookService) CancelRepush added in v0.8.0

func (s *WebhookService) CancelRepush(ctx context.Context, repushID string) error

CancelRepush aborts a pending or in-progress batch re-push.

func (*WebhookService) CancelRetry added in v0.8.0

func (s *WebhookService) CancelRetry(ctx context.Context, retryID string) error

CancelRetry aborts a pending or in-progress batch delivery retry.

func (*WebhookService) CreateSubscription added in v0.2.0

func (s *WebhookService) CreateSubscription(ctx context.Context, webhookID, eventName, namespace string, headers map[string]string, method string, timeout int, transformEnabled bool, transformTemplate string, labelFilters map[string]string) (string, time.Time, error)

func (*WebhookService) CreateWebhook added in v0.2.0

CreateWebhook creates a webhook registration with HTTP configuration support

func (*WebhookService) DecryptSecretHeaders added in v0.2.0

func (s *WebhookService) DecryptSecretHeaders(encrypted []byte) (map[string]string, error)

DecryptSecretHeaders decrypts encrypted secret headers bytes back to a plaintext map. Returns nil map if the encrypted data is nil/empty or if encryption is not configured.

func (*WebhookService) DecryptWebhookSecret added in v0.5.0

func (s *WebhookService) DecryptWebhookSecret(encrypted []byte) (string, error)

DecryptWebhookSecret decrypts encrypted webhook secret bytes back to a plaintext string. Returns "" if the encrypted data is nil/empty or if encryption is not configured.

func (*WebhookService) DeleteEvent

func (s *WebhookService) DeleteEvent(ctx context.Context, name string) error

DeleteEvent deletes an event registration

func (*WebhookService) DeleteSubscription added in v0.2.0

func (s *WebhookService) DeleteSubscription(ctx context.Context, subscriptionID string, namespace string) error

func (*WebhookService) EncryptSecretHeaders added in v0.2.0

func (s *WebhookService) EncryptSecretHeaders(headers map[string]string) ([]byte, error)

EncryptSecretHeaders encrypts a plaintext secret headers map to bytes for storage. Returns nil if the map is empty or nil, or if encryption is not configured.

func (*WebhookService) EncryptWebhookSecret added in v0.5.0

func (s *WebhookService) EncryptWebhookSecret(secret string) ([]byte, error)

EncryptWebhookSecret encrypts a plaintext webhook secret string to bytes for storage. Returns nil if the secret is empty, or if encryption is not configured.

func (*WebhookService) GetCrypto added in v0.2.0

func (s *WebhookService) GetCrypto() *crypto.Service

GetCrypto returns the crypto service for use by workers and handlers

func (*WebhookService) GetDeliveryAttempts added in v0.2.0

func (s *WebhookService) GetDeliveryAttempts(ctx context.Context, deliveryID string) ([]*store.WebhookHealthEvent, error)

GetDeliveryAttempts retrieves individual attempt history for a delivery. Returns all recorded health events for the delivery, ordered by timestamp ascending.

func (*WebhookService) GetDeliveryStatus added in v0.2.0

func (s *WebhookService) GetDeliveryStatus(ctx context.Context, deliveryID string, namespace string) (*store.WebhookDelivery, error)

GetDeliveryStatus gets the status of a webhook delivery. When namespace is empty, looks up by delivery ID alone.

func (*WebhookService) GetEvent added in v0.2.0

func (s *WebhookService) GetEvent(ctx context.Context, name string) (*store.EventRegistration, error)

GetEvent retrieves an event registration by name

func (*WebhookService) GetEventRecord added in v1.1.0

func (s *WebhookService) GetEventRecord(ctx context.Context, eventID string) (*store.EventRecord, int32, int32, int32, int32, error)

GetEventRecord retrieves a single pushed event instance by UUID with delivery statistics.

func (*WebhookService) GetHealthSummary

func (s *WebhookService) GetHealthSummary(ctx context.Context) (*HealthSummaryData, error)

GetHealthSummary retrieves a summary of webhook health across all namespaces

func (*WebhookService) GetNamespaceStats

func (s *WebhookService) GetNamespaceStats(ctx context.Context, namespace string) (*NamespaceStatsData, error)

GetNamespaceStats retrieves statistics for a namespace, or across all namespaces if empty

func (*WebhookService) GetRepushStatus added in v0.8.0

func (s *WebhookService) GetRepushStatus(ctx context.Context, repushID string) (*store.BatchJob, error)

GetRepushStatus returns the current state of a batch re-push.

func (*WebhookService) GetRetryStatus added in v0.8.0

func (s *WebhookService) GetRetryStatus(ctx context.Context, retryID string) (*store.BatchJob, error)

GetRetryStatus returns the current state of a batch delivery retry.

func (*WebhookService) GetSubscription added in v0.2.0

func (s *WebhookService) GetSubscription(ctx context.Context, subscriptionID string, namespace string) (*store.EventSubscription, error)

func (*WebhookService) GetTemplateFunctions added in v0.2.0

func (s *WebhookService) GetTemplateFunctions() []TemplateFunctionInfo

func (*WebhookService) GetWebhookHealth

func (s *WebhookService) GetWebhookHealth(ctx context.Context, webhookID string, namespace string) (*WebhookHealthData, error)

GetWebhookHealth retrieves health metrics for a webhook

func (*WebhookService) GetWebhookRepo added in v0.2.0

func (s *WebhookService) GetWebhookRepo() store.RepositoryInterface

GetWebhookRepo returns the repository interface for direct access

func (*WebhookService) ListDeliveries added in v0.2.0

func (s *WebhookService) ListDeliveries(ctx context.Context, filter store.DeliveryFilter) ([]*store.WebhookDelivery, int32, string, error)

ListDeliveries retrieves delivery history with filters. Supports filtering by namespace, webhook, event, status, error_category, subscription, and time range via the DeliveryFilter struct. When PrepareRetry is true, snapshots all matching delivery IDs into a batch job and returns the batch ID.

func (*WebhookService) ListEventReports

ListEventReports lists event records with delivery statistics in descending order by creation time. Supports filtering by namespace, event name, schema_valid, labels, and time range. When PrepareRepush is true, snapshots all matching event IDs into a batch job and returns the batch ID.

func (*WebhookService) ListEvents

func (s *WebhookService) ListEvents(ctx context.Context, activeOnly bool, limit, offset int32) ([]*store.EventRegistration, int32, error)

ListEvents lists all registered events

func (*WebhookService) ListSubscriptions added in v0.2.0

func (s *WebhookService) ListSubscriptions(ctx context.Context, namespace string, webhookID string, eventName string, limit, offset int32) ([]*store.EventSubscription, int32, error)

func (*WebhookService) ListWebhooks

func (s *WebhookService) ListWebhooks(ctx context.Context, namespace string, webhookID string, event string, activeOnly bool, limit, offset int32) ([]*store.WebhookRegistration, int32, error)

ListWebhooks lists all registered webhooks with optional namespace and other filters. When namespace is empty, returns webhooks across all namespaces.

func (*WebhookService) ListWebhooksByHealth

func (s *WebhookService) ListWebhooksByHealth(ctx context.Context, health store.WebhookHealth, limit, offset int32) ([]*store.WebhookRegistration, int32, error)

ListWebhooksByHealth retrieves webhooks filtered by health status

func (*WebhookService) PauseWebhook

func (s *WebhookService) PauseWebhook(ctx context.Context, webhookID string, namespace string, reason string) error

PauseWebhook temporarily disables webhook deliveries

func (*WebhookService) PushEvent

func (s *WebhookService) PushEvent(ctx context.Context, namespace string, event string, payload map[string]any, ttlSeconds int64, metadata map[string]string, labels map[string]string, idempotencyKey *string) (string, bool, []string, error)

PushEvent pushes an event. When idempotencyKey is non-nil and non-empty, duplicate detection is performed: if an event with the same key already exists within the (tenant, namespace), the existing event_id is returned with isDuplicate=true and no new event or deliveries are created. Re-push/re-enqueue flows pass nil, so they are never deduplicated.

func (*WebhookService) RePushEvent added in v0.9.3

func (s *WebhookService) RePushEvent(ctx context.Context, eventID string) (string, []string, error)

RePushEvent replays a previously pushed event as if it were pushed fresh. It loads the original event record and calls PushEvent with the same payload, namespace, event name, metadata, and labels. The payload is validated against the CURRENT event type schema. Returns a new event_id and any warnings.

func (*WebhookService) RePushEvents added in v0.8.0

func (s *WebhookService) RePushEvents(ctx context.Context, repushID string) error

RePushEvents starts async processing of a batch re-push. The batch must exist, belong to the tenant, be of type event_repush, and be in pending status.

func (*WebhookService) RegisterEvent

func (s *WebhookService) RegisterEvent(ctx context.Context, name string, description string, schema map[string]any, metadata map[string]string, active bool) (string, time.Time, error)

RegisterEvent registers a new event type

func (*WebhookService) RegisterWebhook

func (s *WebhookService) RegisterWebhook(ctx context.Context, namespace string, events []string, url string, headers map[string]string, timeout int, active bool, description string, secretHeaders map[string]string) (string, time.Time, error)

func (*WebhookService) ResumeWebhook

func (s *WebhookService) ResumeWebhook(ctx context.Context, webhookID string, namespace string) error

ResumeWebhook re-enables webhook deliveries

func (*WebhookService) RetryDeliveries added in v0.8.0

func (s *WebhookService) RetryDeliveries(ctx context.Context, retryID string) error

RetryDeliveries starts async processing of a batch delivery retry.

func (*WebhookService) RetryDelivery added in v0.2.0

func (s *WebhookService) RetryDelivery(ctx context.Context, namespace string, deliveryID string, webhookID string, force bool) ([]string, int32, error)

RetryDelivery manually retries failed or pending webhook deliveries

func (*WebhookService) TestSubscriptionTemplate added in v0.2.0

func (s *WebhookService) TestSubscriptionTemplate(ctx context.Context, eventName, transformTemplate, namespace string) (string, error)

func (*WebhookService) UnregisterWebhook

func (s *WebhookService) UnregisterWebhook(ctx context.Context, webhookID string, namespace string) error

UnregisterWebhook removes a webhook registration

func (*WebhookService) UpdateEvent

func (s *WebhookService) UpdateEvent(ctx context.Context, name string, description string, schema map[string]any, metadata map[string]string, active bool) error

UpdateEvent updates an event registration

func (*WebhookService) UpdateSubscription added in v0.2.0

func (s *WebhookService) UpdateSubscription(ctx context.Context, subscriptionID string, namespace string, headers map[string]string, method string, timeout int, transformEnabled bool, transformTemplate string, labelFilters map[string]string) error

func (*WebhookService) UpdateWebhookConfig

func (s *WebhookService) UpdateWebhookConfig(ctx context.Context, webhookID string, namespace string, events []string, url string, headers map[string]string, timeout int, active bool, description string, httpConfig *HTTPConfigUpdate, secretHeaders map[string]string, signatureType string, updateMask []string) error

UpdateWebhookConfig updates webhook configuration. When updateMask is non-empty, only the listed field paths are applied. When updateMask is empty, falls back to legacy behavior (all non-zero fields applied).

Supported mask paths:

"url", "active", "description", "events", "headers",
"secret_headers", "http_config", "http_config.webhook_secret"

type WebhookServiceInterface

type WebhookServiceInterface interface {
	// Webhook Management
	RegisterWebhook(ctx context.Context, namespace string, events []string, url string, headers map[string]string, timeout int, active bool, description string, secretHeaders map[string]string) (string, time.Time, error)
	CreateWebhook(ctx context.Context, req WebhookRegistrationRequest) (*WebhookRegistration, error)
	UnregisterWebhook(ctx context.Context, webhookID string, namespace string) error
	ListWebhooks(ctx context.Context, namespace string, webhookID string, event string, activeOnly bool, limit, offset int32) ([]*store.WebhookRegistration, int32, error)
	UpdateWebhookConfig(ctx context.Context, webhookID string, namespace string, events []string, url string, headers map[string]string, timeout int, active bool, description string, httpConfig *HTTPConfigUpdate, secretHeaders map[string]string, signatureType string, updateMask []string) error
	PauseWebhook(ctx context.Context, webhookID string, namespace string, reason string) error
	ResumeWebhook(ctx context.Context, webhookID string, namespace string) error
	GetNamespaceStats(ctx context.Context, namespace string) (*NamespaceStatsData, error)

	// Event Management
	RegisterEvent(ctx context.Context, name string, description string, schema map[string]any, metadata map[string]string, active bool) (string, time.Time, error)
	ListEvents(ctx context.Context, activeOnly bool, limit, offset int32) ([]*store.EventRegistration, int32, error)
	UpdateEvent(ctx context.Context, name string, description string, schema map[string]any, metadata map[string]string, active bool) error
	DeleteEvent(ctx context.Context, name string) error
	GetEvent(ctx context.Context, name string) (*store.EventRegistration, error)
	PushEvent(ctx context.Context, namespace string, event string, payload map[string]any, ttlSeconds int64, metadata map[string]string, labels map[string]string, idempotencyKey *string) (string, bool, []string, error)
	RePushEvent(ctx context.Context, eventID string) (string, []string, error)
	GetEventRecord(ctx context.Context, eventID string) (*store.EventRecord, int32, int32, int32, int32, error)
	ListEventReports(ctx context.Context, filter store.EventReportFilter) ([]*store.EventReportWithStats, int32, string, error)

	// Subscription Management
	CreateSubscription(ctx context.Context, webhookID, eventName, namespace string, headers map[string]string, method string, timeout int, transformEnabled bool, transformTemplate string, labelFilters map[string]string) (string, time.Time, error)
	GetSubscription(ctx context.Context, subscriptionID string, namespace string) (*store.EventSubscription, error)
	ListSubscriptions(ctx context.Context, namespace string, webhookID string, eventName string, limit, offset int32) ([]*store.EventSubscription, int32, error)
	UpdateSubscription(ctx context.Context, subscriptionID string, namespace string, headers map[string]string, method string, timeout int, transformEnabled bool, transformTemplate string, labelFilters map[string]string) error
	DeleteSubscription(ctx context.Context, subscriptionID string, namespace string) error
	TestSubscriptionTemplate(ctx context.Context, eventName, transformTemplate, namespace string) (string, error)

	// Delivery Management
	GetDeliveryStatus(ctx context.Context, deliveryID string, namespace string) (*store.WebhookDelivery, error)
	GetDeliveryAttempts(ctx context.Context, deliveryID string) ([]*store.WebhookHealthEvent, error)
	ListDeliveries(ctx context.Context, filter store.DeliveryFilter) ([]*store.WebhookDelivery, int32, string, error)
	RetryDelivery(ctx context.Context, namespace string, deliveryID string, webhookID string, force bool) ([]string, int32, error)

	// Health Management
	GetWebhookHealth(ctx context.Context, webhookID string, namespace string) (*WebhookHealthData, error)
	ListWebhooksByHealth(ctx context.Context, health store.WebhookHealth, limit, offset int32) ([]*store.WebhookRegistration, int32, error)
	GetHealthSummary(ctx context.Context) (*HealthSummaryData, error)

	// Batch Operations
	RePushEvents(ctx context.Context, repushID string) error
	GetRepushStatus(ctx context.Context, repushID string) (*store.BatchJob, error)
	CancelRepush(ctx context.Context, repushID string) error
	RetryDeliveries(ctx context.Context, retryID string) error
	GetRetryStatus(ctx context.Context, retryID string) (*store.BatchJob, error)
	CancelRetry(ctx context.Context, retryID string) error

	// Metadata
	GetTemplateFunctions() []TemplateFunctionInfo

	// Repository access
	GetWebhookRepo() store.RepositoryInterface

	// Crypto
	DecryptSecretHeaders(encrypted []byte) (map[string]string, error)
	DecryptWebhookSecret(encrypted []byte) (string, error)
	GetCrypto() *crypto.Service
}

type WebhookServiceInterfaceWithTracing

type WebhookServiceInterfaceWithTracing struct {
	WebhookServiceInterface
	// contains filtered or unexported fields
}

WebhookServiceInterfaceWithTracing implements WebhookServiceInterface interface instrumented with open telemetry spans

func NewWebhookServiceInterfaceWithTracing

func NewWebhookServiceInterfaceWithTracing(base WebhookServiceInterface, instance string, spanDecorator ...func(span trace.Span, params, results map[string]any)) WebhookServiceInterfaceWithTracing

NewWebhookServiceInterfaceWithTracing returns WebhookServiceInterfaceWithTracing

func (WebhookServiceInterfaceWithTracing) CancelRepush added in v0.8.0

func (_d WebhookServiceInterfaceWithTracing) CancelRepush(ctx context.Context, repushID string) (err error)

CancelRepush implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) CancelRetry added in v0.8.0

func (_d WebhookServiceInterfaceWithTracing) CancelRetry(ctx context.Context, retryID string) (err error)

CancelRetry implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) CreateSubscription added in v0.2.0

func (_d WebhookServiceInterfaceWithTracing) CreateSubscription(ctx context.Context, webhookID string, eventName string, namespace string, headers map[string]string, method string, timeout int, transformEnabled bool, transformTemplate string, labelFilters map[string]string) (s1 string, t1 time.Time, err error)

CreateSubscription implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) CreateWebhook added in v0.2.0

CreateWebhook implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) DeleteEvent

func (_d WebhookServiceInterfaceWithTracing) DeleteEvent(ctx context.Context, name string) (err error)

DeleteEvent implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) DeleteSubscription added in v0.2.0

func (_d WebhookServiceInterfaceWithTracing) DeleteSubscription(ctx context.Context, subscriptionID string, namespace string) (err error)

DeleteSubscription implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) GetDeliveryAttempts added in v0.2.0

func (_d WebhookServiceInterfaceWithTracing) GetDeliveryAttempts(ctx context.Context, deliveryID string) (wpa1 []*store.WebhookHealthEvent, err error)

GetDeliveryAttempts implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) GetDeliveryStatus added in v0.2.0

func (_d WebhookServiceInterfaceWithTracing) GetDeliveryStatus(ctx context.Context, deliveryID string, namespace string) (wp1 *store.WebhookDelivery, err error)

GetDeliveryStatus implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) GetEvent added in v0.2.0

GetEvent implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) GetEventRecord added in v1.1.0

func (_d WebhookServiceInterfaceWithTracing) GetEventRecord(ctx context.Context, eventID string) (ep1 *store.EventRecord, i1 int32, i2 int32, i3 int32, i4 int32, err error)

GetEventRecord implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) GetHealthSummary

func (_d WebhookServiceInterfaceWithTracing) GetHealthSummary(ctx context.Context) (hp1 *HealthSummaryData, err error)

GetHealthSummary implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) GetNamespaceStats

func (_d WebhookServiceInterfaceWithTracing) GetNamespaceStats(ctx context.Context, namespace string) (np1 *NamespaceStatsData, err error)

GetNamespaceStats implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) GetRepushStatus added in v0.8.0

func (_d WebhookServiceInterfaceWithTracing) GetRepushStatus(ctx context.Context, repushID string) (bp1 *store.BatchJob, err error)

GetRepushStatus implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) GetRetryStatus added in v0.8.0

func (_d WebhookServiceInterfaceWithTracing) GetRetryStatus(ctx context.Context, retryID string) (bp1 *store.BatchJob, err error)

GetRetryStatus implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) GetSubscription added in v0.2.0

func (_d WebhookServiceInterfaceWithTracing) GetSubscription(ctx context.Context, subscriptionID string, namespace string) (ep1 *store.EventSubscription, err error)

GetSubscription implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) GetWebhookHealth

func (_d WebhookServiceInterfaceWithTracing) GetWebhookHealth(ctx context.Context, webhookID string, namespace string) (wp1 *WebhookHealthData, err error)

GetWebhookHealth implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) ListDeliveries added in v0.2.0

func (_d WebhookServiceInterfaceWithTracing) ListDeliveries(ctx context.Context, filter store.DeliveryFilter) (wpa1 []*store.WebhookDelivery, i1 int32, s1 string, err error)

ListDeliveries implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) ListEventReports

func (_d WebhookServiceInterfaceWithTracing) ListEventReports(ctx context.Context, filter store.EventReportFilter) (epa1 []*store.EventReportWithStats, i1 int32, s1 string, err error)

ListEventReports implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) ListEvents

func (_d WebhookServiceInterfaceWithTracing) ListEvents(ctx context.Context, activeOnly bool, limit int32, offset int32) (epa1 []*store.EventRegistration, i1 int32, err error)

ListEvents implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) ListSubscriptions added in v0.2.0

func (_d WebhookServiceInterfaceWithTracing) ListSubscriptions(ctx context.Context, namespace string, webhookID string, eventName string, limit int32, offset int32) (epa1 []*store.EventSubscription, i1 int32, err error)

ListSubscriptions implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) ListWebhooks

func (_d WebhookServiceInterfaceWithTracing) ListWebhooks(ctx context.Context, namespace string, webhookID string, event string, activeOnly bool, limit int32, offset int32) (wpa1 []*store.WebhookRegistration, i1 int32, err error)

ListWebhooks implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) ListWebhooksByHealth

func (_d WebhookServiceInterfaceWithTracing) ListWebhooksByHealth(ctx context.Context, health store.WebhookHealth, limit int32, offset int32) (wpa1 []*store.WebhookRegistration, i1 int32, err error)

ListWebhooksByHealth implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) PauseWebhook

func (_d WebhookServiceInterfaceWithTracing) PauseWebhook(ctx context.Context, webhookID string, namespace string, reason string) (err error)

PauseWebhook implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) PushEvent

func (_d WebhookServiceInterfaceWithTracing) PushEvent(ctx context.Context, namespace string, event string, payload map[string]any, ttlSeconds int64, metadata map[string]string, labels map[string]string, idempotencyKey *string) (s1 string, b1 bool, sa1 []string, err error)

PushEvent implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) RePushEvent added in v0.9.3

func (_d WebhookServiceInterfaceWithTracing) RePushEvent(ctx context.Context, eventID string) (s1 string, sa1 []string, err error)

RePushEvent implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) RePushEvents added in v0.8.0

func (_d WebhookServiceInterfaceWithTracing) RePushEvents(ctx context.Context, repushID string) (err error)

RePushEvents implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) RegisterEvent

func (_d WebhookServiceInterfaceWithTracing) RegisterEvent(ctx context.Context, name string, description string, schema map[string]any, metadata map[string]string, active bool) (s1 string, t1 time.Time, err error)

RegisterEvent implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) RegisterWebhook

func (_d WebhookServiceInterfaceWithTracing) RegisterWebhook(ctx context.Context, namespace string, events []string, url string, headers map[string]string, timeout int, active bool, description string, secretHeaders map[string]string) (s1 string, t1 time.Time, err error)

RegisterWebhook implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) ResumeWebhook

func (_d WebhookServiceInterfaceWithTracing) ResumeWebhook(ctx context.Context, webhookID string, namespace string) (err error)

ResumeWebhook implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) RetryDeliveries added in v0.8.0

func (_d WebhookServiceInterfaceWithTracing) RetryDeliveries(ctx context.Context, retryID string) (err error)

RetryDeliveries implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) RetryDelivery added in v0.2.0

func (_d WebhookServiceInterfaceWithTracing) RetryDelivery(ctx context.Context, namespace string, deliveryID string, webhookID string, force bool) (sa1 []string, i1 int32, err error)

RetryDelivery implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) TestSubscriptionTemplate added in v0.2.0

func (_d WebhookServiceInterfaceWithTracing) TestSubscriptionTemplate(ctx context.Context, eventName string, transformTemplate string, namespace string) (s1 string, err error)

TestSubscriptionTemplate implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) UnregisterWebhook

func (_d WebhookServiceInterfaceWithTracing) UnregisterWebhook(ctx context.Context, webhookID string, namespace string) (err error)

UnregisterWebhook implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) UpdateEvent

func (_d WebhookServiceInterfaceWithTracing) UpdateEvent(ctx context.Context, name string, description string, schema map[string]any, metadata map[string]string, active bool) (err error)

UpdateEvent implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) UpdateSubscription added in v0.2.0

func (_d WebhookServiceInterfaceWithTracing) UpdateSubscription(ctx context.Context, subscriptionID string, namespace string, headers map[string]string, method string, timeout int, transformEnabled bool, transformTemplate string, labelFilters map[string]string) (err error)

UpdateSubscription implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) UpdateWebhookConfig

func (_d WebhookServiceInterfaceWithTracing) UpdateWebhookConfig(ctx context.Context, webhookID string, namespace string, events []string, url string, headers map[string]string, timeout int, active bool, description string, httpConfig *HTTPConfigUpdate, secretHeaders map[string]string, signatureType string, updateMask []string) (err error)

UpdateWebhookConfig implements WebhookServiceInterface

type WebhookServiceOption added in v0.2.0

type WebhookServiceOption func(*WebhookService)

NewWebhookService creates a new WebhookService instance WebhookServiceOption configures a WebhookService.

func WithAllowPrivateNetworks added in v0.2.0

func WithAllowPrivateNetworks(allow bool) WebhookServiceOption

WithAllowPrivateNetworks disables SSRF protection for webhook URL validation, permitting loopback and private-network addresses. Useful for self-hosted deployments where webhook targets live on the same network, and required for integration tests that use httptest.NewServer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL