web

package
v3.13.3 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2021 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package web implements the webhooks integration.

Index

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.

Types

type ControllableSink

type ControllableSink interface {
	Sink
	Run(context.Context) error
}

ControllableSink is a controllable Sink.

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

type HTTPClientSink struct {
	*http.Client
}

HTTPClientSink contains an HTTP client to make outgoing requests.

func (*HTTPClientSink) Process

func (s *HTTPClientSink) Process(req *http.Request) error

Process uses the HTTP client to perform the request.

type QueuedSink

type QueuedSink struct {
	Target  Sink
	Queue   chan *http.Request
	Workers int
}

QueuedSink is a ControllableSink with queue.

func (*QueuedSink) Process

func (s *QueuedSink) Process(req *http.Request) error

Process sends the request to the queue. This method returns immediately. An error is returned when the queue is full.

func (*QueuedSink) Run

func (s *QueuedSink) Run(ctx context.Context) error

Run starts concurrent workers to process messages from the queue. If Target is a ControllableSink, this method runs the target. This method blocks until the target (if controllable) and all workers are done.

type Sink

type Sink interface {
	Process(*http.Request) error
}

Sink processes HTTP requests.

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)
}

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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