perm

package
v1.1.40 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindPrincipal

func BindPrincipal(ctx context.Context, principal Principal) (context.Context, error)

BindPrincipal 在ctx中绑定principal

func HasPermWithPrinciapl

func HasPermWithPrinciapl(ctx context.Context, principal Principal) bool

HasPermWithPrinciapl 检查principal是否拥有ctx中要求的权限

func HasPermWithPrincipalAndPerms

func HasPermWithPrincipalAndPerms(principal Principal, reqPerms []*Perm) bool

HasPermWithPrincipalAndPerms 检查principal是否拥有reqPerms指定的权限

func ReqPerm

func ReqPerm(ctx context.Context, perms []*Perm) (context.Context, error)

ReqPerm 在ctx中声明需要由perms指定的权限

Types

type Operation

type Operation int8

Operation 定义操作类型

const (
	OPRead Operation = 1 << iota
	OPInsert
	OPUpdate
	OPDelete
	OPAll = OPRead | OPInsert | OPUpdate | OPDelete
)

定义操作的类型

func ParseOperation

func ParseOperation(operation string) Operation

ParseOperation 从字符串中解析操作的权限

func (Operation) String

func (p Operation) String() string

String 将权限转为字符串表达

type Perm

type Perm struct {
	Res *Resource //资源
	Op  Operation //操作
}

Perm 定义了一个权限,一个权限由资源及其对应的操作组成

func GetRequiredPerm

func GetRequiredPerm(ctx context.Context) ([]*Perm, error)

GetRequiredPerm 在ctx中取得需要权限

func NewPerm

func NewPerm(res *Resource, op Operation) *Perm

NewPerm 构建Perm

type Principal

type Principal interface {
	// GetID 取得principal的id
	GetID() int64
	// GetName 取得principal的名称
	GetName() string
	// GetRoles 取得principal所拥有的角色
	GetRoles() []Role
}

Principal 定义了拥有权限的主体

func GetPrincipal

func GetPrincipal(ctx context.Context) (Principal, error)

GetPrincipal 在ctx中取得principal

type Resource

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

Resource 定义资源

func NewResource

func NewResource(name, id string, parent *Resource) *Resource

NewResource 创建一个新的资源

func NewResourceAndReg

func NewResourceAndReg(registry *ResourceRegistry, name, id string, parent *Resource) *Resource

NewResourceAndReg 创建并新建一个资源,如果相同的资源在registry中已经存在,则会panic

func (*Resource) GetID

func (p *Resource) GetID() string

GetID 资源的id

func (*Resource) GetName

func (p *Resource) GetName() string

GetName 资源的名称

func (*Resource) GetParent

func (p *Resource) GetParent() *Resource

GetParent 父级资源

type ResourceGroup

type ResourceGroup struct {
	Name      string      //组名称
	Resources []*Resource //资源
}

ResourceGroup 资源分组

type ResourceRegistry

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

ResourceRegistry 记录所有的资源

func NewResourceRegistry

func NewResourceRegistry() *ResourceRegistry

NewResourceRegistry 构建资源注册

func (*ResourceRegistry) Add

func (p *ResourceRegistry) Add(resource *Resource) error

Add 注册一个Resource,如果相同的资源在registry中已经存在,返回error

func (*ResourceRegistry) BuildResourceGroup

func (p *ResourceRegistry) BuildResourceGroup(depth int) (groups []*ResourceGroup, err error)

BuildResourceGroup 构建resource group列表

func (*ResourceRegistry) IsExist

func (p *ResourceRegistry) IsExist(resID string) bool

IsExist 检查指定的资源id是否存在

type Role

type Role interface {
	//GetName 角色的名称
	GetName() string
	//GetPerms 角色拥有的权限
	GetPerms() map[string]Operation
}

Role 定义角色

Jump to

Keyboard shortcuts

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