package storage
import "github.com/open-policy-agent/opa/storage"
Index ¶
- Constants
- func IsNotFound(err error) bool
- func LoadPolicies(bufs map[string][]byte) (map[string]*ast.Module, error)
- type Bindings
- func NewBindings() *Bindings
- func (b *Bindings) Copy() *Bindings
- func (b *Bindings) Equal(other *Bindings) bool
- func (b *Bindings) Get(k ast.Value) ast.Value
- func (b *Bindings) Hash() int
- func (b *Bindings) Iter(iter func(ast.Value, ast.Value) bool) bool
- func (b *Bindings) Put(k, v ast.Value)
- func (b *Bindings) String() string
- func (b *Bindings) Update(other *Bindings) *Bindings
- type DataStore
- func NewDataStore() *DataStore
- func NewDataStoreFromJSONObject(data map[string]interface{}) *DataStore
- func (ds *DataStore) Get(path []interface{}) (interface{}, error)
- func (ds *DataStore) GetRef(ref ast.Ref) (interface{}, error)
- func (ds *DataStore) MakePath(path []interface{}) error
- func (ds *DataStore) MustGet(path []interface{}) interface{}
- func (ds *DataStore) Patch(op PatchOp, path []interface{}, value interface{}) error
- func (ds *DataStore) String() string
- type ErrCode
- type Error
- type Index
- func NewIndex() *Index
- func (ind *Index) Add(val interface{}, bindings *Bindings)
- func (ind *Index) Iter(val interface{}, iter func(*Bindings) error) error
- func (ind *Index) String() string
- type Indices
- func NewIndices() *Indices
- func (ind *Indices) Build(store *DataStore, ref ast.Ref) error
- func (ind *Indices) Drop(ref ast.Ref)
- func (ind *Indices) Get(ref ast.Ref) *Index
- func (ind *Indices) Iter(iter func(ast.Ref, *Index) error) error
- func (ind *Indices) String() string
- type PatchOp
- type PolicyStore
- func NewPolicyStore(store *DataStore, policyDir string) *PolicyStore
- func (p *PolicyStore) Add(id string, mod *ast.Module, raw []byte, persist bool) error
- func (p *PolicyStore) Get(id string) (*ast.Module, error)
- func (p *PolicyStore) GetRaw(id string) ([]byte, error)
- func (p *PolicyStore) List() map[string]*ast.Module
- func (p *PolicyStore) Open(f func(map[string][]byte) (map[string]*ast.Module, error)) error
- func (p *PolicyStore) Remove(id string) error
Constants ¶
Patch supports add, remove, and replace operations.
Functions ¶
func IsNotFound ¶
IsNotFound returns true if this error is a NotFoundErr
func LoadPolicies ¶
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 ¶
Copy returns a shallow copy of these bindings.
func (*Bindings) Equal ¶
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 ¶
Get returns the binding for the given key.
func (*Bindings) Hash ¶
Hash returns the hash code for the bindings.
func (*Bindings) Iter ¶
Iter iterates the bindings and calls the "iter" function for each key/value pair.
func (*Bindings) Put ¶
Put inserts a key/value pair.
func (*Bindings) String ¶
func (*Bindings) Update ¶
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 ¶
NewDataStoreFromJSONObject returns a new DataStore containing the supplied documents. This is mostly for test purposes.
func (*DataStore) Get ¶
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 ¶
GetRef returns the value in Storage referred to by the reference. This is a convienence function.
func (*DataStore) MakePath ¶
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 ¶
Patch modifies the store by performing the associated add/remove/replace operation on the given path.
func (*DataStore) 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 ¶
Error is the error type returned by Storage functions.
func (*Error) Error ¶
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 ¶
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 ¶
Iter calls the iter function for each set of bindings for the value.
func (*Index) 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 ¶
Build initializes the references' index by walking the store for the reference and creating the index that maps values to bindings.
func (*Indices) Drop ¶
Drop removes the index for the reference.
func (*Indices) Get ¶
Get returns the reference's index.
func (*Indices) Iter ¶
Iter calls the iter function for each of the indices.
func (*Indices) 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 ¶
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 ¶
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.
Source Files ¶
bindings.go datastore.go index.go policystore.go
- Version
- v0.1.0-rc1
- Published
- Jun 3, 2016
- Platform
- linux/amd64
- Imports
- 9 packages
- Last checked
- 3 minutes ago –
Tools for package owners.