hooks

package
v0.0.0-...-64f7ebe Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Webhook

type Webhook struct {
	// A unique ID for the webhook.
	Id string `json:"id"`

	// The URL that the webhook will request.
	Url string `json:"url"`

	// A secret used for generating an HMAC-SHA1 signature for the payload.
	Secret string `json:"secret"`

	// Whether or not the webhook is enabled.
	Enabled bool `json:"enabled"`

	// A sorted list of events that this webhook applies to.
	Events []string `json:"events"`

	// A sorted list of repository names that this webhook applies to.
	Repos []string `json:"repos"`
}

func (Webhook) SignPayload

func (hook Webhook) SignPayload(payload []byte) string

Return an HMAC-SHA1 signature of the payload using the hook's secret.

func (Webhook) Validate

func (hook Webhook) Validate(repos map[string]struct{}) error

Validate a hook.

type WebhookStore

type WebhookStore map[string]*Webhook

A collection of webhooks, mapped to by their `Id`.

func LoadStore

func LoadStore(path string, repositories map[string]struct{}) (WebhookStore, error)

Load a collection of webhooks from the given reader.

The store is expected to be unmarshalled from JSON.

`repositories` must be a set of all repository names.

If a webhook references a non-extant repository, that repository will be stripped from the loaded webhook. Likewise, if a webhook references an invalid event that too will be stripped.

As a side effect, the `Events` and `Repos` fields of each hook will be sorted.

func ReadStore

func ReadStore(r io.Reader, repositories map[string]struct{}) (WebhookStore, error)

Read a collection of webhooks from the given reader.

Callers should prefer the higher-level `LoadStore` over this function.

func (WebhookStore) ForEach

func (store WebhookStore) ForEach(event, repoName string, f func(h Webhook) error) []error

Iterate over all the webhooks that match the specified event and repository.

`f` will be called for each repository. Errors will not stop iteration from continuing. `f` will only be called for webhooks that are enabled for the given event and repository name.

All errors will be returned as a slice (which will be `nil` if there were no errors).

func (WebhookStore) Save

func (s WebhookStore) Save(path string) error

Save the WebhookStore.

The store will first be written to a temporary file and will then be moved to the target location. This is done to avoid `rb-gateway trigger-webhooks` processess from reading the file as we are writing to it, causing errors.

func (WebhookStore) Write

func (s WebhookStore) Write(w io.Writer) error

Write the store to a writer.

The store will be marshalled as JSON.

Callers should prefer the higher-level `WebhookStore.Save` over this function.

Jump to

Keyboard shortcuts

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