rbac

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PermPO = &PermissionPersistence{
		perm: make(map[string]string),
	}
)

Functions

func AddInheritance

func AddInheritance(role string, inherit ...string) error

func AddPermission

func AddPermission(role string, permission ...string) error

func CheckPermission

func CheckPermission(role, perm string) error

func CreateRole

func CreateRole(aul *CreateRoleRequest) error

func DeleteInheritance

func DeleteInheritance(role string, inherit ...string) error

func DeletePermission

func DeletePermission(role string, permission ...string) error

func DeleteRole

func DeleteRole(name string) error

func GetDefaultRoleName

func GetDefaultRoleName() string

func GetGuestRoleName

func GetGuestRoleName() string

func GetPermissionName

func GetPermissionName(name string) string

GetPermissionName 获取权限名称

func GuestHasPermission

func GuestHasPermission(permission string) bool

func HasPermission

func HasPermission(role, permission string) bool

func LoadRole

func LoadRole(config *viper.Viper)

func PermInterceptor

func PermInterceptor(perm string) iris.Handler

func RegisterPerm

func RegisterPerm(name string, perm map[string]string)

func SetDefaultRole

func SetDefaultRole(name string) error

func SetGuestRole

func SetGuestRole(name string) error

func UpdateRole

func UpdateRole(name string, aul *UpdateRoleRequest) error

Types

type CreateRoleRequest

type CreateRoleRequest struct {
	Name        string   `json:"name"         validate:"required,gte=2,lte=50"`
	DisplayName string   `json:"display_name" validate:"required,lte=191"`
	Position    uint     `json:"position"`
	Permissions []string `json:"permissions"`
	Inheritance []string `json:"inheritance"`
}

type PermSet

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

func (*PermSet) Add

func (p *PermSet) Add(keys ...string) *PermSet

func (*PermSet) Delete

func (p *PermSet) Delete(keys ...string) *PermSet

func (*PermSet) Find

func (p *PermSet) Find(key string) (positive, found bool)

func (*PermSet) Has

func (p *PermSet) Has(key string) bool

type PermissionJson

type PermissionJson struct {
	Name        string `json:"name"`
	DisplayName string `json:"display_name"`
}

func GetAllPermissions

func GetAllPermissions() (perms []*PermissionJson)

func GetPermission

func GetPermission(name string) *PermissionJson

GetPermission 获取权限Json

type PermissionPersistence

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

type Role

type Role struct {
	*RoleInfo
	PermSet  *PermSet
	InheRole []*Role
	sync.RWMutex
}

func (*Role) String

func (r *Role) String() string

type RoleInfo

type RoleInfo struct {
	Name        string   `mapstructure:"name"         yaml:"name"`
	DisplayName string   `mapstructure:"display_name" yaml:"display_name"`
	Default     bool     `mapstructure:"default"      yaml:"default,omitempty"`
	Guest       bool     `mapstructure:"guest"        yaml:"guest,omitempty"`
	Permissions []string `mapstructure:"permissions"  yaml:"permissions"`
	Inheritance []string `mapstructure:"inheritance"  yaml:"inheritance"`
}

type RoleJson

type RoleJson struct {
	Name        string            `json:"name"`
	DisplayName string            `json:"display_name"`
	Default     bool              `json:"default"`
	Guest       bool              `json:"guest"`
	Permissions []*PermissionJson `json:"permissions,omitempty"`
	Inheritance []string          `json:"inheritance,omitempty"`
}

func GetAllRoles

func GetAllRoles() []*RoleJson

func GetDefaultRole

func GetDefaultRole() *RoleJson

func GetGuestRole

func GetGuestRole() *RoleJson

func GetRole

func GetRole(name string) *RoleJson

type RolePersistence

type RolePersistence struct {
	sync.RWMutex
	// contains filtered or unexported fields
}
var (
	RolePO *RolePersistence
)

func (*RolePersistence) AddInheritance

func (s *RolePersistence) AddInheritance(role string, inherit ...string) error

func (*RolePersistence) AddPermission

func (s *RolePersistence) AddPermission(role string, perms ...string) error

func (*RolePersistence) CreateRole

func (s *RolePersistence) CreateRole(aul *CreateRoleRequest) (err error)

func (*RolePersistence) DeleteInheritance

func (s *RolePersistence) DeleteInheritance(role string, inherit ...string) error

func (*RolePersistence) DeletePermission

func (s *RolePersistence) DeletePermission(role string, permission ...string) error

func (*RolePersistence) DeleteRole

func (s *RolePersistence) DeleteRole(name string) error

func (*RolePersistence) GetAllRoles

func (s *RolePersistence) GetAllRoles() (roles []*RoleJson)

func (*RolePersistence) GetDefaultRole

func (s *RolePersistence) GetDefaultRole() *RoleJson

func (*RolePersistence) GetGuestRole

func (s *RolePersistence) GetGuestRole() *RoleJson

func (*RolePersistence) GetGuestRoleName

func (s *RolePersistence) GetGuestRoleName() string

func (*RolePersistence) GetRole

func (s *RolePersistence) GetRole(name string) *RoleJson

func (*RolePersistence) GuestHasPermission

func (s *RolePersistence) GuestHasPermission(permission string) bool

func (*RolePersistence) HasPermission

func (s *RolePersistence) HasPermission(role, permission string) bool

func (*RolePersistence) SetDefaultRole

func (s *RolePersistence) SetDefaultRole(name string) error

func (*RolePersistence) SetGuestRole

func (s *RolePersistence) SetGuestRole(name string) (err error)

func (*RolePersistence) UpdateRole

func (s *RolePersistence) UpdateRole(name string, aul *UpdateRoleRequest) error

type UpdateRoleRequest

type UpdateRoleRequest struct {
	DisplayName    string   `json:"display_name" validate:"required,lte=191"`
	Position       uint     `json:"position"`
	AddPermissions []string `json:"add_permissions"`
	DelPermissions []string `json:"del_permissions"`
	AddInheritance []string `json:"add_inheritance"`
	DelInheritance []string `json:"del_inheritance"`
}

Jump to

Keyboard shortcuts

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