Documentation
¶
Index ¶
- Variables
- type CancelEventListenerFunc
- type Decorator
- type DecoratorFunc
- type Listener
- func (l *Listener) Accept(secrets []string)
- func (l *Listener) AddAuthorizeEventListener(listener event.AuthorizeListener) CancelEventListenerFunc
- func (l *Listener) AddRegistrationEventListener(listener event.RegistrationListener) CancelEventListenerFunc
- func (l *Listener) AddTokenizeEventListener(listener event.TokenizeListener) CancelEventListenerFunc
- func (l *Listener) Authorize(r *http.Request, t Token) error
- func (l *Listener) Register(ctx context.Context, secret ...string) error
- func (l *Listener) Stop()
- func (l *Listener) String() string
- func (l *Listener) Tokenize(r *http.Request) (*token, error)
- type Option
- func AcceptCustom(name string, h func() hash.Hash) Option
- func AcceptNoHash() Option
- func AcceptSHA1() Option
- func AcceptSHA256() Option
- func AcceptedSecrets(secrets ...string) Option
- func DecorateRequest(d Decorator) Option
- func HTTPClient(c *http.Client) Option
- func Interval(i time.Duration) Option
- func Once() Option
- func WebhookOpts(opts ...webhook.Option) Option
- func WithAuthorizeEventListener(listener event.AuthorizeListener, cancel ...*CancelEventListenerFunc) Option
- func WithRegistrationEventListener(listener event.RegistrationListener, cancel ...*CancelEventListenerFunc) Option
- func WithTokenizeEventListener(listener event.TokenizeListener, cancel ...*CancelEventListenerFunc) Option
- type Token
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInput is returned when an invalid input is provided. ErrInput = errors.New("invalid input") // ErrInvalidTokenHeader is returned when the token header is invalid. ErrInvalidTokenHeader = errors.New("invalid token header") // ErrRegistrationFailed is returned when the webhook registration fails. ErrRegistrationFailed = errors.New("registration failed") // ErrRegistrationNotAttempted is returned when the webhook registration // was not attempted. ErrRegistrationNotAttempted = errors.New("registration not attempted") // ErrNotAcceptedHash is returned when the hash is not accepted, because it // is not in the list of accepted hashes. ErrNotAcceptedHash = errors.New("not accepted hash") // ErrDecoratorFailed is returned when the decorator returns an error. ErrDecoratorFailed = errors.New("decorator failed") // ErrNewRequestFailed is returned when the request cannot be created. ErrNewRequestFailed = errors.New("new request failed") // ErrInvalidHeaderFormat is returned when the header is not in the correct // format. ErrInvalidHeaderFormat = errors.New("invalid header format") // ErrInvalidAlgorithm is returned when the algorithm is not supported. ErrAlgorithmNotFound = errors.New("algorithm not found") // ErrNoToken is returned when the token is not found. ErrNoToken = errors.New("no token") // ErrInvalidSignature is returned when the signature is invalid. ErrInvalidSignature = errors.New("invalid signature") // ErrUnableToReadBody is returned when the body cannot be read. ErrUnableToReadBody = errors.New("unable to read body") )
Functions ¶
This section is empty.
Types ¶
type CancelEventListenerFunc ¶ added in v0.5.0
type CancelEventListenerFunc func()
CancelEventListenerFunc removes the listener it's associated with and cancels any future events sent to that listener.
A CancelEventListenerFunc is idempotent: after the first invocation, calling this closure will have no effect.
type Decorator ¶ added in v0.5.0
A Decorator decorates an http request before it is sent to the webhook registration endpoint.
type DecoratorFunc ¶ added in v0.5.0
The Decorator type is an adapter to allow the use of ordinary functions as decorators. If f is a function with the appropriate signature, DecoratorFunc(f) is a Decorator that calls f.
func (DecoratorFunc) Decorate ¶ added in v0.5.0
func (d DecoratorFunc) Decorate(r *http.Request) error
func (DecoratorFunc) String ¶ added in v0.5.0
func (d DecoratorFunc) String() string
type Listener ¶ added in v0.4.0
type Listener struct {
// contains filtered or unexported fields
}
Listener provides a way to register a webhook and validate the callbacks. It can be configured to register the webhook at a given interval, as well as it can also be configured to accept multiple secrets and hash algorithms.
func New ¶ added in v0.4.0
New creates a new webhook listener with the given registration and options.
func (*Listener) Accept ¶ added in v0.4.0
Accept defines the entire list of secrets to accept for the webhook callbacks. If any of the secrets match the secret in the token, the request will be authorized.
func (*Listener) AddAuthorizeEventListener ¶ added in v0.5.0
func (l *Listener) AddAuthorizeEventListener(listener event.AuthorizeListener) CancelEventListenerFunc
AddAuthorizeEventListener adds an event listener to the webhook listener. The listener will be called for each event that occurs. The returned function can be called to remove the listener.
func (*Listener) AddRegistrationEventListener ¶ added in v0.5.0
func (l *Listener) AddRegistrationEventListener(listener event.RegistrationListener) CancelEventListenerFunc
AddRegistrationEventListener adds an event listener to the webhook listener. The listener will be called for each event that occurs. The returned function can be called to remove the listener.
func (*Listener) AddTokenizeEventListener ¶ added in v0.5.0
func (l *Listener) AddTokenizeEventListener(listener event.TokenizeListener) CancelEventListenerFunc
AddTokenizeEventListener adds an event listener to the webhook listener. The listener will be called for each event that occurs. The returned function can be called to remove the listener.
func (*Listener) Authorize ¶ added in v0.4.0
Authorize validates that the request body matches the hash and secret provided in the token.
func (*Listener) Register ¶ added in v0.4.0
Register registers the webhook listener using the optional specified secret. If the interval is greater than 0 the registrations will continue until Stop() is called or the parent context is canceled. If the listener is already running, the secret will be updated immediately. If the secret is not provided, the current secret will be used. Only the first secret will be used if multiple secrets are provided.
func (*Listener) Stop ¶ added in v0.4.0
func (l *Listener) Stop()
Stop stops the webhook listener. If the listener is not running, this is a no-op.
type Option ¶ added in v0.4.0
Option is an interface that is used to configure the webhook listener.
func AcceptCustom ¶ added in v0.4.0
AcceptCustom is an option that sets the hash to use for the webhook callback validation to use. A nil hash is not accepted.
func AcceptNoHash ¶ added in v0.4.0
func AcceptNoHash() Option
AcceptNoHash enables the use of no hash for the webhook listener callback validation.
USE WITH CAUTION.
func AcceptSHA1 ¶ added in v0.4.0
func AcceptSHA1() Option
AcceptSHA1 enables the use of the sha1 hash for the webhook listener callback validation.
func AcceptSHA256 ¶ added in v0.4.0
func AcceptSHA256() Option
AcceptSHA256 enables the use of the sha256 hash for the webhook listener callback validation.
func AcceptedSecrets ¶ added in v0.4.0
AcceptedSecrets is an option that provides the list of secrets accepted by the webhook listener when validating the callback event. A valid hash (or multiple) must be provided as well.
func DecorateRequest ¶ added in v0.5.0
DecorateRequest is an option that provides the function to use to decorate the http request before it is sent to the webhook registration endpoint. This is useful for adding headers or other information to the request.
Examples of this include adding an authorization header, or additional headers to the request.
Multiple DecorateRequest options can be provided. They will be called in the order they are provided.
func HTTPClient ¶ added in v0.4.0
HTTPClient is an option that provides the http client to use for the webhook listener registration to use. A nil value will cause the default http client to be used.
func Interval ¶ added in v0.4.0
Interval is an option that sets the interval to wait between webhook registration attempts. The default is to only register once. This option must be greater than or equal to 0. A value of 0 will cause the webhook to only be registered once.
func Once ¶ added in v0.4.0
func Once() Option
Once is an option that sets the webhook to only be registered once. This is the default behavior.
func WebhookOpts ¶ added in v0.4.0
func WebhookOpts(opts ...webhook.Option) Option
WebhookOpts is an option that provides the webhook.Options to apply during the validation of the registration of the webhook.
func WithAuthorizeEventListener ¶ added in v0.6.0
func WithAuthorizeEventListener(listener event.AuthorizeListener, cancel ...*CancelEventListenerFunc) Option
WithRegistrationEventListener is an option that provides the listener to use for webhook registration events. If the optional cancel parameter is provided, it will be set to a function that can be used to cancel the listener.
func WithRegistrationEventListener ¶ added in v0.6.0
func WithRegistrationEventListener(listener event.RegistrationListener, cancel ...*CancelEventListenerFunc) Option
WithRegistrationEventListener is an option that provides the listener to use for webhook registration events. If the optional cancel parameter is provided, it will be set to a function that can be used to cancel the listener.
func WithTokenizeEventListener ¶ added in v0.6.0
func WithTokenizeEventListener(listener event.TokenizeListener, cancel ...*CancelEventListenerFunc) Option
WithTokenizeEventListener is an option that provides the listener to use for webhook tokenize events. If the optional cancel parameter is provided, it will be set to a function that can be used to cancel the listener.
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
examples
|
|
basicListener
Module
|
|
configurableListener
Module
|
|
timedListener
Module
|