Documentation
¶
Overview ¶
Package permissions implements an echo middleware to simplify checking permission checks in downstream handlers by adding a checking function to the context which may later be called to check permissions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoAuthToken is the error returned when there is no auth token provided for the API request ErrNoAuthToken = errors.New("no auth token provided for client") // ErrInvalidAuthToken is the error returned when the auth token is not the expected value ErrInvalidAuthToken = errors.New("invalid auth token") // ErrPermissionDenied is the error returned when permission is denied to a call ErrPermissionDenied = errors.New("subject doesn't have access") // ErrBadResponse is the error returned when we receive a bad response from the server ErrBadResponse = errors.New("bad response from server") // ErrCheckerNotFound is the error returned when CheckAccess does not find the appropriate checker context ErrCheckerNotFound = errors.New("no checker found in context") )
Functions ¶
func CheckAccess ¶
CheckAccess runs the checker function to check if the provided resource and action are supported.
Types ¶
type Checker ¶
Checker defines the checker function definition
var ( // CheckerCtxKey is the context key used to set the checker handling function CheckerCtxKey = checkerCtxKey{} // DefaultAllowChecker defaults to allow when checker is disabled or skipped DefaultAllowChecker Checker = func(_ context.Context, _ gidx.PrefixedID, _ string) error { return nil } // DefaultDenyChecker defaults to denied when checker is disabled or skipped DefaultDenyChecker Checker = func(_ context.Context, _ gidx.PrefixedID, _ string) error { return ErrPermissionDenied } )
type Config ¶
type Config struct { // URL is the URL checks should be executed against URL string }
Config defines the permissions configuration structure
type Option ¶
type Option func(p *Permissions) error
Option defines an option configurator
func WithDefaultChecker ¶
WithDefaultChecker sets the default checker if the middleware is skipped
func WithHTTPClient ¶
WithHTTPClient sets the underlying http client the auth handler uses
func WithLogger ¶
func WithLogger(logger *zap.SugaredLogger) Option
WithLogger sets the logger for the auth handler
func WithSkipper ¶
func WithSkipper(skipper middleware.Skipper) Option
WithSkipper sets the echo middleware skipper function
type Permissions ¶
type Permissions struct {
// contains filtered or unexported fields
}
Permissions handles supporting authorization checks
func New ¶
func New(config Config, options ...Option) (*Permissions, error)
New creates a new Permissions instance
func (*Permissions) Middleware ¶
func (p *Permissions) Middleware() echo.MiddlewareFunc
Middleware produces echo middleware to handle authorization checks