Back to godoc.org

Package web

v0.0.0-...-c44bc7d
Latest Go to latest

The highest tagged major version is v3.

Published: Feb 6, 2020 | License: Apache-2.0 | Module: go.thethings.network/lorawan-stack

Overview

Package web implements the webhooks integration.

Index

func NewWebhookRegistryRPC

func NewWebhookRegistryRPC(webhooks WebhookRegistry, templates *TemplateStore) ttnpb.ApplicationWebhookRegistryServer

NewWebhookRegistryRPC returns a new webhook registry gRPC server.

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 struct {
	// contains filtered or unexported fields
}

TemplateStore contains the webhook templates.

func (*TemplateStore) GetTemplate

func (ts *TemplateStore) GetTemplate(ctx context.Context, req *ttnpb.GetApplicationWebhookTemplateRequest) (*ttnpb.ApplicationWebhookTemplate, error)

GetTemplate returns the template with the given identifiers.

func (*TemplateStore) ListTemplates

func (ts *TemplateStore) ListTemplates(ctx context.Context, req *ttnpb.ListApplicationWebhookTemplatesRequest) (*ttnpb.ApplicationWebhookTemplates, error)

ListTemplates returns the available 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"`
}

TemplatesConfig defines the configuration for the webhook templates registry.

func (TemplatesConfig) NewTemplateStore

func (c TemplatesConfig) NewTemplateStore() (*TemplateStore, error)

NewTemplateStore returns a new *web.TemplateStore based on the configuration. If no stores are provided, this method returns nil.

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
	// NewSubscription returns a new webhooks integration subscription.
	NewSubscription() *io.Subscription
}

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

NewWebhooks returns a new Webhooks.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier