Documentation
¶
Overview ¶
Package webhook is the built-in webhook provider: a signed HTTP POST of JSON to a URL the product names on every call, signed per Standard Webhooks (webhook-id, webhook-timestamp, webhook-signature: HMAC-SHA256 with the secret the product holds for that receiver). Retries are the platform's (the activity's); the receiver deduplicates by webhook-id, the same on every attempt.
Index ¶
Constants ¶
const ( // CodeForbidden: a URL courier does not post to — not https, a host the // channel does not allow, or an internal address. CodeForbidden = "forbidden_destination" // CodeGone: the receiver answered 410, it takes no more. CodeGone = "gone" // CodeRefused: the receiver answered another 3xx or 4xx. CodeRefused = "refused" )
Codes of the refusals.
const ( HeaderID = "Webhook-Id" HeaderTimestamp = "Webhook-Timestamp" HeaderSignature = "Webhook-Signature" )
Signature headers (Standard Webhooks: webhook-id, webhook-timestamp, webhook-signature), canonical.
const (
MaxBodyBytes = 1 << 20
)
Limits of a message.
Variables ¶
var ( ErrURL = errors.New("webhook: url is an https URL") ErrDestination = errors.New("webhook: url is not a host this channel allows") ErrSecret = errors.New("webhook: secrets are required (each raw, or whsec_ and base64)") ErrBody = errors.New("webhook: body is a JSON value") ErrTooBig = errors.New("webhook: body exceeds 1 MiB") ErrID = errors.New("webhook: id is up to 256 printable characters") ErrHeader = errors.New("webhook: header") )
Errors of Validate; every one is final.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client posts the webhooks of one channel.
func New ¶
New is the client of a channel. A nil client: one that does not follow redirects and, unless the channel is insecure, dials only public addresses, directly (netguard.ErrForbiddenAddress).
type Config ¶
type Config struct {
// Hosts the channel posts to (exact or *.suffix); empty: any public
// host.
Hosts []string `json:"hosts,omitempty" schemapb:"description=Hosts webhooks may go to, else any public host"`
// Insecure lets the channel post over http and to internal addresses:
// a receiver in the installation's own network, or development.
Insecure bool `json:"insecure,omitempty" schemapb:"description=Allow http and internal addresses"`
}
Config of a webhook channel.
type Message ¶
type Message struct {
Channel string `json:"channel,omitempty" schemapb:"description=Webhook channel of the installation, else the default"`
URL string `json:"url" schemapb:"description=Receiver URL"`
// Secrets sign the message, each raw or whsec_ and base64: every one
// adds its signature to webhook-signature, in order, so a receiver
// that knows any of them verifies it. A product rotating a receiver's
// secret signs with the new one and, while the receiver may still hold
// it, the old one.
Secrets []string `json:"secrets" schemapb:"secret=true;description=Signing secrets: the current one, then older ones"`
// ID is webhook-id, the receiver deduplicates by it; empty: the
// step's, the same on every attempt.
ID string `json:"id,omitempty" schemapb:"description=webhook-id, else the step's"`
Body json.RawMessage `json:"body" schemapb:"description=JSON posted as the body"`
Headers map[string]string `json:"headers,omitempty" schemapb:"description=Extra request headers"`
}
Message is courier.SendWebhook's input.