security

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddRole added in v0.2.0

type AddRole func(role Role) error

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

func MakeIsGranted(rolesTree RolesTree, playerDiscordRoles []string) IsGranted

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

type Properties struct {
	RolesTreeFile  string
	RolesHierarchy RolesTree
}

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 RemoveRole func(role Role) error

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) Deny

func (r *Role) Deny(permission Permission)

Deny a permission from the role

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) Grant

func (r *Role) Grant(permission Permission)

Grant a permission to the role

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) Join added in v0.2.0

func (r *Role) Join(addRole AddRole) error

Join a role if the role is of type clan or group

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

func StringToRoleType(s string) RoleType

StringToRoleType Convert a string to a RoleType

func (*RoleType) UnmarshalYAML added in v0.2.0

func (rt *RoleType) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML for custom Permission type

type RolesTree

type RolesTree struct {
	Roles  map[string]*Role
	Buffer []Role
}

RolesTree handles the hierarchy of roles and permissions using RBAC structures.

func MakeEmptyRolesTree

func MakeEmptyRolesTree() RolesTree

MakeEmptyRolesTree returns an empty RolesTree structure.

func MakeRolesTreeFromFile

func MakeRolesTreeFromFile(path string) (RolesTree, error)

MakeRolesTreeFromFile returns a RolesTree generated from a file. See Kadok's wiki for more information regarding the file format

func (*RolesTree) GetClans added in v0.2.0

func (rolesTree *RolesTree) GetClans() []Role

func (*RolesTree) GetGroups added in v0.2.0

func (rolesTree *RolesTree) GetGroups() []Role

func (*RolesTree) GetRolesByType added in v0.2.0

func (rolesTree *RolesTree) GetRolesByType(t RoleType) []Role

func (*RolesTree) JoinClan added in v0.2.0

func (rolesTree *RolesTree) JoinClan(addClan AddRole, removeClan RemoveRole, clanReference string) (Role, error)

func (*RolesTree) JoinGroup added in v0.2.0

func (rolesTree *RolesTree) JoinGroup(addGroup AddRole, groupReference string) (Role, error)

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

func (rolesTree *RolesTree) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalJSON implementation for type RolesTree.

Jump to

Keyboard shortcuts

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