webhookctrl

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package webhookctrl implements the webhook-controller engine: the router between the GitHub App's single webhook URL and the controllers' cluster-internal receivers. A GitHub App can deliver to exactly one URL, but every controller runs its own receiver, so the webhook-controller — the only internet-facing patchy component — accepts each delivery once and forwards it to the targets its X-GitHub-Event type routes to (a "*" route catches event types no rule claims, e.g. those registered by pkg/source plugins).

The webhook-controller holds no GitHub credential. It shares only the webhook HMAC secret, which it uses twice: internal/webhook validates the inbound signature before anything is forwarded, and the Forwarder re-signs the payload on the way out (an identical signature, since the secret is the same), so every controller keeps authenticating every delivery itself. Forwarding is best-effort: a failed or unrouted target is logged and skipped, because the controllers' reconcile loops — not webhook redelivery — are the correctness mechanism.

Index

Constants

View Source
const DefaultRoute = "*"

DefaultRoute is the Routes key that catches event types with no route of their own.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Secret is the shared webhook HMAC secret. The forwarded
	// X-Hub-Signature-256 is recomputed from it — byte-identical to the one
	// GitHub sent — so the controllers keep validating every delivery.
	Secret []byte
	// Routes maps an X-GitHub-Event type to the webhook endpoints that
	// consume it, e.g. "code_scanning_alert" ->
	// http://patchy-source-controller:8080/webhook. The DefaultRoute ("*")
	// entry, when present, receives every event type no other key claims.
	Routes map[string][]string
	// Timeout bounds each per-target forward. Default 10s.
	Timeout time.Duration
	// Client optionally overrides the HTTP client (tests). Timeouts are
	// applied per request via context, not on the client.
	Client *http.Client
}

Config configures a Forwarder.

type Forwarder

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

Forwarder routes one validated delivery to the targets that consume its event type. It implements webhook.Handler, so it plugs straight into webhook.NewServer.

func New

func New(cfg Config, log *slog.Logger) *Forwarder

New builds a Forwarder; defaults are applied here so the zero Config fields need no ceremony at call sites.

func (*Forwarder) Handle

func (f *Forwarder) Handle(ctx context.Context, e webhook.Event) error

Handle forwards the delivery to its event type's targets concurrently and reports the targets that failed. A partial failure still delivers to the healthy targets; the failed controller's reconcile loop is the retry mechanism. An event type with no route (and no DefaultRoute) is dropped without error — GitHub only sends subscribed events, so this is a routing config gap, not a delivery failure worth retrying.

Jump to

Keyboard shortcuts

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