role

package
v0.0.0-...-5aca00c Latest Latest
Warning

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

Go to latest
Published: May 18, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const SuperuserName = "root"

Variables

View Source
var Allow = PolicyFunc(func(r *Roles) (bool, error) {
	return true, nil
})
View Source
var Deny = PolicyFunc(func(r *Roles) (bool, error) {
	return false, nil
})
View Source
var Superuser = New(SuperuserName)

Functions

func Authorize

func Authorize(r *Roles, p ...Policy) (bool, error)

Types

type Attribute

type Attribute struct {
	Keyword string
	Value   []byte
}

func NewAttribute

func NewAttribute() *Attribute

type Attributes

type Attributes []*Attribute

func NewAttributes

func NewAttributes(a ...*Attribute) *Attributes

func (*Attributes) Add

func (a *Attributes) Add(keyword string, value []byte)

func (*Attributes) AddValues

func (a *Attributes) AddValues(keyword string, values ...[]byte)

func (*Attributes) Append

func (a *Attributes) Append(attrs ...*Attribute)

func (*Attributes) Clone

func (a *Attributes) Clone() *Attributes

func (*Attributes) Contains

func (a *Attributes) Contains(target *Attributes) bool

func (*Attributes) Data

func (a *Attributes) Data() []*Attribute

func (*Attributes) Get

func (a *Attributes) Get(keyword string) []byte

func (*Attributes) GetAll

func (a *Attributes) GetAll(keyword string) *Attributes

type Policy

type Policy interface {
	Authorize(*Roles) (bool, error)
}

func All

func All(policies ...Policy) Policy

func Any

func Any(policies ...Policy) Policy

func Not

func Not(p Policy) Policy

type PolicyFunc

type PolicyFunc func(*Roles) (bool, error)

func (PolicyFunc) Authorize

func (f PolicyFunc) Authorize(r *Roles) (bool, error)

type Role

type Role struct {
	Name       string
	Attributes *Attributes
}

func NewRole

func NewRole(name string) *Role

NewRole create new role by given name.

func (*Role) Contains

func (r *Role) Contains(target *Role) bool

func (*Role) WithNewAttribute

func (r *Role) WithNewAttribute(name string, value []byte) *Role

func (*Role) WithNewAttributeValues

func (r *Role) WithNewAttributeValues(name string, values ...[]byte) *Role

type Roles

type Roles []*Role

func New

func New(name ...string) *Roles

func NewRoles

func NewRoles(r ...*Role) *Roles

func (*Roles) Append

func (r *Roles) Append(roles ...*Role)

func (*Roles) Authorize

func (r *Roles) Authorize(toauth *Roles) (bool, error)

func (*Roles) Clone

func (r *Roles) Clone() *Roles

func (*Roles) Contains

func (r *Roles) Contains(target *Roles) bool

func (*Roles) Data

func (r *Roles) Data() []*Role

func (*Roles) FindAll

func (r *Roles) FindAll(name string) *Roles

func (*Roles) LoadRoles

func (r *Roles) LoadRoles() (*Roles, error)

type RolesLoader

type RolesLoader interface {
	LoadRoles() (*Roles, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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