rbac

package
v0.0.0-...-1fbbad1 Latest Latest
Warning

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

Go to latest
Published: May 9, 2016 License: GPL-2.0 Imports: 1 Imported by: 0

Documentation

Overview

https://github.com/mikespook/gorbac

https://github.com/mikespook/gorbac

Index

Constants

View Source
const (
	ParentKey     = "parents"
	PermissionKey = "permissions"
	NameKey       = "name"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AssertionFunc

type AssertionFunc func(string, string, *Rbac) bool

Assertion function supplies more fine-grained permission controls.

type BaseRole

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

func (*BaseRole) AddParent

func (role *BaseRole) AddParent(name string)

func (*BaseRole) AddPermission

func (role *BaseRole) AddPermission(permission string)

func (*BaseRole) HasPermission

func (role *BaseRole) HasPermission(permission string) bool

func (*BaseRole) Name

func (role *BaseRole) Name() string

func (*BaseRole) Parents

func (role *BaseRole) Parents() []string

func (*BaseRole) Permissions

func (role *BaseRole) Permissions() []string

func (*BaseRole) RemoveParent

func (role *BaseRole) RemoveParent(name string)

func (*BaseRole) Reset

func (role *BaseRole) Reset()

func (*BaseRole) RevokePermission

func (role *BaseRole) RevokePermission(permission string)

type Map

type Map map[string]RoleMap

Export RBAC to a structure data

type Rbac

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

RBAC

func New

func New() *Rbac

Return a RBAC structure.

func Restore

func Restore(data Map) *Rbac

Restore rbac from a map

func (*Rbac) Add

func (rbac *Rbac) Add(name string, permissions []string, parents []string)

Add a role with `name`. It has `permissions` and `parents`. If the role is not existing, a new one will be created. This function will add new permissions and parents to the role, and keep orignals.

func (*Rbac) Dump

func (rbac *Rbac) Dump() Map

Dump RBAC

func (*Rbac) Get

func (rbac *Rbac) Get(name string) Role

Return a role or nil if not exists.

func (*Rbac) IsGranted

func (rbac *Rbac) IsGranted(name, permission string, assert AssertionFunc) bool

Test if the `name` has `permission` in the `assert` condition.

func (*Rbac) Remove

func (rbac *Rbac) Remove(name string)

Remove a role.

func (*Rbac) Set

func (rbac *Rbac) Set(name string, permissions []string, parents []string)

Set a role with `name`. It has `permissions` and `parents`. If the role is not existing, a new one will be created. This function will cover role's orignal permissions and parents.

type Role

type Role interface {
	Name() string
	AddPermission(string)
	HasPermission(string) bool
	RevokePermission(string)
	Permissions() []string
	AddParent(string)
	RemoveParent(string)
	Parents() []string
	Reset()
}

func NewBaseRole

func NewBaseRole(rbac *Rbac, name string) Role

type RoleFactoryFunc

type RoleFactoryFunc func(*Rbac, string) Role

Sometimes, a custom role structure is needed by projects. You should define your own role factory function for this purpuse.

type RoleMap

type RoleMap map[string][]string

func RoleToMap

func RoleToMap(role Role) RoleMap

Jump to

Keyboard shortcuts

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