webhook

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrQueueFull = errors.New("deployment queue is full")

ErrQueueFull is returned when the deployment queue is at capacity.

Functions

func ComputeHmacSHA256

func ComputeHmacSHA256(body []byte, secret string) string

ComputeHmacSHA256 returns the hex-encoded HMAC-SHA256 of body using secret. Useful for generating test signatures.

func ValidateSignature

func ValidateSignature(body []byte, signatureHeader, secret string) bool

ValidateSignature verifies that the request body matches the signature provided by the Git provider. Supports:

GitHub:    X-Hub-Signature-256: sha256=<hex>
GitLab:    X-Gitlab-Token: <plaintext token>

The signatureHeader should be the raw value of the signature header. Returns true if the signature is valid.

Types

type DeployJob

type DeployJob struct {
	// RepoURL is the clone URL of the repository (e.g., "https://github.com/user/repo.git").
	RepoURL string `json:"repo_url"`

	// CommitHash is the full SHA of the commit that triggered the webhook.
	CommitHash string `json:"commit_hash"`

	// ReceivedAt is the time the webhook was received.
	ReceivedAt time.Time `json:"received_at"`
}

DeployJob represents a deployment request extracted from a webhook payload.

func ParseWebhookPayload

func ParseWebhookPayload(body []byte) (*DeployJob, error)

ParseWebhookPayload attempts to parse a webhook JSON body as a GitHub, GitLab, or generic push event. Returns a DeployJob if successful.

type Queue

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

Queue is a bounded, channel-based deployment job queue. A single worker goroutine processes jobs sequentially, preventing concurrent Docker builds from exhausting server resources.

The queue also performs debouncing: if a job with the same commit hash is already being processed (in-flight), duplicate submissions are silently skipped.

func NewQueue

func NewQueue(capacity int) *Queue

NewQueue creates a deployment queue with the given capacity. capacity determines how many jobs can be buffered before Enqueue returns ErrQueueFull.

func (*Queue) Drain

func (q *Queue) Drain()

Drain blocks until the queue is empty, then returns. Useful for graceful shutdown.

func (*Queue) Enqueue

func (q *Queue) Enqueue(job DeployJob) error

Enqueue submits a deployment job to the queue. Returns ErrQueueFull if the queue buffer is at capacity. Silently skips the job (returns nil) if a job with the same commit hash is already in-flight.

func (*Queue) Len

func (q *Queue) Len() int

Len returns the current number of jobs waiting in the queue.

func (*Queue) StartWorker

func (q *Queue) StartWorker(ctx context.Context, handler func(context.Context, DeployJob) error)

StartWorker begins processing jobs from the queue in a single goroutine. It blocks until ctx is cancelled. Call this in a goroutine if you want the caller to continue.

type Server

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

Server is an HTTP server that receives Git provider webhook events, validates their HMAC signatures, rate-limits by IP, and enqueues deployment jobs.

func NewServer

func NewServer(pipeline *deploy.Pipeline, queue *Queue, port int, secret string) *Server

NewServer creates a webhook server wired to the given pipeline and queue.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start begins listening for webhook events. It blocks until ctx is cancelled, then performs a graceful shutdown.

Jump to

Keyboard shortcuts

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