Documentation
¶
Overview ¶
Package registry is the registry of webhooks: they're registered, for a session, with the protocol of the service which calls them, and listed, changed, and deleted, and their calls are received, and kept, in its store
Index ¶
- Constants
- func Hash(token string) []byte
- type Opt
- type Received
- type Registry
- func (r *Registry) Call(ctx context.Context, token string, req *http.Request) (_ Received, err error)
- func (r *Registry) CreateWebhook(ctx context.Context, meta schema.WebhookMeta) (_ schema.WebhookToken, err error)
- func (r *Registry) DeleteWebhook(ctx context.Context, id uint64) (_ schema.Webhook, err error)
- func (r *Registry) GetCall(ctx context.Context, id uint64) (_ schema.Call, err error)
- func (r *Registry) GetWebhook(ctx context.Context, id uint64) (_ schema.Webhook, err error)
- func (r *Registry) ListCalls(ctx context.Context, req schema.CallListRequest) (_ schema.CallList, err error)
- func (r *Registry) ListWebhooks(ctx context.Context, req schema.WebhookListRequest) (_ schema.WebhookList, err error)
- func (r *Registry) Run(ctx context.Context, logger *slog.Logger) error
- func (r *Registry) UpdateWebhook(ctx context.Context, id uint64, req schema.WebhookRequest) (_ schema.Webhook, err error)
Constants ¶
const DefaultMaxBody = 4 << 20
DefaultMaxBody is the largest body of a call which is received, by default, which is larger than services send, such as GitHub's 25 MB limit, which few events are near
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Opt ¶
type Opt func(*opt) error
Opt is an option of the registry
func WithBroadcaster ¶
func WithBroadcaster(b *broadcaster.Broadcaster) Opt
WithBroadcaster sets the broadcaster which Run watches, which the store publishes its changes to, such as the SQLite store's, with its WithBroadcaster: the webhooks, and calls, which are created, updated and deleted, of store.WebhookTable, and store.CallTable
func WithMaxBody ¶
WithMaxBody sets the largest body of a call which is received, in bytes, beyond which it isn't
func WithTracer ¶
WithTracer sets the tracer which traces the registry's methods, or none, when it's nil
type Received ¶
type Received struct {
// Call is the call, as it was kept, with its serial number
Call schema.Call
// Handshake is the response to a handshake, when it was one
Handshake []byte
// IsHandshake is whether it was a handshake
IsHandshake bool
// Duplicate is whether it was a delivery which was sent again
Duplicate bool
}
Received is what a request of a webhook was: a call, which was kept, a handshake, which a service checks the webhook with, as it's registered, whose response is returned, and which isn't kept, or a delivery which was sent again, which isn't kept again
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is the registry of webhooks, of its store
func (*Registry) Call ¶
func (r *Registry) Call(ctx context.Context, token string, req *http.Request) (_ Received, err error)
Call receives a request of the webhook with the token, which is in the URL its service calls, and returns what it was: a handshake, whose response is returned, a delivery which was sent again, or a call, which is kept, as it was received, with what its protocol says happened, and whether it was verified, with the webhook's secret. A call which is refused, such as one which isn't verified, with a webhook's secret, or whose body is too large, is kept too, with why, so a secret which is wrong can be seen, and its error is returned.
Returns ErrNotFound when no webhook has the token, ErrForbidden when the call isn't verified, and ErrBadParameter when its body is larger than the registry's largest, or isn't what its content type says.
func (*Registry) CreateWebhook ¶
func (r *Registry) CreateWebhook(ctx context.Context, meta schema.WebhookMeta) (_ schema.WebhookToken, err error)
CreateWebhook registers a webhook, of the session, and the protocol of its type, or generic, when it has none, and returns it, with its token, which is in the URL its service calls, which isn't returned again. Returns ErrBadParameter when it has no session, or description, or its type isn't a protocol.
func (*Registry) DeleteWebhook ¶
DeleteWebhook deletes the webhook, and its calls, so its URL stops working at once, and returns it, as it was, without its secret, or ErrNotFound when there's none
func (*Registry) GetCall ¶
GetCall returns the call with the serial number, or ErrNotFound when there's none
func (*Registry) GetWebhook ¶
GetWebhook returns the webhook with the serial number, without its secret, or ErrNotFound when there's none
func (*Registry) ListCalls ¶
func (r *Registry) ListCalls(ctx context.Context, req schema.CallListRequest) (_ schema.CallList, err error)
ListCalls returns the calls, of the webhook, or the session's webhooks, when the request has one, which were accepted, or refused, or both, of its status, after the call with its serial number, oldest first, so what watches them carries on after the last it had, and how many there are after it. Returns ErrBadParameter when its status isn't one.
func (*Registry) ListWebhooks ¶
func (r *Registry) ListWebhooks(ctx context.Context, req schema.WebhookListRequest) (_ schema.WebhookList, err error)
ListWebhooks returns the webhooks, of the session, when the request has one, newest first, without their secrets
func (*Registry) Run ¶
Run watches the store's changes, with the broadcaster it publishes them to, and logs them to the logger: the webhooks which are created, changed and deleted, and the calls which are received, which were accepted, or refused, with why, and deleted, until the context is cancelled, when it returns nil. Without a broadcaster, it waits until then. It returns the broadcaster's error, when it stops running first.
func (*Registry) UpdateWebhook ¶
func (r *Registry) UpdateWebhook(ctx context.Context, id uint64, req schema.WebhookRequest) (_ schema.Webhook, err error)
UpdateWebhook changes what the request sets, such as the secret, which a service gives once it's registered there, such as Pidgeon, and returns the webhook, without its secret, or ErrNotFound when there's none, or ErrBadParameter when its description is empty