mhook

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PollCounter          = "webhook_polls_total"
	WebhookListSizeGauge = "webhook_list_size_value"
)

Names

View Source
const (
	SuccessOutcome = "success"
	FailureOutcome = "failure"
)

Label Values

View Source
const (
	// ClientIDHeader provides a fallback method for fetching the client ID of users
	// registering their webhooks. The main method fetches this value from the claims of
	// the authentication JWT.
	ClientIDHeader = "X-Xmidt-Client-Id"
)
View Source
const (
	OutcomeLabel = "outcome"
)

Labels

Variables

This section is empty.

Functions

func Initialise

func Initialise()

func Metrics added in v1.0.3

func Metrics() []xmetrics.Metric

Metrics returns the Metrics relevant to this package

func NewAddWebhookHandler added in v1.0.3

func NewAddWebhookHandler(s Service) http.Handler

func NewGetAllWebhooksHandler added in v1.0.3

func NewGetAllWebhooksHandler(s Service) http.Handler

Types

type Service added in v1.0.3

type Service interface {
	Add(owner string, w *Webhook) error
	AllWebhooks(owner string) ([]*Webhook, error)
	AddWebhookFromYaml(yamlFile string) error
}

Service describes the core operations around webhook subscriptions.

func Initialize added in v1.0.3

func Initialize(watches ...Watch) (Service, func(), error)

type Watch added in v1.0.3

type Watch interface {
	Update([]Webhook)
}

Watch is the interface for listening for webhook subcription updates. Updates represent the latest known list of subscriptions.

type WatchConfig added in v1.0.10

type WatchConfig struct {
	// Webhooks contains the list of webhooks to be used by the webhook service
	Webhooks []Webhook

	// WatchUpdateInterval is the duration between each update to all watchers.
	WatchUpdateInterval time.Duration
}

Config provides the different options for the initializing the wehbook service.

type WatchFunc added in v1.0.3

type WatchFunc func([]Webhook)

WatchFunc allows bare functions to pass as Watches.

func (WatchFunc) Update added in v1.0.3

func (f WatchFunc) Update(webhooks []Webhook)

type Webhook added in v1.0.3

type Webhook struct {
	// Address is the subscription request origin HTTP Address.
	Address string `json:"registered_from_address"`

	// Config contains data to inform how events are delivered.
	Config struct {
		// URL is the HTTP URL to deliver messages to.
		URL string `json:"url"`

		// ContentType is content type value to set WRP messages to (unless already specified in the WRP).
		ContentType string `json:"content_type"`

		// Secret is the string value for the SHA1 HMAC.
		// (Optional, set to "" to disable behavior).
		Secret string `json:"secret,omitempty"`

		// AlternativeURLs is a list of explicit URLs that should be round robin through on failure cases to the main URL.
		AlternativeURLs []string `json:"alt_urls,omitempty"`
	} `json:"config"`

	// FailureURL is the URL used to notify subscribers when they've been cut off due to event overflow.
	// Optional, set to "" to disable notifications.
	FailureURL string `json:"failure_url"`

	// Events is the list of regular expressions to match an event type against.
	Events []string `json:"events"`

	// Matcher type contains values to match against the metadata.
	Matcher struct {
		// DeviceID is the list of regular expressions to match device id type against.
		DeviceID []string `json:"device_id"`
	} `json:"matcher,omitempty"`

	// Duration describes how long the subscription lasts once added.
	// Deprecated. User input is ignored and value is always 5m.
	Duration time.Duration `json:"duration"`

	// Until describes the time this subscription expires.
	Until time.Time `json:"until"`
}

Webhook contains all the information needed to serve events to webhook listeners.

type WebhookStore added in v1.0.3

type WebhookStore interface {
	Add(owner string, w *Webhook) error
	Delete(owner string, url string) error
	AllWebhooks(owner string) ([]*Webhook, error)
}

func NewWebhookStore added in v1.0.3

func NewWebhookStore(logger *loggerGroup) WebhookStore

Jump to

Keyboard shortcuts

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