Documentation
¶
Index ¶
Constants ¶
const ModuleName string = "authorization"
Variables ¶
var ErrForbidden = fmt.Errorf("forbidden")
Functions ¶
func WithPolicy ¶
WithPolicy sets the role-to-permission policy for this service. It must be called during module configuration; the LocalAuthorizer is built from it.
Types ¶
type Authorizer ¶
type Authorizer interface {
// CanPerform checks whether the user holds any role that grants permission.
CanPerform(context.Context, User, Permission) error
// CanPerformOwned checks whether the user holds permission unconditionally,
// or — when ownership is required — whether user.GetID() == ownerID.
CanPerformOwned(context.Context, User, Permission, uuid.UUID) error
}
Authorizer checks whether a user is permitted to perform an action.
type LocalAuthorizer ¶
type LocalAuthorizer struct {
// contains filtered or unexported fields
}
LocalAuthorizer evaluates permissions against a static, in-process Policy. It is the standard implementation for services that define policy at startup.
func NewLocalAuthorizer ¶
func NewLocalAuthorizer(policy Policy) *LocalAuthorizer
func (*LocalAuthorizer) CanPerform ¶
func (l *LocalAuthorizer) CanPerform(_ context.Context, user User, permission Permission) error
func (*LocalAuthorizer) CanPerformOwned ¶
func (l *LocalAuthorizer) CanPerformOwned( _ context.Context, user User, permission Permission, ownerID uuid.UUID, ) error
type Module ¶
func (*Module) Authorizer ¶
func (m *Module) Authorizer() Authorizer
Authorizer returns the configured Authorizer for use in route registration and use cases. Call this after the module has been configured.
type OwnershipConstraint ¶
type OwnershipConstraint bool
OwnershipConstraint controls whether a permission requires the subject to own the resource being acted upon.
const ( OwnershipRequired OwnershipConstraint = true NoOwnershipRequired OwnershipConstraint = false )
type Permission ¶
type Permission string
Permission is a named action that can be granted to a role.
type Policy ¶
type Policy map[string]map[Permission]OwnershipConstraint
Policy maps role names to the set of permissions granted to that role, along with the ownership constraint for each permission. Each service defines its own policy as a package-level variable and passes it to WithPolicy.