role

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxPermissionCount 一个角色最多可以容纳的权限条数
	MaxPermissionCount = 500
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateRoleRequest

type CreateRoleRequest struct {
	*token.Session `bson:"-" json:"-"`
	Name           string        `bson:"name" json:"name,omitempty" validate:"required,lte=30"`       // 应用名称
	Description    string        `bson:"description" json:"description,omitempty" validate:"lte=400"` // 应用简单的描述
	Permissions    []*Permission `bson:"permissions" json:"permissions,omitempty"`                    // 读权限
}

CreateRoleRequest 创建应用请求

func NewCreateRoleRequest

func NewCreateRoleRequest() *CreateRoleRequest

NewCreateRoleRequest 实例化请求

func (*CreateRoleRequest) Validate

func (req *CreateRoleRequest) Validate() error

Validate 请求校验

type DescribeRoleRequest

type DescribeRoleRequest struct {
	Name string `json:"name,omitempty" validate:"required,lte=64"`
}

DescribeRoleRequest role详情

type EffectType

type EffectType uint

EffectType 授权效力包括两种:允许(Allow)和拒绝(Deny)

const (
	// Allow 允许访问
	Allow EffectType = iota + 1
	// Deny 拒绝访问
	Deny
)

func (EffectType) MarshalJSON

func (t EffectType) MarshalJSON() ([]byte, error)

MarshalJSON todo

func (EffectType) String

func (t EffectType) String() string

func (*EffectType) UnmarshalJSON

func (t *EffectType) UnmarshalJSON(b []byte) error

UnmarshalJSON todo

type Permission

type Permission struct {
	Effect       EffectType `bson:"effect" json:"effect,omitempty"`               // 效力
	ResourceName string     `bson:"resource_name" json:"resource_name,omitempty"` // 资源列表
	LabelKey     string     `bson:"label_key" json:"label_key,omitempty"`         // 维度
	LabelValues  []string   `bson:"label_values" json:"label_values,omitempty"`   // 标识值
}

Permission 权限

func NewDefaultPermission

func NewDefaultPermission() *Permission

NewDefaultPermission todo

func (*Permission) ID

func (p *Permission) ID(namespace string) string

ID 计算唯一ID

type PermissionSet

type PermissionSet struct {
	*request.PageRequest

	Total int64         `json:"total"`
	Items []*Permission `json:"items"`
}

PermissionSet 用户列表

func (*PermissionSet) Add

func (s *PermissionSet) Add(item *Permission)

Add todo

type QueryRoleRequest

type QueryRoleRequest struct {
	*request.PageRequest
	*DescribeRoleRequest
	Type Type
}

QueryRoleRequest 查询请求

func NewQueryRoleRequest

func NewQueryRoleRequest(pageReq *request.PageRequest) *QueryRoleRequest

NewQueryRoleRequest 列表查询请求

type Role

type Role struct {
	ID                 string     `bson:"_id" json:"id"`                        // 角色ID
	Type               Type       `bson:"type" json:"type"`                     // 角色类型
	CreateAt           ftime.Time `bson:"create_at" json:"create_at,omitempty"` // 创建时间`
	UpdateAt           ftime.Time `bson:"update_at" json:"update_at,omitempty"` // 更新时间
	CreaterID          string     `bson:"creater_id" json:"creater_id"`         // 创建人
	*CreateRoleRequest `bson:",inline"`
}

Role is rbac's role

func New

func New(t Type, req *CreateRoleRequest) (*Role, error)

New 新创建一个Role

func NewDefaultRole

func NewDefaultRole() *Role

NewDefaultRole 默认实例

func (*Role) CheckPermission

func (r *Role) CheckPermission() error

CheckPermission 检测该角色是否具有该权限

type Service

type Service interface {
	CreateRole(t Type, req *CreateRoleRequest) (*Role, error)
	QueryRole(req *QueryRoleRequest) (*Set, error)
	DescribeRole(req *DescribeRoleRequest) (*Role, error)
	DeleteRole(name string) error
}

Service 角色服务

type Set

type Set struct {
	*request.PageRequest

	Total int64   `json:"total"`
	Items []*Role `json:"items"`
}

Set 角色集合

func NewRoleSet

func NewRoleSet(req *request.PageRequest) *Set

NewRoleSet 实例化

func (*Set) Add

func (s *Set) Add(item *Role)

Add todo

type Type

type Type uint

Type 角色类型

const (
	// BuildInType 内建角色, 系统初始时创建
	BuildInType Type = iota + 1
	// GlobalType 管理员创建的一些角色, 全局可用
	GlobalType
	// CustomType 用户自定义的角色
	CustomType
)

func (Type) MarshalJSON

func (t Type) MarshalJSON() ([]byte, error)

MarshalJSON todo

func (Type) String

func (t Type) String() string

func (*Type) UnmarshalJSON

func (t *Type) UnmarshalJSON(b []byte) error

UnmarshalJSON todo

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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