rbac

package
v0.0.0-...-f8334dc Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package rbac provides role-based access control.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateRole

func CreateRole(ctx context.Context, db *sql.DB, role *Role) error

func RoleByName

func RoleByName(guildID string, name string) qm.QueryMod

Types

type Enforcer

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

func (*Enforcer) GetTargets

func (e *Enforcer) GetTargets(guildID string, userID string) []Target

GetTargets generates all appropriate targets for a member or user.

func (*Enforcer) HasPermission

func (e *Enforcer) HasPermission(guildID string, userID string, permissions ...Permission) (bool, error)

HasPermission checks whether a member or user has all of the permissions.

func (*Enforcer) HasRateLimit

func (e *Enforcer) HasRateLimit(guildID string, userID string) (bool, error)

type Permission

type Permission uint
const (
	QueueModify Permission = iota
)

type Role

type Role = models.Role

func GetRole

func GetRole(ctx context.Context, db *sql.DB, id int64) (*Role, error)

func GetRoleByName

func GetRoleByName(ctx context.Context, db *sql.DB, guildID string, name string) (*Role, error)

type RoleTarget

type RoleTarget = models.RoleTarget

func GetRoleTargetsForTarget

func GetRoleTargetsForTarget(ctx context.Context, db *sql.DB, target string) ([]*RoleTarget, error)

type Target

type Target struct {
	GuildID string
	Type    TargetType
	ID      string
}

Target is an identifier to which a role can be assigned.

Syntax: `[<guild id>:][<type>]<id>`

As you can see both the guild id and the target type are optional.
A missing guild id indicates a global target and a missing type stands for
a user target type.

func ParseTarget

func ParseTarget(raw string) (target Target, err error)

ParseTarget parses a raw target into

func TargetMember

func TargetMember(guildID string, userID string) Target

TargetMember creates a new target for a guild member.

func TargetRole

func TargetRole(guildID string, roleID string) Target

TargetRole creates a new target for a role.

func TargetUser

func TargetUser(userID string) Target

TargetUser creates a new target for a user.

func (Target) GuildTarget

func (t Target) GuildTarget() string

GuildTarget returns the target without the guild specifier.

func (Target) IsGlobal

func (t Target) IsGlobal() bool

IsGlobal returns whether the target targets a global entity (i.e. is not bound to a guild).

func (Target) IsMember

func (t Target) IsMember() bool

func (Target) IsRole

func (t Target) IsRole() bool

func (Target) IsSpecial

func (t Target) IsSpecial() bool

func (Target) IsUser

func (t Target) IsUser() bool

func (Target) String

func (t Target) String() string

String converts the target to its string representation.

type TargetType

type TargetType rune

TargetType represents the type of entity a target targets.

const (
	UserTargetType    TargetType = 0   // Target user
	SpecialTargetType TargetType = '$' // Special target
	RoleTargetType    TargetType = '@' // Target role
)

func GetTargetType

func GetTargetType(r rune) (TargetType, bool)

GetTargetType determines the target type from its rune representation.

Jump to

Keyboard shortcuts

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