storage

package
v0.1.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2016 License: Apache-2.0 Imports: 9 Imported by: 269

Documentation

Index

Constants

View Source
const (
	AddOp     PatchOp = iota
	RemoveOp          = iota
	ReplaceOp         = iota
)

Patch supports add, remove, and replace operations.

Variables

This section is empty.

Functions

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if this error is a NotFoundErr

func LoadPolicies

func LoadPolicies(bufs map[string][]byte) (map[string]*ast.Module, error)

LoadPolicies is the default callback function that will be used when opening the policy store.

Types

type Bindings

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

Bindings represents a mapping between key/value pairs. The key/value pairs are AST values contained in expressions. Insertion of a key/value pair represents unification of the two values.

func NewBindings

func NewBindings() *Bindings

NewBindings returns a new empty set of bindings.

func (*Bindings) Copy

func (b *Bindings) Copy() *Bindings

Copy returns a shallow copy of these bindings.

func (*Bindings) Equal

func (b *Bindings) Equal(other *Bindings) bool

Equal returns true if these bindings equal the other bindings. Two bindings are equal if they contain the same key/value pairs.

func (*Bindings) Get

func (b *Bindings) Get(k ast.Value) ast.Value

Get returns the binding for the given key.

func (*Bindings) Hash

func (b *Bindings) Hash() int

Hash returns the hash code for the bindings.

func (*Bindings) Iter

func (b *Bindings) Iter(iter func(ast.Value, ast.Value) bool) bool

Iter iterates the bindings and calls the "iter" function for each key/value pair.

func (*Bindings) Put

func (b *Bindings) Put(k, v ast.Value)

Put inserts a key/value pair.

func (*Bindings) String

func (b *Bindings) String() string

func (*Bindings) Update

func (b *Bindings) Update(other *Bindings) *Bindings

Update returns new bindings that are the union of these bindings and the other bindings.

type DataStore

type DataStore struct {
	Indices *Indices
	// contains filtered or unexported fields
}

DataStore is the backend containing rule references and data.

func NewDataStore

func NewDataStore() *DataStore

NewDataStore returns an empty DataStore.

func NewDataStoreFromJSONObject

func NewDataStoreFromJSONObject(data map[string]interface{}) *DataStore

NewDataStoreFromJSONObject returns a new DataStore containing the supplied documents. This is mostly for test purposes.

func (*DataStore) Get

func (ds *DataStore) Get(path []interface{}) (interface{}, error)

Get returns the value in Storage referenced by path. If the lookup fails, an error is returned with a message indicating why the failure occurred.

func (*DataStore) GetRef

func (ds *DataStore) GetRef(ref ast.Ref) (interface{}, error)

GetRef returns the value in Storage referred to by the reference. This is a convienence function.

func (*DataStore) MakePath

func (ds *DataStore) MakePath(path []interface{}) error

MakePath ensures the specified path exists by creating elements as necessary.

func (*DataStore) MustGet

func (ds *DataStore) MustGet(path []interface{}) interface{}

MustGet returns the value in Storage reference by path. If the lookup fails, the function will panic.

func (*DataStore) Patch

func (ds *DataStore) Patch(op PatchOp, path []interface{}, value interface{}) error

Patch modifies the store by performing the associated add/remove/replace operation on the given path.

func (*DataStore) String

func (ds *DataStore) String() string

type ErrCode

type ErrCode int

ErrCode represents the collection of error types that can be returned by Storage.

const (
	// InternalErr indicates an unknown, internal error has occurred.
	InternalErr ErrCode = iota

	// NotFoundErr indicates the path used in the storage operation does not
	// locate a document.
	NotFoundErr = iota
)

type Error

type Error struct {
	Code    ErrCode
	Message string
}

Error is the error type returned by Storage functions.

func (*Error) Error

func (err *Error) Error() string

type Index

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

Index contains a mapping of values to bindings.

func NewIndex

func NewIndex() *Index

NewIndex returns a new empty index.

func (*Index) Add

func (ind *Index) Add(val interface{}, bindings *Bindings)

Add updates the index to include new bindings for the value. If the bindings already exist for the value, no change is made.

func (*Index) Iter

func (ind *Index) Iter(val interface{}, iter func(*Bindings) error) error

Iter calls the iter function for each set of bindings for the value.

func (*Index) String

func (ind *Index) String() string

type Indices

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

Indices contains a mapping of non-ground references to values to sets of bindings.

+------+------------------------------------+ | ref1 | val1 | bindings-1, bindings-2, ... | | +------+-----------------------------+ | | val2 | bindings-m, bindings-m, ... | | +------+-----------------------------+ | | .... | ... | +------+------+-----------------------------+ | ref2 | .... | ... | +------+------+-----------------------------+ | ... | +-------------------------------------------+

The "value" is the data value stored at the location referred to by the ground reference obtained by plugging bindings into the non-ground reference that is the index key.

func NewIndices

func NewIndices() *Indices

NewIndices returns an empty indices.

func (*Indices) Build

func (ind *Indices) Build(store *DataStore, ref ast.Ref) error

Build initializes the references' index by walking the store for the reference and creating the index that maps values to bindings.

func (*Indices) Drop

func (ind *Indices) Drop(ref ast.Ref)

Drop removes the index for the reference.

func (*Indices) Get

func (ind *Indices) Get(ref ast.Ref) *Index

Get returns the reference's index.

func (*Indices) Iter

func (ind *Indices) Iter(iter func(ast.Ref, *Index) error) error

Iter calls the iter function for each of the indices.

func (*Indices) String

func (ind *Indices) String() string

type PatchOp

type PatchOp int

PatchOp is the enumeration of supposed modifications.

type PolicyStore

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

PolicyStore provides a storage abstraction for policy definitions and modules.

func NewPolicyStore

func NewPolicyStore(store *DataStore, policyDir string) *PolicyStore

NewPolicyStore returns an empty PolicyStore.

func (*PolicyStore) Add

func (p *PolicyStore) Add(id string, mod *ast.Module, raw []byte, persist bool) error

Add inserts the policy module into the store. If an existing policy module exists with the same ID, it is overwritten. If persist is false, then the policy will not be persisted.

func (*PolicyStore) Get

func (p *PolicyStore) Get(id string) (*ast.Module, error)

Get returns the policy module for id.

func (*PolicyStore) GetRaw

func (p *PolicyStore) GetRaw(id string) ([]byte, error)

GetRaw returns the raw content of the module for id.

func (*PolicyStore) List

func (p *PolicyStore) List() map[string]*ast.Module

List returns all of the modules.

func (*PolicyStore) Open

func (p *PolicyStore) Open(f func(map[string][]byte) (map[string]*ast.Module, error)) error

Open initializes the policy store.

This should be called on startup to load policies from persistent storage. The callback function "f" will be invoked with the buffers representing the persisted policies. The callback should return the compiled version of the policies so that they can be installed into the data store.

func (*PolicyStore) Remove

func (p *PolicyStore) Remove(id string) error

Remove removes the policy module for id.

Jump to

Keyboard shortcuts

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