handlers

package
v3.0.0-dev.48 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: Apache-2.0 Imports: 33 Imported by: 3

Documentation

Index

Constants

View Source
const (
	Origin                        = "Origin"
	Vary                          = "Vary"
	AccessControlRequestMethod    = "Access-Control-Request-Method"
	AccessControlExposeHeaders    = "Access-Control-Expose-Headers"
	AccessControlAllowCredentials = "Access-Control-Allow-Credentials"
	AccessControlAllowOrigin      = "Access-Control-Allow-Origin"
	AccessControlAllowMethods     = "Access-Control-Allow-Methods"
	AccessControlAllowHeaders     = "Access-Control-Allow-Headers"
	AccessControlMaxAge           = "Access-Control-Max-Age"
)

Variables

This section is empty.

Functions

func AutoConfigAuthenticationFunc

func AutoConfigAuthenticationFunc(secretProvider interfaces.SecretProvider, lc logger.LoggingClient) func(inner http.HandlerFunc) http.HandlerFunc

AutoConfigAuthenticationFunc auto-selects between a HandlerFunc wrapper that does authentication and a HandlerFunc wrapper that does not. By default, JWT validation is enabled in secure mode (i.e. when using a real secrets provider instead of a no-op stub)

Set EDGEX_DISABLE_JWT_VALIDATION to 1, t, T, TRUE, true, or True to disable JWT validation. This might be wanted for an EdgeX adopter that wanted to only validate JWT's at the proxy layer, or as an escape hatch for a caller that cannot authenticate.

func HandlePreflight

func HandlePreflight(corsInfo config.CORSConfigurationInfo) func(w http.ResponseWriter, r *http.Request)

HandlePreflight returns a http handler function that process CORS preflight responses and sets CORS headers.

func MessagingBootstrapHandler

func MessagingBootstrapHandler(ctx context.Context, wg *sync.WaitGroup, startupTimer startup.Timer, dic *di.Container) bool

MessagingBootstrapHandler fulfills the BootstrapHandler contract. If creates and initializes the Messaging client and adds it to the DIC

func NilAuthenticationHandlerFunc

func NilAuthenticationHandlerFunc() func(inner http.HandlerFunc) http.HandlerFunc

NilAuthenticationHandlerFunc just invokes a nested handler

func ProcessCORS

func ProcessCORS(corsInfo config.CORSConfigurationInfo) func(http.Handler) http.Handler

ProcessCORS is a middleware function that enables CORS responses and sets CORS headers.

func RequestLimitMiddleware

func RequestLimitMiddleware(sizeLimit int64, lc logger.LoggingClient) func(http.Handler) http.Handler

RequestLimitMiddleware is a middleware function that limits the request body size to Service.MaxRequestSize in kilobytes

func VaultAuthenticationHandlerFunc

func VaultAuthenticationHandlerFunc(secretProvider interfaces.SecretProvider, lc logger.LoggingClient) func(inner http.HandlerFunc) http.HandlerFunc

VaultAuthenticationHandlerFunc prefixes an existing HandlerFunc with a Vault-based JWT authentication check. Usage:

 authenticationHook := handlers.NilAuthenticationHandlerFunc()
 if secret.IsSecurityEnabled() {
		lc := container.LoggingClientFrom(dic.Get)
     secretProvider := container.SecretProviderFrom(dic.Get)
     authenticationHook = handlers.VaultAuthenticationHandlerFunc(secretProvider, lc)
 }
 For optionally-authenticated requests
 r.HandleFunc("path", authenticationHook(handlerFunc)).Methods(http.MethodGet)

 For unauthenticated requests
 r.HandleFunc("path", handlerFunc).Methods(http.MethodGet)

For typical usage, it is preferred to use AutoConfigAuthenticationFunc which will automatically select between a real and a fake JWT validation handler.

Types

type ClientsBootstrap

type ClientsBootstrap struct {
	// contains filtered or unexported fields
}

ClientsBootstrap contains data to boostrap the configured clients

func NewClientsBootstrap

func NewClientsBootstrap() *ClientsBootstrap

NewClientsBootstrap is a factory method that returns the initialized "ClientsBootstrap" receiver struct.

func (*ClientsBootstrap) BootstrapHandler

func (cb *ClientsBootstrap) BootstrapHandler(
	_ context.Context,
	_ *sync.WaitGroup,
	startupTimer startup.Timer,
	dic *di.Container) bool

BootstrapHandler fulfills the BootstrapHandler contract. It creates instances of each of the EdgeX clients that are in the service's configuration and place them in the DIC. If the registry is enabled it will be used to get the URL for client otherwise it will use configuration for the url. This handler will fail if an unknown client is specified.

type ExternalMQTT

type ExternalMQTT struct {
	// contains filtered or unexported fields
}

func NewExternalMQTT

func NewExternalMQTT(onConnectHandler mqtt.OnConnectHandler) *ExternalMQTT

func (*ExternalMQTT) BootstrapHandler

func (e *ExternalMQTT) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup, startupTimer startup.Timer, dic *di.Container) bool

type HttpServer

type HttpServer struct {
	// contains filtered or unexported fields
}

HttpServer contains references to dependencies required by the http server implementation.

func NewHttpServer

func NewHttpServer(router *mux.Router, doListenAndServe bool) *HttpServer

NewHttpServer is a factory method that returns an initialized HttpServer receiver struct.

func (*HttpServer) BootstrapHandler

func (b *HttpServer) BootstrapHandler(
	ctx context.Context,
	wg *sync.WaitGroup,
	_ startup.Timer,
	dic *di.Container) bool

BootstrapHandler fulfills the BootstrapHandler contract. It creates two go routines -- one that executes ListenAndServe() and another that waits on closure of a context's done channel before calling Shutdown() to cleanly shut down the http server.

func (*HttpServer) IsRunning

func (b *HttpServer) IsRunning() bool

IsRunning returns whether or not the http server is running. It is provided to support delayed shutdown of any resources required to successfully process http requests until after all outstanding requests have been processed (e.g. a database connection).

type Ready

type Ready struct {
	// contains filtered or unexported fields
}

Ready contains references to dependencies required by the testing implementation.

func NewReady

func NewReady(httpServer httpServer, stream chan<- bool) *Ready

NewReady is a factory method that returns an initialized Ready receiver struct.

func (*Ready) BootstrapHandler

func (r *Ready) BootstrapHandler(
	_ context.Context,
	_ *sync.WaitGroup,
	startupTimer startup.Timer,
	_ *di.Container) bool

BootstrapHandler fulfills the BootstrapHandler contract. During normal production execution, a nil stream will be supplied. A non-nil stream indicates we're running within the test runner context and that we should wait for the httpServer to start running before sending confirmation over the stream. If the httpServer doesn't start running within the defined startup time, no confirmation is sent over the stream and the application bootstrapping is aborted.

type ServiceMetrics

type ServiceMetrics struct {
	// contains filtered or unexported fields
}

func NewServiceMetrics

func NewServiceMetrics(serviceName string) *ServiceMetrics

func (*ServiceMetrics) BootstrapHandler

func (s *ServiceMetrics) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup, _ startup.Timer, dic *di.Container) bool

BootstrapHandler fulfills the BootstrapHandler contract and performs initialization of service metrics.

type StartMessage

type StartMessage struct {
	// contains filtered or unexported fields
}

StartMessage contains references to dependencies required by the start message handler.

func NewStartMessage

func NewStartMessage(serviceKey, version string) *StartMessage

NewStartMessage is a factory method that returns an initialized StartMessage receiver struct.

func (StartMessage) BootstrapHandler

func (h StartMessage) BootstrapHandler(
	_ context.Context,
	_ *sync.WaitGroup,
	startupTimer startup.Timer,
	dic *di.Container) bool

BootstrapHandler fulfills the BootstrapHandler contract. It creates no go routines. It logs a "standard" set of messages when the service first starts up successfully.

Jump to

Keyboard shortcuts

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