asgard

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package club provides middleware for use in HTTP API servers and gateways.

Index

Constants

View Source
const (
	DefaultRequestContextHeader = "x-amzn-request-context"
)

Variables

This section is empty.

Functions

func Heimdall

func Heimdall(headerName string) func(http.Handler) http.Handler

Heimdall returns HTTP handler middleware function that parses headerName as JSON into the RequestContext struct. If the header is missing or malformed, the middleware responds with a 401 Unauthorized error.

func Identify

func Identify(headerName string) func(http.Handler) http.Handler

Identify returns a HTTP Handler middleware function that identifies clients by their TLS client certificates. It parses the client certficiate into a RequestContext which is JSON-serialised into the headerName header.

Types

type RequestContext

type RequestContext struct {
	Namespace         uuid.UUID
	ClientCertificate *x509.Certificate
	ClientPublicKey   *ecdsa.PublicKey
	SourceIP          string `json:"sourceIp"`
	UserAgent         string `json:"userAgent"`
}

func FromContext

func FromContext(ctx context.Context) (r *RequestContext, ok bool)

FromContext returns a *RequestContext from http.Request.Context. If it doesn't exist (i.e. Heimdall hasn't run yet), the second return parameter is false.

func MustFromContext

func MustFromContext(ctx context.Context) *RequestContext

MustFromContext is identical to FromContext, except that it panics if the context doesn't have a RequestContext object. Heimdall must have run before this function is called.

func (RequestContext) MarshalJSON

func (r RequestContext) MarshalJSON() ([]byte, error)

func (*RequestContext) UnmarshalJSON

func (r *RequestContext) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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