webhook

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ListSize                     = "webhook_list_size_value"
	NotificationUnmarshallFailed = "notification_unmarshall_failed_count"
)
View Source
const (
	DEFAULT_EXPIRATION_DURATION time.Duration = time.Second * 300
)
View Source
const (
	DEFAULT_UNDERTAKER_INTERVAL time.Duration = time.Minute
)

Variables

This section is empty.

Functions

func Metrics

func Metrics() []xmetrics.Metric

Metrics returns the defined metrics as a list

Types

type Factory

type Factory struct {

	// Tick is an optional function that produces a channel for time ticks.
	// Test code can set this field to something that returns a channel under the control of the test.
	Tick func(time.Duration) <-chan time.Time `json:"-"`

	// UndertakerInterval is how often the undertaker is invoked
	UndertakerInterval time.Duration `json:"undertakerInterval"`

	// internal handler for AWS SNS Server
	AWS.Notifier `json:"-"`

	// StartConfig is the contains the data need to obtain the current system's listeners
	Start *StartConfig `json:"start"`
	// contains filtered or unexported fields
}

Factory is a classic Factory Object for various webhook things.

func NewFactory

func NewFactory(v *viper.Viper) (f *Factory, err error)

NewFactory creates a Factory from a Viper environment. This function always returns a non-nil Factory instance.

This example uses Viper, which I highly recommend. You could just pass an io.Reader too, and use the encoding/json package. In any case, allowing the configuration source to be nil makes a lot of things easier on clients, like creating a test Factory for tests in client code.

func (*Factory) NewRegistryAndHandler

func (f *Factory) NewRegistryAndHandler(registry xmetrics.Registry) (Registry, http.Handler)

NewRegistryAndHandler returns a List instance for accessing webhooks and an HTTP handler which can receive updates from external systems.

func (*Factory) Prune

func (f *Factory) Prune(items []W) (list []W)

func (*Factory) SetExternalUpdate

func (f *Factory) SetExternalUpdate(fn func([]W))

SetExternalUpdate is a specified function that takes an []W argument This function is called when monitor.changes receives a message

func (*Factory) SetList

func (f *Factory) SetList(ul UpdatableList)

type List

type List interface {
	Len() int
	Get(int) *W
}

List is a read-only random access interface to a set of W's We don't necessarily need an implementation of just this interface alone.

type Registry

type Registry struct {
	Changes chan []W
	// contains filtered or unexported fields
}

func NewRegistry

func NewRegistry(mon *monitor) Registry

func (*Registry) GetRegistry

func (r *Registry) GetRegistry(rw http.ResponseWriter, req *http.Request)

get is an api call to return all the registered listeners

func (*Registry) UpdateRegistry

func (r *Registry) UpdateRegistry(rw http.ResponseWriter, req *http.Request)

update is an api call to processes a listenener registration for adding and updating

type Result

type Result struct {
	Hooks []W
	Error error
}

type StartConfig

type StartConfig struct {
	// maximum time allowed to wait for data to be retrieved
	Duration time.Duration `json:"duration"`

	// path to query for current hooks
	ApiPath string `json:"apiPath"`

	AuthHeader string `json:"authHeader"`

	// sat configuration data for requesting token
	Sat struct {
		// url path
		Path string `json:"path"`

		// client id
		Id string `json:"id"`

		// client secret
		Secret string `json:"secret"`

		// client capabilities
		Capabilities string `json:"capabilities"`

		// the obtained sat token
		Token token
	} `json:"sat"`
	// contains filtered or unexported fields
}

func NewStartFactory

func NewStartFactory(v *viper.Viper) (sc *StartConfig)

func (*StartConfig) GetCurrentSystemsHooks

func (sc *StartConfig) GetCurrentSystemsHooks(rc chan Result)

type UpdatableList

type UpdatableList interface {
	List

	// Update performs a bulk update of this webhooks known to this list
	Update([]W)

	// Filter atomically filters the elements of this list
	Filter(func([]W) []W)
}

UpdatableList is mutable list that can be updated en masse

func NewList

func NewList(initial []W) UpdatableList

NewList just creates an UpdatableList. Don't forget: NewList(nil) is valid!

type W

type W struct {
	// Configuration for message delivery
	Config struct {
		// The URL to deliver messages to.
		URL string `json:"url"`

		// The content-type to set the messages to (unless specified by WRP).
		ContentType string `json:"content_type"`

		// The secret to use for the SHA1 HMAC.
		// Optional, set to "" to disable behavior.
		Secret string `json:"secret,omitempty"`

		// The max number of times to retry for webhook
		MaxRetryCount int `json:"max_retry_count,omitempty"`

		// alt_urls is a list of explicit URLs that should be round robin on faliure
		AlternativeURLs []string `json:"alt_urls,omitempty"`
	} `json:"config"`

	// The URL to notify when we cut off a client due to overflow.
	// Optional, set to "" to disable behavior
	FailureURL string `json:"failure_url"`

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

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

	// The specified duration for this hook to live
	Duration time.Duration `json:"duration"`

	// The absolute time when this hook is to be disabled
	Until time.Time `json:"until"`

	// The address that performed the registration
	Address string `json:"registered_from_address"`
}

W is the structure that represents the Webhook listener data we share.

(Note to Wes: this follows the golang naming conventions. webhook.Webhook "stutters", and this type is really the central type of this package. Calling it a single letter is the norm. This could also go in the server package, in which case I'd change the name to Webhook, since service.Webhook works better. See https://blog.golang.org/package-names)

func NewW

func NewW(jsonString []byte, ip string) (w *W, err error)

func (*W) ID

func (w *W) ID() string

ID creates the canonical string identifing a WebhookListener

type WebhookMetrics

type WebhookMetrics struct {
	ListSize                     metrics.Gauge
	NotificationUnmarshallFailed metrics.Counter
}

func ApplyMetricsData

func ApplyMetricsData(registry xmetrics.Registry) (m WebhookMetrics)

ApplyMetricsData is used for setting the counter values on the WebhookMetrics when stored and accessing for later use

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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