rbac

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: Unlicense Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PolicyAll = _CheckPolicy(iota)
	PolicyAny
)

Variables

View Source
var (
	PermApiLogin = perm("rbac.api.login")
	PermApiWrite = perm("rbac.api.write")
	PermApiRead  = perm("rbac.api.read")
)
View Source
var ErrPermissionDenied = errors.New("rbac: permission denied")

Functions

func Register

func Register(mux Router, backend Backend, opt *Options)

Types

type Backend added in v0.0.2

type Backend interface {
	GetAllPermissions(ctx context.Context) []Permission
	GetAllRoles(ctx context.Context) []Role
	GetSubjectRoleIDs(ctx context.Context, subject Subject) []uint32

	NewPermission(ctx context.Context, name string) error
	DelPermission(ctx context.Context, name string) error

	NewRole(ctx context.Context, name string) error
	DelRole(ctx context.Context, name string) error
	RoleAddPermission(ctx context.Context, role, perm string) error
	RoleDelPermission(ctx context.Context, role, perms string) error
	RoleAddSuper(ctx context.Context, role, super string) error
	RoleDelSuper(ctx context.Context, role, super string) error
	RoleAddWildcard(ctx context.Context, role, wildcard string) error
	RoleDelWildcard(ctx context.Context, role, wildcard string) error
	RoleAddConflict(ctx context.Context, role, conflict string) error
	RoleDelConflict(ctx context.Context, role, conflict string) error

	SubjectAddRole(ctx context.Context, sid int64, role string) error
	SubjectDelRole(ctx context.Context, sid int64, role string) error
}

type Handler

type Handler func(w http.ResponseWriter, req Request)

type Op

type Op struct {
	Type       string `json:"type"`
	Column     string `json:"column"`
	ID         int64  `json:"id"`
	Name       string `json:"name"`
	SecondName string `json:"second_name"`
}

type Options

type Options struct {
	PathPrefix   string
	ErrorHandler func(w http.ResponseWriter, r Request, v interface{})
}

type Permission added in v0.0.2

type Permission interface {
	// contains filtered or unexported methods
}

type RBAC

type RBAC struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func New

func New(backend Backend, maxAge int64) *RBAC

func (*RBAC) Errors

func (rbac *RBAC) Errors() []error

func (*RBAC) IsGranted

func (rbac *RBAC) IsGranted(ctx context.Context, subject Subject, policy _CheckPolicy, perms ...string) error

func (*RBAC) IsGrantedAll

func (rbac *RBAC) IsGrantedAll(ctx context.Context, subject Subject, perms ...string) error

func (*RBAC) IsGrantedAny

func (rbac *RBAC) IsGrantedAny(ctx context.Context, subject Subject, perms ...string) error

func (*RBAC) Load

func (rbac *RBAC) Load(ctx context.Context)

func (*RBAC) MustGrantedAll

func (rbac *RBAC) MustGrantedAll(ctx context.Context, subject Subject, perms ...string)

func (*RBAC) MustGrantedAny

func (rbac *RBAC) MustGrantedAny(ctx context.Context, subject Subject, perms ...string)

func (*RBAC) RoleConflict

func (rbac *RBAC) RoleConflict(ctx context.Context, roleIDs []uint32) []error

func (*RBAC) RolePermissions

func (rbac *RBAC) RolePermissions(ctx context.Context, role string) []Permission

func (*RBAC) Warnings

func (rbac *RBAC) Warnings() []string

type Request

type Request interface {
	GetContext() context.Context
	GetMethod() string
	GetBody() io.Reader
	Subject() Subject
}

type Role added in v0.0.2

type Role interface {
	SuperRoleIDs() []uint32
	PermissionIDs() []uint32
	PermissionWildcards() []string
	ConflictWith() []uint32
	// contains filtered or unexported methods
}

type Router

type Router interface {
	HandleFunc(p string, fn Handler)
}

type Subject added in v0.0.2

type Subject interface {
	ID() int64
}

Jump to

Keyboard shortcuts

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