rbac

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRoleNotFound = errors.New("role not found")
	ErrInvalidRole  = errors.New("role must be a string or implement the Role interface")
)
View Source
var ErrCircularReference = errors.New("circular reference detected")

Functions

This section is empty.

Types

type AccessConfig

type AccessConfig struct {
	Role        string   `json:"role,omitempty" yaml:"role,omitempty"`
	Permissions []string `json:"permissions,omitempty" yaml:"permissions,omitempty"`
}

type Assertion

type Assertion interface {
	Assert(ctx context.Context, role Role, permission string) (bool, error)
}

type AssertionFunc

type AssertionFunc func(ctx context.Context, role Role, permission string) (bool, error)

func (AssertionFunc) Assert

func (f AssertionFunc) Assert(ctx context.Context, role Role, permission string) (bool, error)

type AuthorizationChecker

type AuthorizationChecker interface {
	IsGranted(ctx context.Context, role any, permission string, assertions ...Assertion) bool
}

type Config

type Config struct {
	CreateMissingRoles bool           `json:"createMissingRoles,omitempty" yaml:"createMissingRoles,omitempty"`
	RoleHierarchy      []RoleConfig   `json:"roleHierarchy,omitempty" yaml:"roleHierarchy,omitempty"`
	AccessControl      []AccessConfig `json:"accessControl,omitempty" yaml:"accessControl,omitempty"`
}

type DefaultRole

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

func NewRole

func NewRole(name string) *DefaultRole

func (*DefaultRole) AddChild

func (r *DefaultRole) AddChild(child Role) error

func (*DefaultRole) AddParent

func (r *DefaultRole) AddParent(parent Role) error

func (*DefaultRole) AddPermissions

func (r *DefaultRole) AddPermissions(permission string, rest ...string)

func (*DefaultRole) Children

func (r *DefaultRole) Children() []Role

func (*DefaultRole) HasAncestor

func (r *DefaultRole) HasAncestor(role Role) bool

func (*DefaultRole) HasDescendant

func (r *DefaultRole) HasDescendant(role Role) bool

func (*DefaultRole) HasPermission

func (r *DefaultRole) HasPermission(permission string) bool

func (*DefaultRole) Name

func (r *DefaultRole) Name() string

func (*DefaultRole) Parents

func (r *DefaultRole) Parents() []Role

func (*DefaultRole) Permissions

func (r *DefaultRole) Permissions(children bool) []string

func (*DefaultRole) String

func (r *DefaultRole) String() string

type RBAC

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

func New

func New() *RBAC

func NewWithConfig

func NewWithConfig(cfg Config) (*RBAC, error)

func (*RBAC) AddRole

func (rbac *RBAC) AddRole(role any, parents ...any) error

func (*RBAC) Apply

func (rbac *RBAC) Apply(cfg Config) error

func (*RBAC) CreateMissingRoles

func (rbac *RBAC) CreateMissingRoles() bool

func (*RBAC) HasRole

func (rbac *RBAC) HasRole(role any) (bool, error)

func (*RBAC) IsGranted

func (rbac *RBAC) IsGranted(ctx context.Context, role any, permission string, assertions ...Assertion) bool

func (*RBAC) IsGrantedE

func (rbac *RBAC) IsGrantedE(ctx context.Context, role any, permission string, assertions ...Assertion) (bool, error)

func (*RBAC) Role

func (rbac *RBAC) Role(name string) (Role, error)

func (*RBAC) Roles

func (rbac *RBAC) Roles() []Role

func (*RBAC) SetCreateMissingRoles

func (rbac *RBAC) SetCreateMissingRoles(createMissingRoles bool) *RBAC

type Role

type Role interface {
	fmt.Stringer
	Name() string
	AddPermissions(permission string, rest ...string)
	HasPermission(permission string) bool
	Permissions(children bool) []string
	AddParent(Role) error
	Parents() []Role
	AddChild(Role) error
	Children() []Role
	HasAncestor(role Role) bool
	HasDescendant(role Role) bool
}

type RoleConfig

type RoleConfig struct {
	Role     string   `json:"role,omitempty" yaml:"role,omitempty"`
	Parents  []string `json:"parents,omitempty" yaml:"parents,omitempty"`
	Children []string `json:"children,omitempty" yaml:"children,omitempty"`
}

Jump to

Keyboard shortcuts

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