sdk

package
Version: v0.46.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2022 License: Apache-2.0 Imports: 25 Imported by: 5

Documentation

Overview

Package sdk contains a high-level API for embedding OPA inside of Go programs.

Index

Constants

View Source
const (
	// UndefinedErr indicates that the queried decision was undefined.
	UndefinedErr = "opa_undefined_error"
)

Variables

This section is empty.

Functions

func IsUndefinedErr added in v0.29.0

func IsUndefinedErr(err error) bool

IsUndefinedErr returns true of the err represents an undefined decision error.

Types

type ConfigOptions added in v0.29.0

type ConfigOptions struct {

	// Config provides the OPA configuration for this instance. The config can
	// be supplied as a YAML or JSON byte stream. See
	// https://www.openpolicyagent.org/docs/latest/configuration/ for detailed
	// description of the supported configuration.
	Config io.Reader

	// Ready sets a channel to notify when the OPA instance is ready. If this
	// field is not set, the Configure() function will block until ready. The
	// channel is closed to signal readiness.
	Ready chan struct{}
	// contains filtered or unexported fields
}

ConfigOptions contains parameters to (re-)configure OPA.

type DecisionOptions added in v0.29.0

type DecisionOptions struct {
	Now      time.Time   // specifies wallclock time used for time.now_ns(), decision log timestamp, etc.
	Path     string      // specifies name of policy decision to evaluate (e.g., example/allow)
	Input    interface{} // specifies value of the input document to evaluate policy with
	NDBCache interface{} // specifies the non-deterministic builtins cache to use for evaluation.
}

DecisionOptions contains parameters for query evaluation.

type DecisionResult added in v0.29.0

type DecisionResult struct {
	ID     string      // provides a globally unique identifier for this decision (which is included in the decision log.)
	Result interface{} // provides the output of query evaluation.
}

DecisionResult contains the output of query evaluation.

type Error

type Error struct {
	Code    string `json:"code"`
	Message string `json:"message,omitempty"`
}

Error represents an internal error in the SDK.

func (*Error) Error added in v0.29.0

func (err *Error) Error() string

type OPA added in v0.29.0

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

OPA represents an instance of the policy engine. OPA can be started with several options that control configuration, logging, and lifecycle.

func New added in v0.29.0

func New(ctx context.Context, opts Options) (*OPA, error)

New returns a new OPA object. This function should minimally be called with options that specify an OPA configuration file.

func (*OPA) Configure added in v0.29.0

func (opa *OPA) Configure(ctx context.Context, opts ConfigOptions) error

Configure updates the configuration of the OPA in-place. This function should be called in response to configuration updates in the environment. This function is atomic. If the configuration update cannot be successfully applied, the old configuration will remain intact.

func (*OPA) Decision added in v0.29.0

func (opa *OPA) Decision(ctx context.Context, options DecisionOptions) (*DecisionResult, error)

Decision returns a named decision. This function is threadsafe.

func (*OPA) Partial added in v0.39.0

func (opa *OPA) Partial(ctx context.Context, options PartialOptions) (*PartialResult, error)

Partial returns a named decision. This function is threadsafe. Note(philipc): The NDBCache is unused here, because non-deterministic builtins are not run during partial evaluation.

func (*OPA) Plugin added in v0.36.0

func (opa *OPA) Plugin(name string) plugins.Plugin

Plugin returns the named plugin. If the plugin does not exist, this function returns nil.

func (*OPA) Stop added in v0.29.0

func (opa *OPA) Stop(ctx context.Context)

Stop closes the OPA. The OPA cannot be restarted.

type Options added in v0.29.0

type Options struct {

	// Config provides the OPA configuration for this instance. The config can
	// be supplied as a YAML or JSON byte stream. See
	// https://www.openpolicyagent.org/docs/latest/configuration/ for detailed
	// description of the supported configuration.
	Config io.Reader

	// Logger sets the logging implementation to use for standard logs emitted
	// by OPA. By default, standard logging is disabled.
	Logger logging.Logger

	// ConsoleLogger sets the logging implementation to use for emitting Status
	// and Decision Logs to the console. By default, console logging is enabled.
	ConsoleLogger logging.Logger

	// Ready sets a channel to notify when the OPA instance is ready. If this
	// field is not set, the New() function will block until ready. The channel
	// is closed to signal readiness.
	Ready chan struct{}

	// Plugins provides a set of plugins.Factory instances that will be
	// registered with the OPA SDK instance.
	Plugins map[string]plugins.Factory

	// When calling the sdk the user can specify an opa id so that repeat calls to the sdk don't have a unique opa id
	ID string
	// contains filtered or unexported fields
}

Options contains parameters to setup and configure OPA.

type PartialOptions added in v0.39.0

type PartialOptions struct {
	Now      time.Time          // specifies wallclock time used for time.now_ns(), decision log timestamp, etc.
	Input    interface{}        // specifies value of the input document to evaluate policy with
	Query    string             // specifies the query to be partially evaluated
	Unknowns []string           // specifies the unknown elements of the policy
	Mapper   PartialQueryMapper // specifies the mapper to use when processing results
}

PartialOptions contains parameters for partial query evaluation.

type PartialQueryMapper added in v0.39.0

type PartialQueryMapper interface {
	// The first interface being returned is the type that will be used for further processing
	MapResults(pq *rego.PartialQueries) (interface{}, error)
	// This should be able to take the Result object from MapResults and return a type that can be logged as JSON
	ResultToJSON(result interface{}) (interface{}, error)
}

type PartialResult added in v0.39.0

type PartialResult struct {
	ID     string               // decision ID
	Result interface{}          // mapped result
	AST    *rego.PartialQueries // raw result
}

type RawMapper added in v0.39.0

type RawMapper struct {
}

func (*RawMapper) MapResults added in v0.39.0

func (e *RawMapper) MapResults(pq *rego.PartialQueries) (interface{}, error)

func (*RawMapper) ResultToJSON added in v0.39.0

func (e *RawMapper) ResultToJSON(results interface{}) (interface{}, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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