policy

package
v0.0.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a policy engine client

func New

func New(options ...Option) (*Client, error)

New creates a new Local client. It requires one or more WithFile, WithDir or WithPolicyData.

func (*Client) Query

func (x *Client) Query(ctx *model.Context, query string, input any, output any) error

Query evaluates policy with `input` data. The result will be written to `out`. `out` must be pointer of instance.

type Mock

type Mock struct {
	MockQuery func(ctx *model.Context, query string, input any) (any, error)
}

func (*Mock) Query

func (x *Mock) Query(ctx *model.Context, query string, input any, output any) error

type Option

type Option func(x *Client)

Option is a functional option for Client

func WithDir

func WithDir(dirPath string) Option

WithDir specifies directory path of .rego policy. Import policy files recursively.

func WithFile

func WithFile(filePath string) Option

WithFile specifies file path of .rego policy. Import policy files recursively.

func WithPackage

func WithPackage(pkg string) Option

WithPackage specifies using package name. e.g. "example.my_policy"

func WithPolicyData

func WithPolicyData(name, policy string) Option

WithPolicyData specifies raw policy data with name. If the `name` conflicts with file path loaded by WithFile or WithDir, the policy overwrites data loaded by WithFile or WithDir.

func WithPrinter

func WithPrinter(fn RegoPrint) Option

WithPrinter specifies callback function to print statement in policy. This is useful for debugging.

func WithReadFile

func WithReadFile(fn func(string) ([]byte, error)) Option

WithReadFile specifies file path of .rego policy. Import policy files recursively.

type RegoPrint

type RegoPrint func(ctx *model.Context, file string, row int, msg string) error

Jump to

Keyboard shortcuts

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