resource

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: GPL-2.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ServiceAccessChecker  = "resource:access-checker"
	ServiceChangeNotifier = "resource:change-notifier"
	ServiceManager        = "resource:manager"
)
View Source
const (
	AccessReadMask   = 0x01 << AccessRead
	AccessWriteMask  = 0x01 << AccessWrite
	AccessCreateMask = 0x01 << AccessCreate
	AccessDeleteMask = 0x01 << AccessDelete
	AccessListMask   = 0x01 << AccessList
)

Variables

View Source
var (
	ErrForbidden       = errors.New("forbidden")
	ErrUnknownResource = errors.New("resource not found")
	ErrDuplicate       = errors.New("duplicate key")
)
View Source
var AccessMaskMapping = map[string]int{
	"r": AccessReadMask,
	"w": AccessWriteMask,
	"c": AccessCreateMask,
	"d": AccessDeleteMask,
	"l": AccessListMask,
}
View Source
var AccessNames = []string{
	"read",
	"write",
	"create",
	"delete",
	"list",
}
View Source
var AccessShortNames = []string{
	"r",
	"w",
	"c",
	"d",
	"l",
}

Functions

This section is empty.

Types

type AccessChecker

type AccessChecker interface {
	//CheckResourceAccess called when it is necessary to check access rights to Resource with given id;
	//  objectID may be nil or contain id of Resource instance
	//  accessKind defines action performing with resource
	//  return should be ErrForbidden if access is forbidden or nil if granted;
	//  in general may contain other value (e.g. ErrUnknownResource)
	CheckResourceAccess(ctx context.Context, id ID, objectID interface{}, accessKind AccessKind) (err error)
	// CheckResourceAccessByKey may be used for checking access by resource key; see CheckResourceAccess
	CheckResourceAccessByKey(ctx context.Context, key Key, objectID interface{}, accessKind AccessKind) (err error)
}

AccessChecker defines access check implementation interface

type AccessKind

type AccessKind int
const (
	AccessRead AccessKind = iota
	AccessWrite
	AccessCreate
	AccessDelete
	AccessList
)

type ChangeKind

type ChangeKind int
const (
	ChangeModified ChangeKind = iota
	ChangeCreated
	ChangeDeleted
)

type ChangeNotifier

type ChangeNotifier interface {
	NotifyResourceChanged(id ID, objectID interface{}, kind ChangeKind)
}

ChangeNotifier may be used for notification of resource changes

type ID

type ID int

type Key

type Key string

Key may be used to uniquely identify resource by name; generally resource may have unique int id

type Manager

type Manager interface {
	// FindResource looks for resource dy key and returns its id or ErrUnknownResource
	FindResource(key Key) (ID, error)
	// CreateResource creates new resource; if parent is absent parentKey should be ""
	CreateResource(key Key, description string, parentKey Key) (ID, error)
}

Jump to

Keyboard shortcuts

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