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 ¶
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
Click to show internal directories.
Click to hide internal directories.