trampoline

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package trampoline implements an HTTP server that receives GitHub webhook events, validates their signatures, and forwards them as CloudEvents to a broker ingress.

Use NewServer to create a Server configured with a CloudEvents client and webhook secrets. The server implements http.Handler and can be registered with any HTTP mux.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidatePayload

func ValidatePayload(r *http.Request, secrets [][]byte) ([]byte, error)

ValidatePayload validates the payload of a webhook request for a given set of secrets. If any of the secrets are valid, the payload is returned with no error.

Types

type PayloadInfo

type PayloadInfo struct {
	Action     string `json:"action,omitempty"`
	Number     int    `json:"number,omitempty"`
	Repository struct {
		FullName string `json:"full_name,omitempty"`
		Owner    struct {
			Login string `json:"login,omitempty"`
		} `json:"owner,omitempty"`
		Name string `json:"name,omitempty"`
	} `json:"repository,omitempty"`
	Organization struct {
		Login string `json:"login,omitempty"`
	} `json:"organization,omitempty"`
	PullRequest struct {
		Number int  `json:"number,omitempty"`
		Merged bool `json:"merged,omitempty"`
	} `json:"pull_request,omitempty"`
	Issue struct {
		Number          int       `json:"number,omitempty"`
		PullRequestInfo *struct{} `json:"pull_request,omitempty"`
	} `json:"issue,omitempty"`
	CheckRun struct {
		CheckSuite struct {
			PullRequests []struct {
				Number int `json:"number,omitempty"`
			} `json:"pull_requests,omitempty"`
		} `json:"check_suite,omitempty"`
	} `json:"check_run,omitempty"`
	CheckSuite struct {
		PullRequests []struct {
			Number int `json:"number,omitempty"`
		} `json:"pull_requests,omitempty"`
	} `json:"check_suite,omitempty"`
	Comment struct {
		ID int `json:"id,omitempty"`
	} `json:"comment,omitempty"`
	Review struct {
		ID int `json:"id,omitempty"`
	} `json:"review,omitempty"`
}

PayloadInfo is a minimal struct for GitHub webhook payload information, containing only the fields we need to process for our needs of setting cloud event headers.

type Server

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

func NewServer

func NewServer(client cloudevents.Client, opts ServerOptions) *Server
Example
package main

import (
	"fmt"
	"net/http"
	"net/http/httptest"

	"github.com/chainguard-dev/terraform-infra-common/modules/github-events/internal/trampoline"
	cloudevents "github.com/cloudevents/sdk-go/v2"
)

func main() {
	client, err := cloudevents.NewClientHTTP()
	if err != nil {
		panic(err)
	}

	s := trampoline.NewServer(client, trampoline.ServerOptions{
		Secrets: [][]byte{[]byte("my-secret")},
	})

	// The server implements http.Handler.
	req := httptest.NewRequest(http.MethodPost, "/", nil)
	w := httptest.NewRecorder()
	s.ServeHTTP(w, req)
	fmt.Println(w.Code)
}
Output:
403

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ServerOptions

type ServerOptions struct {
	Secrets              [][]byte
	WebhookID            []string
	RequestedOnlyWebhook []string
	OrgFilter            []string
}

Jump to

Keyboard shortcuts

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