middlewares

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RWords is a residual string used to mimic the actual HMAC
	RWords = "" /* 788-byte string literal not displayed */
)

Variables

View Source
var (
	// HMACAgeMinutes holds the validity (in minutes) of the hmac
	HMACAgeMinutes int
	// SecretKey holds the hmac secret
	SecretKey string
)

Functions

func CORSMiddleware

func CORSMiddleware(next http.Handler) http.Handler

CORSMiddleware will handle CORS handling

func ComputeHmac

func ComputeHmac(message string, secret string) string

ComputeHmac will calculate and create new HMAC-SHA256 string hash based on the payload and the secret string

func DevKey

func DevKey(w http.ResponseWriter, r *http.Request)

DevKey can be invoked from curl -X PUT -H "HocusPocus: AvadaCadavra" http://localhost:50051/devkey

func GenHMAC

func GenHMAC() string

GenHMAC will generate a new HMAC string using the current time in RFC3339 format as payload .

func HMACMiddleware

func HMACMiddleware(next http.Handler) http.Handler

HMACMiddleware will handle the HMAC verification for each request of all restricted endpoint.

func Logger

func Logger(next http.Handler) http.Handler

Logger middleware handles some logging with logrus

func MakeResidue

func MakeResidue(hmac string) string

MakeResidue create a dummy HMAC

func SetupContextMiddleware

func SetupContextMiddleware(next http.Handler) http.Handler

SetupContextMiddleware will check if the current request already contains a context or not If it do not contain a context, a new context from background will be used and inserted into the request. The context is then injected with XRequestID key taken from the request header (or a new request id if theres no such header). This will be useful to chain the logs based on the request.

func ValidateHMAC

func ValidateHMAC(hmac string) bool

ValidateHMAC will validate if a specific HMAC string is valid, it will open the time payload and make sure the payload is not expired and it equals to the hash

Types

This section is empty.

Jump to

Keyboard shortcuts

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