Documentation
¶
Overview ¶
Package eventhook delivers platform events to operator-configured HTTPS endpoints: signed, queued, retried with backoff, dead-lettered after the last attempt, and recorded in a delivery log that supports replay.
Index ¶
- Constants
- Variables
- func Backoff(cfg Config, attempts int) time.Duration
- func EventTypes() []string
- func Matches(subscribed []string, eventType string) bool
- func TypeForRequest(method, path, action string) string
- type Config
- type Counts
- type Deps
- type Event
- type Input
- type Outcome
- type Patch
- type Secrets
- type Service
- func (s *Service) Create(ctx context.Context, in Input) (store.EventWebhook, string, error)
- func (s *Service) Delete(ctx context.Context, id string) error
- func (s *Service) Deliveries(ctx context.Context, webhookID string, limit int) ([]store.EventWebhookDelivery, error)
- func (s *Service) Dropped() int64
- func (s *Service) Emit(e Event)
- func (s *Service) Get(ctx context.Context, id string) (store.EventWebhook, error)
- func (s *Service) List(ctx context.Context) ([]store.EventWebhook, error)
- func (s *Service) Replay(ctx context.Context, deliveryID string) (store.EventWebhookDelivery, error)
- func (s *Service) RotateSecret(ctx context.Context, id string) (string, error)
- func (s *Service) Run(ctx context.Context)
- func (s *Service) Summary(ctx context.Context, id string) (Counts, error)
- func (s *Service) Test(ctx context.Context, id string) (int, error)
- func (s *Service) Update(ctx context.Context, id string, p Patch) (store.EventWebhook, error)
- type Store
Constants ¶
const ( EnvMaxAttempts = "APP_EVENT_WEBHOOK_MAX_ATTEMPTS" EnvBackoffBase = "APP_EVENT_WEBHOOK_BACKOFF_BASE" EnvBackoffMax = "APP_EVENT_WEBHOOK_BACKOFF_MAX" EnvSendTimeout = "APP_EVENT_WEBHOOK_TIMEOUT" EnvRetention = "APP_EVENT_WEBHOOK_RETENTION" EnvQueueSize = "APP_EVENT_WEBHOOK_QUEUE_SIZE" )
Environment variables that tune delivery.
Variables ¶
var ErrInvalid = errors.New("invalid event webhook")
ErrInvalid wraps every validation failure so callers can answer 400.
ErrSecretsUnavailable is returned when no master key is configured.
Functions ¶
func Backoff ¶
Backoff is the wait before attempt number attempts+1: exponential from BackoffBase, capped at BackoffMax.
func EventTypes ¶
func EventTypes() []string
EventTypes lists the event types the platform emits today, sorted.
func Matches ¶
Matches reports whether a subscription list selects an event type. An empty list selects everything; "family.*" selects a name prefix.
func TypeForRequest ¶
TypeForRequest names the event for one audited mutation: the audit action when the handler set one, else "<resource>.<verb>" from the request path.
Types ¶
type Config ¶
type Config struct {
MaxAttempts int
BackoffBase time.Duration
BackoffMax time.Duration
SendTimeout time.Duration
Retention time.Duration
Tick time.Duration
BatchSize int
QueueSize int
}
Config bounds queueing, retries and retention.
func ConfigFromEnv ¶
ConfigFromEnv applies env overrides on top of DefaultConfig. Unparseable or non-positive values are ignored.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig is the config used when no env override is set.
type Deps ¶
type Deps struct {
Store Store
Secrets Secrets
Config Config
// RetentionDays, when set, supplies the live delivery retention in days (0 keeps everything) instead of Config.Retention.
RetentionDays func(ctx context.Context) int
Brand string
Logger *slog.Logger
HTTPClient *http.Client
Now func() time.Time
}
Deps wires a Service.
type Secrets ¶
type Secrets interface {
SetValue(ctx context.Context, serviceName, envKey, plaintext string) error
Resolve(ctx context.Context, serviceName, envKey string) (string, error)
DeleteAll(ctx context.Context, serviceName string) error
}
Secrets stores signing secrets in envelope encryption.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service owns webhook CRUD and the delivery workers.
func NewService ¶
NewService builds a Service. Call Run to start delivery.
func (*Service) Create ¶
Create validates and stores a webhook and returns it with its signing secret, which is shown once and never readable afterwards.
func (*Service) Deliveries ¶
func (s *Service) Deliveries(ctx context.Context, webhookID string, limit int) ([]store.EventWebhookDelivery, error)
Deliveries lists a webhook's newest deliveries.
func (*Service) Dropped ¶
Dropped reports how many events were discarded because the buffer was full.
func (*Service) Emit ¶
Emit queues an event without blocking the caller. When the intake buffer is full the event is dropped and counted, never waited on.
func (*Service) Replay ¶
func (s *Service) Replay(ctx context.Context, deliveryID string) (store.EventWebhookDelivery, error)
Replay puts a delivery back in the queue with a fresh attempt budget.
func (*Service) RotateSecret ¶
RotateSecret issues a new signing secret and returns it once.
type Store ¶
type Store interface {
SaveEventWebhook(ctx context.Context, w store.EventWebhook) error
UpdateEventWebhook(ctx context.Context, w store.EventWebhook) error
GetEventWebhook(ctx context.Context, id string) (store.EventWebhook, error)
ListEventWebhooks(ctx context.Context) ([]store.EventWebhook, error)
DeleteEventWebhook(ctx context.Context, id string) error
SaveEventDelivery(ctx context.Context, d store.EventWebhookDelivery) error
UpdateEventDelivery(ctx context.Context, d store.EventWebhookDelivery) error
GetEventDelivery(ctx context.Context, id string) (store.EventWebhookDelivery, error)
ListDueEventDeliveries(ctx context.Context, now string, limit int) ([]store.EventWebhookDelivery, error)
ListEventDeliveries(ctx context.Context, webhookID string, limit int) ([]store.EventWebhookDelivery, error)
DeleteEventDeliveriesOlderThan(ctx context.Context, cutoff string) (int64, error)
}
Store is the persistence surface; *store.DB satisfies it.