webhook

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: MIT Imports: 8 Imported by: 1

README

webhook

Golang parser for webhooks. Not a server, though it could be integrated with one.

Build Status Go Report Card GoDoc

Installation

$ go get gopkg.in/arxdsilva/webhook.v0

Usage

Given an incoming *http.Request representing a webhook signed with a secret, use webhook to validate and parse its content:

secret := []byte("don't tell!")
hook, err := webhook.Parse(secret, req)

Plays nicely with the google/go-github client!

evt := github.PullRequestEvent{}
if err := json.Unmarshal(hook.Payload, &evt); err != nil {
  fmt.Println("Invalid JSON?", err)
}

Documentation

Overview

Package githubhook implements handling and verification of github webhooks

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSignature      = errors.New("No signature!")
	ErrUnknownMethod    = errors.New("Unknown method!")
	ErrInvalidSignature = errors.New("Invalid signature")
)

Functions

func SignBody added in v0.0.3

func SignBody(secret, body []byte) []byte

Types

type Hook

type Hook struct {

	// Id specifies the Id of a github webhook request.
	//
	// Id is extracted from the inbound request's `X-Github-Delivery` header.
	Id string

	// Event specifies the event name of a github webhook request.
	//
	// Event is extracted from the inbound request's `X-GitHub-Event` header.
	// See: https://developer.github.com/webhooks/#events
	Event string

	// Signature specifies the signature of a github webhook request.
	//
	// Signature is extracted from the inbound request's `X-Hub-Signature` header.
	Signature string

	// Payload contains the raw contents of the webhook request.
	//
	// Payload is extracted from the JSON-formatted body of the inbound request.
	Payload []byte
}

Hook is an inbound github webhook

func New

func New(req *http.Request) (hook *Hook, err error)

New reads a Hook from an incoming HTTP Request.

func Parse

func Parse(secret []byte, req *http.Request) (hook *Hook, err error)

Parse reads and verifies the hook in an inbound request.

func (*Hook) Extract

func (h *Hook) Extract(dst interface{}) error

Extract unmarshals Payload into a destination interface.

func (*Hook) SignedBy

func (h *Hook) SignedBy(secret []byte) bool

SignedBy checks that the provided secret matches the hook Signature

Implements validation described in github's documentation: https://developer.github.com/webhooks/securing/

Jump to

Keyboard shortcuts

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