webhookClient

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultContentType  = "wrp"
	DefaultDeviceRegexp = ".*"
	DefaultTimeout      = 10 * time.Second
)
View Source
const (
	OutcomeLabel = "outcome"
	ReasonLabel  = "reason"
)

labels

View Source
const (
	// outcomes
	SuccessOutcome = "success"
	FailureOutcome = "failure"
)
View Source
const (
	WebhookRegistrationOutcome = "webhook_registration"
)

Names for our metrics

Variables

View Source
var (
	ErrGetSecretFail = errors.New("failed to get secret")
	ErrMarshalFail   = errors.New("failed to marshal request")
	ErrDoFail        = errors.New("failed to make http request")
	ErrReadFail      = errors.New("failed to read body")
	ErrNon200Resp    = errors.New("received non-200 response")
)

Functions

func Metrics added in v0.2.0

func Metrics() []xmetrics.Metric

Metrics returns the Metrics relevant to this package

func Provide added in v0.2.2

func Provide() fx.Option

Provide bundles all of the constructors needed to create a new periodic registerer.

func ProvideMetrics added in v0.2.2

func ProvideMetrics() fx.Option

ProvideMetrics provides the metrics relevant to this package as uber/fx options.

Types

type Acquirer

type Acquirer interface {
	Acquire() (string, error)
}

Acquirer gets an Authorization value that can be added to an http request. The format of the string returned should be the key, a space, and then the auth string.

type BasicConfig

type BasicConfig struct {
	Timeout         time.Duration
	ClientTransport http.RoundTripper
	RegistrationURL string
	Request         webhook.W
}

BasicConfig holds the configuration options for setting up a BasicRegisterer.

type BasicRegisterer

type BasicRegisterer struct {
	// contains filtered or unexported fields
}

BasicRegisterer sends POST requests to register at the webhook URL provided.

func NewBasicRegisterer

func NewBasicRegisterer(acquirer Acquirer, secret SecretGetter, config BasicConfig) (*BasicRegisterer, error)

NewBasicRegisterer returns a basic registerer set up with the configuration given. If the acquirer or secretGetter are nil or certain configurations are empty, an error will be returned. Otherwise, some config values are set to defaults if they are invalid and a basic registerer is returned.

func (*BasicRegisterer) Register

func (b *BasicRegisterer) Register() error

Register registers to the webhook using the information the basic registerer has.

type Measures added in v0.2.0

type Measures struct {
	WebhookRegistrationOutcome metrics.Counter
}

Measures describes the defined metrics that will be used by clients.

func NewMeasures added in v0.2.0

func NewMeasures(p provider.Provider) *Measures

NewMeasures realizes desired metrics.

type MeasuresIn added in v0.2.2

type MeasuresIn struct {
	fx.In
	WebhookRegistrationOutcome metrics.Counter `name:"webhook_registration"`
}

MeasuresIn is an uber/fx parameter with the webhook registration counter

type PeriodicRegisterer

type PeriodicRegisterer struct {
	// contains filtered or unexported fields
}

PeriodicRegisterer uses a register to attempt to register at an interval. If there is a failure, it will be logged.

func NewPeriodicRegisterer

func NewPeriodicRegisterer(registerer Registerer, interval time.Duration, logger *zap.Logger, measures *Measures) (*PeriodicRegisterer, error)

NewPeriodicRegisterer creates a registerer that attempts to register at the interval given.

func (*PeriodicRegisterer) Register

func (p *PeriodicRegisterer) Register() error

Register is just a wrapper to provide the regular Register functionality, but generally the periodic registerer should be started and stopped.

func (*PeriodicRegisterer) Start

func (p *PeriodicRegisterer) Start()

Start begins the periodic webhook registration.

func (*PeriodicRegisterer) Stop

func (p *PeriodicRegisterer) Stop()

Stop stops the periodic webhook registration.

type PeriodicRegistererIn added in v0.2.2

type PeriodicRegistererIn struct {
	fx.In
	Registerer *BasicRegisterer
	Interval   time.Duration `name:"periodic_registration_interval"`
	Logger     *zap.Logger
	Measures   *Measures
}

PeriodicRegistererIn is an uber/fx parameter with the in information needed to create a new PeriodicRegisterer.

type ReasonCode added in v0.2.0

type ReasonCode int

ReasonCode is a way to describe what went wrong when trying to register for a webhook.

const (
	UnknownReason ReasonCode = iota
	GetSecretFail
	MarshalRequestFail
	AcquireJWTFail
	CreateRequestFail
	DoRequestFail
	ReadBodyFail
	Non200Response
)

func GetReasonCode added in v0.2.0

func GetReasonCode(v interface{}) ReasonCode

GetReasonCode returns the ReasonCode if the object is a ReasonCoder. Otherwise, it returns UnknownReason.

func (ReasonCode) LabelValue added in v0.2.0

func (rc ReasonCode) LabelValue() string

LabelValue returns the metric label value for this reason code, or unknown if it's some wacky value.

type ReasonCoder added in v0.2.0

type ReasonCoder interface {
	ReasonCode() ReasonCode
}

ReasonCoder is anything that can return a ReasonCode.

type Registerer

type Registerer interface {
	Register() error
}

A Registerer attempts to register to a webhook. If there is a problem, an error is returned.

type SecretGetter

type SecretGetter interface {
	GetSecret() (string, error)
}

SecretGetter gets the secret to use when hashing. If getting the secret is unsuccessful, an error can be returned.

Jump to

Keyboard shortcuts

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