access

package
v0.0.0-...-a9ad9ac Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package access evaluates resource and action permissions for application roles.

Index

Constants

This section is empty.

Variables

View Source
var ErrDenied = errors.New("permission denied")

ErrDenied identifies authorization failures, including empty requests.

Functions

This section is empty.

Types

type Control

type Control struct {
	// contains filtered or unexported fields
}

Control holds an application’s resource and action vocabulary.

func New

func New(vocabulary Statements) Control

New defines which resources and actions can be assigned to roles.

func (Control) HasAction

func (c Control) HasAction(resource, action string) bool

HasAction reports whether the vocabulary declares the resource-action pair.

func (Control) HasResource

func (c Control) HasResource(name string) bool

HasResource reports whether the vocabulary includes the named resource.

func (Control) NewRole

func (c Control) NewRole(grants Statements) (Role, error)

NewRole rejects grants outside the vocabulary. An empty grant list gives the role no actions on that resource.

type Match

type Match uint8

Match controls how a group of checks is combined. The zero value requires all.

const (
	All Match = iota
	Any
)

type Requirement

type Requirement struct {
	Resource string
	Actions  []string
	Match    Match
}

Requirement checks the named actions on a single resource.

type Role

type Role struct {
	// contains filtered or unexported fields
}

Role holds an immutable selection of grants. A role is safe for concurrent use.

func (Role) Authorize

func (r Role) Authorize(match Match, requirements ...Requirement) error

Authorize checks the requirements in order. Each requirement has its own match mode. An empty request or a requirement with no actions never grants access.

func (Role) Statements

func (r Role) Statements() Statements

Statements returns a copy of the role's grants. Change the copy and pass it to NewRole to derive another role; the original role is unaffected.

type Statements

type Statements map[string][]string

Statements lists the actions associated with each resource.

func (Statements) AllowsAll

func (s Statements) AllowsAll(request Statements) bool

AllowsAll checks a request in the resource-to-actions map form. It requires every requested resource to have at least one action, and every action to match.

Jump to

Keyboard shortcuts

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