nopa

package module
v0.0.0-...-f3d8ae0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

README

nopa

NATS + OPA

Nopa is a simple way to store OPA bundles in NATS object storage and have the bundle updated in real time.

Usage

Using the example application:

  • Create a NATS object bucket: nats obj add bundles
  • Add the bundle to the object store: nats obj put bundles bundle.tar.gz
  • Start the server go run main.go
  • Send a request to the service nats req test '{"package": "data.foo", "input": {"foo": "bar"}}'

[!TIP] It is up to your application to handle how the package name and input are generated. You could for example use the subject as the package name.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound error = fmt.Errorf("package not found")
)

Functions

This section is empty.

Types

type Agent

type Agent struct {
	BundleName  string
	ObjectStore nats.ObjectStore
	OPAStore    storage.Store

	Logger *logr.Logger
	Env    map[string]string

	Compiler  *ast.Compiler
	Modifiers []BundleModifyFunc
	// contains filtered or unexported fields
}

func NewAgent

func NewAgent(opts AgentOpts) *Agent

func (*Agent) Activate

func (a *Agent) Activate(ctx context.Context, b bundle.Bundle) error

func (*Agent) Eval

func (a *Agent) Eval(ctx context.Context, input []byte, pkg string) ([]byte, error)

Eval evaluates the input against the policy package

func (*Agent) SetBundle

func (a *Agent) SetBundle(name string) error

SetBundle updates the in-memory store with the bundle retrieved from the NATS object store

func (*Agent) SetRuntime

func (a *Agent) SetRuntime()

func (*Agent) WatchBundleUpdates

func (a *Agent) WatchBundleUpdates()

type AgentOpts

type AgentOpts struct {
	BundleName  string
	ObjectStore nats.ObjectStore
	Logger      *logr.Logger
	Env         map[string]string
	Modifiers   []BundleModifyFunc
}

type BundleModifyFunc

type BundleModifyFunc func(b bundle.Bundle) (bundle.Bundle, error)

BundleModifyFunc will take a bundle and allow for modifications like adding custom modules

Jump to

Keyboard shortcuts

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