asgard

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package asgard provides middleware for use in HTTP API servers and reverse-proxies. In Norse mythology, Heimdallr is the gatekeeper of Bifröst and Hofund is his sword.

Heimdallr returna a HTTP Handler middleware function that parses a header into a RequestContext. Hofund returns a HTTP Handler middleware function that writes a RequestContext into a header from a client's TLS certificate.

Index

Constants

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

Variables

This section is empty.

Functions

func Heimdallr added in v1.10.2

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

Heimdallr returns a 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 Hofund added in v1.10.2

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

Hofund 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 {
	ClientCertificate *bifrost.Certificate
	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