Thanks to visit codestin.com
Credit goes to pkg.go.dev

compile

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package compile collects a specialized interface to package rego, built for compiling policies into filters. It's a combination of simple evals (of any masking rule), and partial eval, equipped with the correct settings for some options; and paired with post-checks that determine if the result of partial evaluation can be translated into filter queries for certain targets/dialects. On success, the PE results are translated into queries, i.e. SQL WHERE clauses or UCAST expressions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Compile

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

func New

func New(opts ...CompileOption) *Compile

New creates a new `*compile.Compile` struct.

func (*Compile) Prepare

func (c *Compile) Prepare(ctx context.Context, po ...PrepareOption) (*Prepared, error)

Prepare evaluates as much as possible without knowing the (known) input yet

type CompileOption

type CompileOption func(*Compile)

func Mappings

func Mappings(m map[string]any) CompileOption

Mappings allows controlling the table and column names of the generated queries, if they don't match what's in the policy's unknowns. These can be simple maps, like

{
  fruit: {
    $self: "fruit_table",
    name: "name_col",
  }
}

or per-target/per-dialect,

{
  sql: { // per-target
	   fruit: {
	     $self: "fruit_table",
	     name: "name_col",
	   }
  }
}

{
  postgresql: { // per-dialect
      fruit: {
        $self: "fruit_table",
        name: "name_col",
      }
   }
}

func MaskRule

func MaskRule(rule ast.Ref) CompileOption

MaskRule determines which rule of the provided modules is to be evaluated to determine the masking of columns. Applying those masking rules is an out- of-band concern, when processing the results of the query.

func Metrics

func Metrics(m metrics.Metrics) CompileOption

Metrics allows passing the `metrics.Metrics` to use for recording timers. It's passed along to the underlying `rego.Rego` evals, too.

func ParsedQuery

func ParsedQuery(q ast.Body) CompileOption

ParsedQuery lets you pass in the main entrypoint of this filter compilation.

func ParsedUnknowns

func ParsedUnknowns(s ...*ast.Term) CompileOption

ParsedUnknowns lets you pass in the unknowns of this filter compilation.

func Rego

func Rego(o ...func(*rego.Rego)) CompileOption

Rego allows passing through common `*rego.Rego` options

func Target

func Target(target, dialect string) CompileOption

Target lets you control the targets of a filter compilation. If repeated, it'll apply constraints for all the targets simultaneously (i.e. the union of their constraints = the intersection of supported features).

type Filter

type Filter struct {
	Query any
	Masks map[string]any
}

Filter represents the result of a policy-to-filter compilation for one specific target/dialect

type Filters

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

Filters represents all the filters compiled from a policy. Can contain `compile.Filter` for various target/dialect combinations.

func (*Filters) For

func (f *Filters) For(target, dialect string) Filter

For is a helper method to retrieve the `compile.Filter` for a specific target/dialect.

func (*Filters) One

func (f *Filters) One() Filter

One is a helper that extracts a single `compile.Filter`. Only safe to use when filters have been compiled for a single target/dialect, otherwise it'll return a random result of the compile filters. Panics when there's no filter at all.

type PrepareOption

type PrepareOption func(*Prepared)

func RegoPrepareOptions

func RegoPrepareOptions(o ...rego.PrepareOption) PrepareOption

RegoPrepareOptions lets you pass through any `rego.PrepareOption`.

type Prepared

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

Prepared represents a ready-for-eval intermediate state where everything not depending on input has already been done.

func (*Prepared) Compile

func (p *Prepared) Compile(ctx context.Context, eo ...rego.EvalOption) (*Filters, error)

Compile does all the steps needed to generate `*compile.Filters` from a prepared state (`*compile.Prepared`).

Jump to

Keyboard shortcuts

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