Documentation
¶
Overview ¶
Package http serves Octomaton's endpoints: GitHub's webhook deliveries and the Kubernetes probes.
Index ¶
Constants ¶
const MaxBodyBytes = 25 << 20
MaxBodyBytes is the largest payload accepted (GitHub caps payloads at 25 MB).
const SignatureHeader = "X-Hub-Signature-256"
SignatureHeader carries the HMAC-SHA256 signature of the request body.
const WebhookPath = "/github/hooks"
WebhookPath is where GitHub delivers the App's webhooks.
Variables ¶
This section is empty.
Functions ¶
func VerifySignature ¶
VerifySignature reports whether header ("sha256=<hex>") is the HMAC-SHA256 of body keyed with secret. The comparison is constant-time.
Types ¶
type Decoder ¶
type Decoder interface {
// Handles reports whether Decode handles an event, by its X-GitHub-Event name.
Handles(event string) bool
// Decode turns a delivery into an event. It returns no event, and the reason, for deliveries
// Octomaton ignores, and an error for payloads it cannot parse.
Decode(event, delivery string, body []byte) (ci.Event, string, error)
}
Decoder turns verified deliveries into events; the GitHub adapter's App implements it.
type Dedupe ¶
type Dedupe struct {
// contains filtered or unexported fields
}
Dedupe remembers recently seen delivery IDs (bounded LRU with a TTL) so that redelivered webhooks are processed once per replica, unless processing failed (Remove).
type EventHandler ¶
EventHandler does what an event asks for; the runs service implements it. It returns an error when it left part of the event undone, which a redelivery may do.
type Handler ¶
type Handler struct {
Secret []byte
Decoder Decoder
Events EventHandler
Pool *Pool
Dedupe *Dedupe
Metrics *metrics.Metrics
Logger *slog.Logger
// Relay, when set, receives verified push and ping deliveries.
Relay Forwarder
}
Handler serves POST /github/hooks: it verifies signatures, decodes deliveries, drops duplicates and hands the events to a bounded worker pool. A delivery is a duplicate while an earlier copy is being handled or was handled; one whose handling failed is forgotten, so its redelivery (GitHub keeps the delivery's ID) is handled again.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool runs jobs on a fixed number of workers fed by a bounded queue.
func NewPool ¶
func NewPool(workers, queueSize int, jobTimeout time.Duration, logger *slog.Logger, m *metrics.Metrics) *Pool
NewPool starts workers goroutines consuming a queue of queueSize jobs; each job runs with a timeout of jobTimeout.
type Readiness ¶
type Readiness struct {
// Ping checks that the Kubernetes API server answers.
Ping func(ctx context.Context) error
// Leading reports whether this replica is the elected leader.
Leading func() bool
// Synced reports whether the leader's PipelineRun informer has synced.
Synced func() bool
// TTL is how long a Ping result is reused, so that frequent probes do not load the API server.
TTL time.Duration
// contains filtered or unexported fields
}
Readiness answers the readiness probe. A replica is ready while the Kubernetes API server answers and, on the leader, once the PipelineRun informer has synced; a replica shutting down never is.