rbac

package
v0.0.0-...-6a037c9 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowAll

func AllowAll(action, target string) (bool, error)

Types

type MatchMode

type MatchMode uint
const (
	// MatchPriorityDeny 按优先匹配,只要有封禁就禁止通过
	MatchPriorityDeny MatchMode = iota
	// MatchSomeDeny 只要有封禁就禁止通过
	MatchSomeDeny
	// MatchPrioritySomeAllow 按优先级匹配,只要有权限就允许通过
	MatchPrioritySomeAllow
	// MatchSomeAllow 只要有权限就可以通过
	MatchSomeAllow
)

type Matcher

type Matcher func(target string) (bool, error)

type Permission

type Permission func(action string, target string) (ok, isDeny bool, err error)

type RBAC

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

func New

func New() *RBAC

func Parse

func Parse(rules ztype.Map) (r *RBAC, err error)

func ParseFile

func ParseFile(path string) (*RBAC, error)

func (*RBAC) AddRole

func (r *RBAC) AddRole(roleName string, role *Role) error

func (*RBAC) Can

func (r *RBAC) Can(roleName string, action, target string) (ok bool, err error)

func (*RBAC) ForEachRole

func (r *RBAC) ForEachRole(fn func(key string, value *Role) bool)

func (*RBAC) Merge

func (r *RBAC) Merge(rd *RBAC) error

func (*RBAC) MergerRole

func (r *RBAC) MergerRole(roleName string, role *Role) error

func (*RBAC) RemoveRole

func (r *RBAC) RemoveRole(roleName string) error

type Role

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

func NewRole

func NewRole(matchMode ...MatchMode) *Role

func (*Role) AddGlobPermission

func (r *Role) AddGlobPermission(priority int, action, target string, deny ...bool)

func (*Role) AddPermission

func (r *Role) AddPermission(priority int, p Permission) *Role

func (*Role) AddRegexPermission

func (r *Role) AddRegexPermission(priority int, action, target string, deny ...bool)

func (*Role) AddRole

func (r *Role) AddRole(role *Role) *Role

func (*Role) Can

func (r *Role) Can(action, target string) (ok bool, err error)

Jump to

Keyboard shortcuts

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