webhook

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package webhook provides the audit-event webhook dispatcher for the registry server. It owns the Store type, which holds the outbound HTTP dispatcher (with DLQ and retry), and exposes the three wire handler methods that the registry dispatch table calls via thin Server wrappers.

Fan-out from the event bus is wired by calling Store.Subscribe(bus) after construction; the store listens for "audit.entry" events and calls Emit on each one so callers no longer need to touch the store directly at mutation sites.

Index

Constants

View Source
const (
	MaxRetries     = 3
	InitialBackoff = 1 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	EventID   uint64                 `json:"event_id"`
	Action    string                 `json:"action"`
	Timestamp time.Time              `json:"timestamp"`
	Details   map[string]interface{} `json:"details,omitempty"`
}

Event is the JSON payload POSTed to webhook endpoints.

type Store

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

Store holds the webhook configuration and dispatcher for the audit-event webhook. A nil *Store is valid and behaves as "no webhook configured".

Typical lifecycle:

st := webhook.NewStore()
st.Subscribe(bus)          // hook into the event bus for automatic fan-out
st.SetURL("https://...")   // configure the endpoint (or leave empty)
...
st.Close()                 // on server shutdown

func NewStore

func NewStore() *Store

NewStore returns an initialised *Store with no webhook URL configured.

func (*Store) Close

func (st *Store) Close()

Close drains the current dispatcher and releases resources.

func (*Store) Emit

func (st *Store) Emit(action string, details map[string]interface{})

Emit is a no-op when no webhook URL is configured or the store is nil.

func (*Store) HandleGetWebhook

func (st *Store) HandleGetWebhook() map[string]interface{}

HandleGetWebhook requires admin-token verification by the caller.

func (*Store) HandleGetWebhookDLQ

func (st *Store) HandleGetWebhookDLQ() map[string]interface{}

HandleGetWebhookDLQ requires admin-token verification by the caller.

func (*Store) HandleSetWebhook

func (st *Store) HandleSetWebhook(urlStr string) map[string]interface{}

HandleSetWebhook requires admin-token verification by the caller. Empty urlStr disables the webhook.

func (*Store) SetInitialBackoff

func (st *Store) SetInitialBackoff(d time.Duration)

SetInitialBackoff sets the retry backoff. Tests set a short value to avoid waiting on retry exhaustion. No-op when no dispatcher is active.

func (*Store) SetURL

func (st *Store) SetURL(url string)

SetURL reconfigures the webhook target URL. Pass an empty string to disable webhook dispatching. The old dispatcher (if any) is drained before the new one starts.

func (*Store) Subscribe

func (st *Store) Subscribe(bus events.Bus)

Subscribe must be called once after construction. The goroutine exits when the store is Closed (which calls the unsubscribe func, closing the channel) or the bus channel closes.

Jump to

Keyboard shortcuts

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