inmem

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 3 Imported by: 171

Documentation

Overview

Deprecated: This package is intended for older projects transitioning from OPA v0.x and will remain for the lifetime of OPA v1.x, but its use is not recommended. For newer features and behaviours, such as defaulting to the Rego v1 syntax, use the corresponding components in the github.com/open-policy-agent/opa/v1 package instead. See https://www.openpolicyagent.org/docs/latest/v0-compatibility/ for more information.

Package inmem implements an in-memory version of the policy engine's storage layer.

The in-memory store is used as the default storage layer implementation. The in-memory store supports multi-reader/single-writer concurrency with rollback.

Callers should assume the in-memory store does not make copies of written data. Once data is written to the in-memory store, it should not be modified (outside of calling Store.Write). Furthermore, data read from the in-memory store should be treated as read-only.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() storage.Store

New returns an empty in-memory store.

func NewFromObject

func NewFromObject(data map[string]interface{}) storage.Store

NewFromObject returns a new in-memory store from the supplied data object.

func NewFromObjectWithOpts added in v0.44.0

func NewFromObjectWithOpts(data map[string]interface{}, opts ...Opt) storage.Store

NewFromObjectWithOpts returns a new in-memory store from the supplied data object, with the options passed.

func NewFromReader

func NewFromReader(r io.Reader) storage.Store

NewFromReader returns a new in-memory store from a reader that produces a JSON serialized object. This function is for test purposes.

func NewFromReaderWithOpts added in v0.44.0

func NewFromReaderWithOpts(r io.Reader, opts ...Opt) storage.Store

NewFromReader returns a new in-memory store from a reader that produces a JSON serialized object, with extra options. This function is for test purposes.

func NewWithOpts added in v0.44.0

func NewWithOpts(opts ...Opt) storage.Store

NewWithOpts returns an empty in-memory store, with extra options passed.

Types

type Opt added in v0.44.0

type Opt = v1.Opt

An Opt modifies store at instantiation.

func OptReturnASTValuesOnRead added in v0.70.0

func OptReturnASTValuesOnRead(enabled bool) Opt

OptReturnASTValuesOnRead sets whether data values added to the store should be eagerly converted to AST values, which are then returned on read.

When enabled, this feature does not sanity check data before converting it to AST values, which may result in panics if the data is not valid. Callers should ensure that passed data can be serialized to AST values; otherwise, it's recommended to also enable OptRoundTripOnWrite.

func OptRoundTripOnWrite added in v0.44.0

func OptRoundTripOnWrite(enabled bool) Opt

OptRoundTripOnWrite sets whether incoming objects written to store are round-tripped through JSON to ensure they are serializable to JSON.

Callers should disable this if they can guarantee all objects passed to Write() are serializable to JSON. Failing to do so may result in undefined behavior, including panics.

Usually, when only storing objects in the inmem store that have been read via encoding/json, this is safe to disable, and comes with an improvement in performance and memory use.

If setting to false, callers should deep-copy any objects passed to Write() unless they can guarantee the objects will not be mutated after being written, and that mutations happening to the objects after they have been passed into Write() don't affect their logic.

Directories

Path Synopsis
Deprecated: This package is intended for older projects transitioning from OPA v0.x and will remain for the lifetime of OPA v1.x, but its use is not recommended.
Deprecated: This package is intended for older projects transitioning from OPA v0.x and will remain for the lifetime of OPA v1.x, but its use is not recommended.

Jump to

Keyboard shortcuts

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