Documentation ¶
Overview ¶
Package web implements the webhooks integration.
Index ¶
- func NewWebhookRegistryRPC(webhooks WebhookRegistry, templates TemplateStore) ttnpb.ApplicationWebhookRegistryServer
- func WithCachedHealthStatus(ctx context.Context, h *ttnpb.ApplicationWebhookHealth) context.Context
- type DownlinksConfig
- type Format
- type HTTPClientSink
- type HealthStatusRegistry
- type RegistryCleaner
- type Sink
- type TemplateStore
- type TemplatesConfig
- type WebhookRegistry
- type Webhooks
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewWebhookRegistryRPC ¶
func NewWebhookRegistryRPC(webhooks WebhookRegistry, templates TemplateStore) ttnpb.ApplicationWebhookRegistryServer
NewWebhookRegistryRPC returns a new webhook registry gRPC server.
func WithCachedHealthStatus ¶ added in v3.16.2
WithCachedHealthStatus constructs a context.Context with the provided health status cached.
Types ¶
type DownlinksConfig ¶
type DownlinksConfig struct { PublicAddress string `name:"public-address" description:"Public address of the HTTP webhooks frontend"` PublicTLSAddress string `name:"public-tls-address" description:"Public address of the HTTPS webhooks frontend"` }
DownlinksConfig defines the configuration for the webhook downlink queue operations. For public addresses, the TLS version is preferred when present.
type Format ¶
type Format struct { formatters.Formatter Name string ContentType string }
Format is a format to use for web-based frontends.
type HTTPClientSink ¶
HTTPClientSink contains an HTTP client to make outgoing requests.
type HealthStatusRegistry ¶ added in v3.16.2
type HealthStatusRegistry interface { Get(r *http.Request) (*ttnpb.ApplicationWebhookHealth, error) Set(r *http.Request, f func(*ttnpb.ApplicationWebhookHealth) (*ttnpb.ApplicationWebhookHealth, error)) error }
HealthStatusRegistry is a registry for webhook health status.
func NewCachedHealthStatusRegistry ¶ added in v3.16.2
func NewCachedHealthStatusRegistry(registry HealthStatusRegistry) HealthStatusRegistry
NewCachedHealthStatusRegistry constructs a HealthStatusRegistry which allows the Get response to be cached.
func NewHealthStatusRegistry ¶ added in v3.16.2
func NewHealthStatusRegistry(registry WebhookRegistry) HealthStatusRegistry
NewHealthStatusRegistry constructs a HealthStatusRegistry on top of the provided WebhookRegistry.
type RegistryCleaner ¶ added in v3.15.2
type RegistryCleaner struct { WebRegistry WebhookRegistry LocalSet map[string]struct{} }
RegistryCleaner is a service responsible for cleanup of the webhook registry.
func (*RegistryCleaner) CleanData ¶ added in v3.15.2
func (cleaner *RegistryCleaner) CleanData(ctx context.Context, isSet map[string]struct{}) error
CleanData cleans registry application data.
func (*RegistryCleaner) DeleteApplicationData ¶ added in v3.15.2
func (cleaner *RegistryCleaner) DeleteApplicationData(ctx context.Context, applicationList []string) error
DeleteApplicationData deletes registry application data of all applications in the application list.
func (*RegistryCleaner) RangeToLocalSet ¶ added in v3.15.2
func (cleaner *RegistryCleaner) RangeToLocalSet(ctx context.Context) error
RangeToLocalSet returns a set of applications that have data in the registry.
type Sink ¶
Sink processes HTTP requests.
func NewHealthCheckSink ¶ added in v3.16.2
func NewHealthCheckSink(sink Sink, registry HealthStatusRegistry, unhealthyAttemptsThreshold int, unhealthyRetryInterval time.Duration) Sink
NewHealthCheckSink creates a Sink that records the health status of the webhooks and stops them from executing if too many fail in a specified interval of time.
func NewPooledSink ¶ added in v3.15.0
func NewPooledSink(ctx context.Context, c workerpool.Component, sink Sink, workers int, queueSize int) Sink
NewPooledSink creates a Sink that queues requests and processes them in parallel workers.
type TemplateStore ¶
type TemplateStore interface { // GetTemplate returns the template with the given identifiers. GetTemplate(ctx context.Context, req *ttnpb.GetApplicationWebhookTemplateRequest) (*ttnpb.ApplicationWebhookTemplate, error) // ListTemplates returns the available templates. ListTemplates(ctx context.Context, req *ttnpb.ListApplicationWebhookTemplatesRequest) (*ttnpb.ApplicationWebhookTemplates, error) }
TemplateStore contains the webhook templates.
type TemplatesConfig ¶
type TemplatesConfig struct { Static map[string][]byte `name:"-"` Directory string `name:"directory" description:"Retrieve the webhook templates from the filesystem"` URL string `name:"url" description:"Retrieve the webhook templates from a web server"` LogoBaseURL string `name:"logo-base-url" description:"The base URL for the logo storage"` HTTPClient *http.Client `name:"-"` }
TemplatesConfig defines the configuration for the webhook templates registry.
func (TemplatesConfig) NewTemplateStore ¶
func (c TemplatesConfig) NewTemplateStore() (TemplateStore, error)
NewTemplateStore returns a TemplateStore based on the configuration.
type WebhookRegistry ¶
type WebhookRegistry interface { // Get returns the webhook by its identifiers. Get(ctx context.Context, ids *ttnpb.ApplicationWebhookIdentifiers, paths []string) (*ttnpb.ApplicationWebhook, error) // List returns all webhooks of the application. List(ctx context.Context, ids *ttnpb.ApplicationIdentifiers, paths []string) ([]*ttnpb.ApplicationWebhook, error) // Set creates, updates or deletes the webhook by its identifiers. Set(ctx context.Context, ids *ttnpb.ApplicationWebhookIdentifiers, paths []string, f func(*ttnpb.ApplicationWebhook) (*ttnpb.ApplicationWebhook, []string, error)) (*ttnpb.ApplicationWebhook, error) // Range ranges over the webhooks and calls the callback function, until false is returned. Range(ctx context.Context, paths []string, f func(context.Context, ttnpb.ApplicationIdentifiers, *ttnpb.ApplicationWebhook) bool) error }
WebhookRegistry is a store for webhooks.
type Webhooks ¶
type Webhooks interface { ttnweb.Registerer Registry() WebhookRegistry }
Webhooks is an interface for registering incoming webhooks for downlink and creating a subscription to outgoing webhooks for upstream data.
func NewWebhooks ¶
func NewWebhooks(ctx context.Context, server io.Server, registry WebhookRegistry, target Sink, downlinks DownlinksConfig) (Webhooks, error)
NewWebhooks returns a new Webhooks.