middleware

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// V2TokenHeader defines the HTTP header used by the IMDS service for extracting a
	// a session token from an HTTP request
	V2TokenHeader = "X-aws-ec2-metadata-token"
)

Variables

This section is empty.

Functions

func Cache added in v0.3.0

func Cache(memcache *cache.MemCache) gin.HandlerFunc

Cache provides middleware caching any request to the IMDS mock using an in memory map. The IMDS response is cached using a lookup query based on the IMDS instance category path

func CompactJSON

func CompactJSON() gin.HandlerFunc

CompactJSON provides middleware capable of rewriting all JSON responses into a compact format

func PrettyJSON

func PrettyJSON() gin.HandlerFunc

PrettyJSON provides middleware capable of rewriting all JSON responses into a pretty format

func StrictV2

func StrictV2() gin.HandlerFunc

StrictV2 provides middleware that explicitly enables IMDSv2 authorisation through the use of session tokens. Any requests without a valid session token are immediately rejected. A session token is presented to this middleware through the use of an HTTP header:

X-aws-ec2-metadata-token: TOKEN

func V1OptionalV2

func V1OptionalV2() gin.HandlerFunc

V1OptionalV2 provides middleware that enables both IMDSv1 and IMDSv2 support. While using V1 all requests will pass straight through without any authorisation checks. V2 checking will only be carried out on the presence of the HTTP header:

X-aws-ec2-metadata-token: TOKEN

func ZapLogger added in v0.3.0

func ZapLogger(logger *zap.Logger) gin.HandlerFunc

ZapLogger provides middleware for logging all requests using Zap based structured logs

func ZapRecovery added in v0.3.0

func ZapRecovery(logger *zap.Logger) gin.HandlerFunc

ZapRecovery provides middleware that recovers from any panics raised within requests and logs them using Zap based structured logs

Types

type JSONFormatter

type JSONFormatter interface {
	Format(in []byte) []byte
}

JSONFormatter defines an interface for formatting JSON text

Jump to

Keyboard shortcuts

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