Documentation ¶
Overview ¶
The security package contains all the features related to security and permission management. The structure of the permissions is based on the RBAC model.
Index ¶
- type AddRole
- type ErrorRoleNotFound
- type IsGranted
- type Permission
- type PermissionRequester
- type Properties
- type RemoveRole
- type Role
- type RoleType
- type RolesTree
- func (rolesTree *RolesTree) GetClans() []Role
- func (rolesTree *RolesTree) GetGroups() []Role
- func (rolesTree *RolesTree) GetRolesByType(t RoleType) []Role
- func (rolesTree *RolesTree) JoinClan(addClan AddRole, removeClan RemoveRole, clanReference string) (Role, error)
- func (rolesTree *RolesTree) JoinGroup(addGroup AddRole, groupReference string) (Role, error)
- func (rolesTree *RolesTree) LeaveClan(removeClan RemoveRole, clanReference string) (Role, error)
- func (rolesTree *RolesTree) LeaveGroup(removeRole RemoveRole, groupReference string) (Role, error)
- func (rolesTree *RolesTree) UnmarshalYAML(unmarshal func(interface{}) error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorRoleNotFound ¶ added in v0.2.0
type ErrorRoleNotFound string
func (ErrorRoleNotFound) Error ¶ added in v0.2.0
func (error ErrorRoleNotFound) Error() string
type IsGranted ¶
type IsGranted func(entity PermissionRequester) bool
IsGranted must return true if the requested permission is granted.
func MakeIsGranted ¶
MakeIsGranted return a function IsGranted that uses a RolesTree structure for the roles hierarchy and playerDiscodRoles representing a user's roles to return if a permission is granted.
type Permission ¶
type Permission int
Permission is a int defined by its name. If present in a role, it is considered as granted
const ( //EmptyPermission - defines a a special permission that means no permission. Used by PermissionOwner that do not own a permission. EmptyPermission Permission = iota //CallCharacter - package: main - Quote from a character CallCharacter //GetCharacterList - package: main - Get list of available characters GetCharacterList //GetHelp - package: main - Get bot information GetHelp )
List of available permissions
func StringToPermission ¶
func StringToPermission(s string) Permission
StringToPermission Convert a string to a Permission type
func (Permission) GetPermission ¶
func (p Permission) GetPermission() Permission
Implementation of the interface PermissionOwner for the Permission type
func (Permission) String ¶
func (p Permission) String() string
Convert a permission the associated string
func (*Permission) UnmarshalYAML ¶ added in v0.2.0
func (p *Permission) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML for custom Permission type
type PermissionRequester ¶
type PermissionRequester interface { // GetPermission returns the permission required by the PermissionRequester GetPermission() Permission }
PermissionRequester interface is used by entities requiring a permission
type Properties ¶
Properties information for the Security package. Yaml structure to add to the properties' hierarchy :
roles: <roles_file_path> (file path to the roles hierarchy file, see Kadok's wiki for more)
func (*Properties) UnmarshalYAML ¶
func (properties *Properties) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implementation for the package Properties.
type RemoveRole ¶ added in v0.2.0
type Role ¶
type Role struct { Name string Parent *Role Permissions []Permission Type RoleType Description string }
Role is defined by a name and can inherit permissions from a parent. It also contains a list of permissions
func (Role) Find ¶
func (r Role) Find(permission Permission) int
Find the index of the permission in the role, returns -1 if not present
func (Role) IsGranted ¶
func (r Role) IsGranted(permission Permission) bool
IsGranted check if the permission is granted to the role or one of its parents
func (*Role) Leave ¶ added in v0.2.0
func (r *Role) Leave(removeRole RemoveRole) error
Leave a role if the role is of type clan or group
type RoleType ¶ added in v0.2.0
type RoleType int
RoleType defines the type of the role in the discord
const ( //RoleDefault - Role of type Default: no particular behavior RoleDefault RoleType = iota //RoleGroup - Role of type Group: a user can join multiple groups RoleGroup //RoleClan - Role of type Clan: a user can join only one clan RoleClan )
List of defined RoleType
func StringToRoleType ¶ added in v0.2.0
StringToRoleType Convert a string to a RoleType
func (*RoleType) UnmarshalYAML ¶ added in v0.2.0
UnmarshalYAML for custom Permission type
type RolesTree ¶
RolesTree handles the hierarchy of roles and permissions using RBAC structures.
func MakeEmptyRolesTree ¶
func MakeEmptyRolesTree() RolesTree
MakeEmptyRolesTree returns an empty RolesTree structure.
func MakeRolesTreeFromFile ¶
MakeRolesTreeFromFile returns a RolesTree generated from a file. See Kadok's wiki for more information regarding the file format
func (*RolesTree) GetRolesByType ¶ added in v0.2.0
func (*RolesTree) LeaveClan ¶ added in v0.2.0
func (rolesTree *RolesTree) LeaveClan(removeClan RemoveRole, clanReference string) (Role, error)
func (*RolesTree) LeaveGroup ¶ added in v0.2.0
func (rolesTree *RolesTree) LeaveGroup(removeRole RemoveRole, groupReference string) (Role, error)
func (*RolesTree) UnmarshalYAML ¶ added in v0.2.0
UnmarshalJSON implementation for type RolesTree.