auth

package
v0.0.0-...-9933dd3 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthNone   = "none"
	AuthAPIKey = "apikey"
	AuthBasic  = "basic"
)

Variables

View Source
var (
	ErrMethodNotSupported = errors.New("authentication method not supported")
	ErrAPIKeyEmpty        = errors.New("api key is empty")
	ErrBasicUsernameEmpty = errors.New("username is empty")
	ErrBasicPasswordEmpty = errors.New("password is empty")
	ErrRouteNotSupported  = errors.New("route not supported by the control server")
)

Functions

func New

func New(settings Settings, debugLogger DebugLogger) (
	middleware func(http.Handler) http.Handler,
	err error,
)

Types

type DebugLogger

type DebugLogger interface {
	Debugf(format string, args ...any)
	Warnf(format string, args ...any)
}

type Role

type Role struct {
	// Name is the role name and is only used for documentation
	// and in the authentication middleware debug logs.
	Name string
	// Auth is the authentication method to use, which can be 'none' or 'apikey'.
	Auth string
	// APIKey is the API key to use when using the 'apikey' authentication.
	APIKey string
	// Username for HTTP Basic authentication method.
	Username string
	// Password for HTTP Basic authentication method.
	Password string
	// Routes is a list of routes that the role can access in the format
	// "HTTP_METHOD PATH", for example "GET /v1/vpn/status"
	Routes []string
}

Role contains the role name, authentication method name and routes that the role can access.

type Settings

type Settings struct {
	// Roles is a list of roles with their associated authentication
	// and routes.
	Roles []Role
}

func Read

func Read(filepath string) (settings Settings, err error)

Read reads the toml file specified by the filepath given. If the file does not exist, it returns empty settings and no error.

func (*Settings) SetDefaults

func (s *Settings) SetDefaults()

func (Settings) Validate

func (s Settings) Validate() (err error)

Jump to

Keyboard shortcuts

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