xwebhook

package
v1.11.9 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package xwebhook provides an event webhook registry component for XMiDT services.

Deprecated: xwebhook has moved to https://github.com/xmidt-org/ancla.

This package is frozen and no new functionality will be added.

Index

Constants

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 (
	WebhookListSizeGauge = "webhook_list_size_value"
)

Names

Variables

This section is empty.

Functions

func Metrics

func Metrics() []xmetrics.Metric

Metrics returns the Metrics relevant to this package

func NewAddWebhookHandler

func NewAddWebhookHandler(s Service) http.Handler

func NewGetAllWebhooksHandler

func NewGetAllWebhooksHandler(s Service) http.Handler

Types

type Config

type Config struct {
	// Argus contains all the argus specific configurations
	Argus chrysom.ClientConfig

	// 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 PushReader

type PushReader interface {
	Pusher
	Reader
}

type Pusher

type Pusher interface {
	// Push applies user configurable for registering an item returning the id
	// i.e. updated the storage with said item.
	Push(item model.Item, owner string) (string, error)

	// Remove will remove the item from the store
	Remove(id string, owner string) (model.Item, error)
}

type Reader

type Reader interface {
	// GeItems will return all the current items or an error.
	GetItems(owner string) ([]model.Item, error)
}

type Service

type Service interface {
	// Add adds the given owned webhook to the current list of webhooks. If the operation
	// succeeds, a non-nil error is returned.
	Add(owner string, w *Webhook) error

	// AllWebhooks lists all the current webhooks for the given owner.
	// If an owner is not provided, all webhooks are returned.
	AllWebhooks(owner string) ([]Webhook, error)
}

Service describes the core operations around webhook subscriptions. Initialize() provides a service ready to use and the controls around watching for updates.

func Initialize

func Initialize(cfg *Config, provider xmetrics.Registry, watches ...Watch) (Service, func(), error)

Initialize builds the webhook service from the given configuration. It allows adding watchers for the internal subscription state. Call the returned function when you are done watching for updates.

type Watch

type Watch interface {
	Update([]Webhook)
}

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

type WatchFunc

type WatchFunc func([]Webhook)

WatchFunc allows bare functions to pass as Watches.

func (WatchFunc) Update

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

type Webhook

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.

Jump to

Keyboard shortcuts

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