middleware

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package middleware exposes middlewares and helpers functions related to context get/set of DatabaseConfig and Auth.

Index

Constants

View Source
const (
	RootRole = 100
)

Variables

This section is empty.

Functions

func Chain

func Chain(h http.Handler, middlewares ...Middleware) http.Handler

Chain creates a request pipeline from which the Middleware are chained together and h is the last Handler executed.

func Extract

func Extract(r *http.Request, withAuth bool) (model.DatabaseConfig, model.Auth, error)

Extract extracts the DatabaseConfig and Auth for the request

func ValidateAuthKey

func ValidateAuthKey(datastore database.Persister, volatile cache.Volatilizer, ctx context.Context, key string) (model.Auth, error)

ValidateAuthKey validates a session token

func ValidateRootToken

func ValidateRootToken(datastore database.Persister, base, token string) (model.User, error)

ValidateRootToken validates that a session token has root level permissions

Types

type BillingPortalGetter added in v1.4.0

type BillingPortalGetter func(customerID string) (string, error)

type ContextKey

type ContextKey int
const (
	ContextAuth ContextKey = iota
	ContextBase
)

Context keys that are needed for all requests pipeline.

type Middleware

type Middleware func(h http.Handler) http.Handler

Middleware is a standard http.Handler

func Cors

func Cors() Middleware

Cors enables calls via remote origin to handle external JavaScript calls mainly.

func RequireAuth

func RequireAuth(datastore database.Persister, volatile cache.Volatilizer) Middleware

RequireAuth validates that a session token is valid. If not valid a 401 HTTP error is returned.

The request must have an HTTP Header of: Authorization: Bearer "session-token".

func RequireRoot

func RequireRoot(datastore database.Persister, volatile cache.Volatilizer) Middleware

RequireRoot validates that the token provided is for a "root" user.

func WithDB

func WithDB(datastore database.Persister, volatile cache.Volatilizer, g BillingPortalGetter) Middleware

WithDB validates the presence of the "SB-PUBLIC-KEY" and fetches the proper DatabaseConfig for this Tenant so the rest of the pipeline can executes actions on the right database.

Jump to

Keyboard shortcuts

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