Documentation
¶
Overview ¶
Package webhook delivers repository events to outside URLs, signed with HMAC-SHA256 (D78).
Index ¶
Constants ¶
const Cursor = "webhook"
Cursor is the outbox reader name of the dispatcher.
const ( // Tick is how often serve looks for new events when nothing woke it; retry timing comes from webhook.retry_seconds. Tick = 5 * time.Second )
Internal batch sizes: how much one tick reads and sends. Not product values; the limits a person tunes are settings.
Variables ¶
var ( ErrBadURL = errors.New("webhook: URL must be http(s)://host/... without user or password") ErrPrivate = errors.New("webhook: address is private, loopback or link-local") )
Errors a form maps to messages.
var Kinds = []string{"push", "issues", "issue_comment", "pull_request", "pull_request_review", "pull_request_review_comment", "status", "wiki"}
Kinds are the event kinds a webhook can subscribe to, in form order. Field names follow GitHub's where the meaning is the same (full_name, html_url, ref/before/after, number), so existing receivers need little change.
Functions ¶
func ParseHosts ¶
ParseHosts reads the comma list of webhook.allow_hosts.
func Sign ¶
Sign is the value of X-Codr-Signature-256 (and X-Hub-Signature-256): "sha256=" + hex HMAC of the exact body.
func ValidKinds ¶
ValidKinds keeps the known kinds of a form submission, in canonical order; empty means "everything".
Types ¶
type Builder ¶
type Builder struct {
Store *store.Store
HTTPHost string // forge base URL, e.g. https://git.codr.my
SSHHost string
Git func(repoID int64) gitread.Repo
// PushCommits caps the commits listed in a push payload (setting webhook.push_commits).
PushCommits int
}
Builder turns an outbox event into the JSON body a webhook receives.
type Dispatcher ¶
type Dispatcher struct {
Store *store.Store
Key secret.Key // auth.secret_key: unseals each webhook's signing secret
Builder Builder
Log *slog.Logger
// Client overrides the HTTP client (tests); nil = a client built from the settings with the address guard.
Client *http.Client
// contains filtered or unexported fields
}
Dispatcher fans outbox events out to webhooks and delivers them. One runs inside `serve`.
func (*Dispatcher) Kick ¶
func (d *Dispatcher) Kick()
Kick asks the loop to run now instead of at the next tick. It never blocks.
type Policy ¶
type Policy struct {
AllowPrivate bool // setting webhook.allow_private
AllowHosts []string // setting webhook.allow_hosts: host names that may resolve to private addresses
}
Policy decides which addresses a webhook may reach. Anyone who administers a repository can add a webhook, so without it a webhook is a way to make this server call its own neighbours (the LLM router, the database, cloud metadata). The check runs on the address actually dialled, after DNS, so a name that resolves to 127.0.0.1 or changes its answer between check and dial is still refused.
func PolicyFrom ¶
PolicyFrom reads the address rules from the settings.