webhookapi

package
v1.136.1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package webhookapi is the admin REST surface for inbound webhook sources (#1870): list, create, read with status, change, and delete. Secrets are write-only: a view says whether one is set and until when the previous one is still accepted, and never carries either.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(mux *http.ServeMux, wrap func(http.Handler) http.Handler, cfg Config)

Register mounts the webhook source routes, each behind wrap, the admin API's authentication.

Types

type AuthInput

type AuthInput struct {
	Mode             string `json:"mode" example:"hmac"`
	Secret           string `json:"secret,omitempty" example:"whsec_example"`
	Algorithm        string `json:"algorithm,omitempty" example:"sha256"`
	SignatureHeader  string `json:"signature_header,omitempty" example:"X-Signature"`
	Encoding         string `json:"encoding,omitempty" example:"hex"`
	Prefix           string `json:"prefix,omitempty" example:"sha256="`
	TimestampHeader  string `json:"timestamp_header,omitempty" example:"X-Timestamp"`
	ToleranceSeconds int    `json:"tolerance_seconds,omitempty" example:"300"`
	Signed           string `json:"signed,omitempty" example:"body"`
	Header           string `json:"header,omitempty" example:"X-Webhook-Token"`
	Username         string `json:"username,omitempty" example:"sender"`
}

AuthInput is how a request proves it came from the sender. secret is write-only; on an update, an empty secret keeps the stored one.

type AuthView

type AuthView struct {
	Mode             string     `json:"mode"`
	SecretSet        bool       `json:"secret_set"`
	PreviousUntil    *time.Time `json:"previous_secret_until,omitempty"`
	Algorithm        string     `json:"algorithm,omitempty"`
	SignatureHeader  string     `json:"signature_header,omitempty"`
	Encoding         string     `json:"encoding,omitempty"`
	Prefix           string     `json:"prefix,omitempty"`
	TimestampHeader  string     `json:"timestamp_header,omitempty"`
	ToleranceSeconds int        `json:"tolerance_seconds,omitempty"`
	Signed           string     `json:"signed,omitempty"`
	Header           string     `json:"header,omitempty"`
	Username         string     `json:"username,omitempty"`
}

AuthView is a source's authentication without its secrets.

type Config

type Config struct {
	// Service manages sources. nil mounts nothing.
	Service Service
	// Author resolves the acting admin.
	Author func(*http.Request) string
}

Config carries the service and the parent-owned helpers.

type Service

type Service interface {
	List(ctx context.Context) ([]whsource.Source, error)
	Get(ctx context.Context, name string) (whsource.Source, whstore.Status, error)
	Create(ctx context.Context, src whsource.Source) (whsource.Source, error)
	Update(ctx context.Context, name string, u whadmin.Update) (whsource.Source, error)
	Delete(ctx context.Context, name string) error
}

Service is what the routes act through. whadmin.Service satisfies it.

type SourceDetail

type SourceDetail struct {
	Source SourceView     `json:"source"`
	Status whstore.Status `json:"status"`
}

SourceDetail is one source with its status.

type SourceInput

type SourceInput struct {
	Name       string          `json:"name,omitempty" example:"esp-events"`
	Enabled    *bool           `json:"enabled,omitempty" example:"true"`
	Connection string          `json:"connection,omitempty" example:"scratch"`
	Auth       AuthInput       `json:"auth"`
	Config     whsource.Config `json:"config"`
	// RotationOverlapSeconds keeps the previous secret valid this long when
	// auth.secret replaces it. Zero ends it at once.
	RotationOverlapSeconds int `json:"rotation_overlap_seconds,omitempty" example:"86400"`
}

SourceInput is the write shape. name and connection are read on create only: the table was created on that connection under a name derived from the source's.

type SourceList

type SourceList struct {
	Sources []SourceView `json:"sources"`
}

SourceList is the collection response.

type SourceView

type SourceView struct {
	Name       string `json:"name"`
	Enabled    bool   `json:"enabled"`
	Connection string `json:"connection"`
	// Path is where the sender posts, relative to the platform's address:
	// /hooks/{name}, with the token as a further segment for path_token.
	Path string `json:"path" example:"/hooks/esp-events"`
	// Table is what readers query, in the connection's scratch schema.
	Table     string          `json:"table" example:"webhook_esp_events"`
	Auth      AuthView        `json:"auth"`
	Config    whsource.Config `json:"config"`
	CreatedBy string          `json:"created_by,omitempty"`
	CreatedAt time.Time       `json:"created_at"`
	UpdatedAt time.Time       `json:"updated_at"`
}

SourceView is the read shape.

Jump to

Keyboard shortcuts

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