data

package
v0.3.2 Latest Latest
Warning

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

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

Documentation

Overview

Package data contains components that are used to translate an AST coming from translate.AstTranslator into a datastore's native query which can then be executed inside the datastore.

As a result, a final decision for the opa.PolicyCompiler should be the result of query evaluation.

Index

Constants

View Source
const (
	TypePostgres = "postgres"
	TypeMysql    = "mysql"
	TypeMongo    = "mongo"
)

DatastoreTranslator constant types

Variables

This section is empty.

Functions

This section is empty.

Types

type Attribute

type Attribute struct {
	Entity Entity
	Name   string
}

Attribute of an entity.

func (Attribute) String

func (a Attribute) String() string

String Implements data.Node

func (Attribute) Walk

func (a Attribute) Walk(vis func(v Node) error) error

Walk Implements data.Node

type Call

type Call struct {
	Operator Operator
	Operands []Node
}

Call represented by an operand and a list of arguments.

func (Call) String

func (c Call) String() string

String Implements data.Node

func (Call) Walk

func (c Call) Walk(vis func(v Node) error) error

Walk Implements data.Node

type CallOpMapper

type CallOpMapper interface {

	// Handles gets the call-operand this handler handles (i.e. 'abs').
	Handles() string

	// Map returns the corresponding datastore native function (i.e. 'ABS(<arguments>)').
	Map(args ...string) (string, error)
}

CallOpMapper is an abstraction for mapping OPA-native functions to DatastoreTranslator-native functions. Therefore, each CallOpMapper should provide the OPA-native call operand it handles (i.e. abs) and define a function Map() which receives all arguments of the OPA-native function and maps them to a datastore's native function call (i.e. ABS(arg)).

Please note, that the mapped function should include the call-operand as well!

type Condition

type Condition struct {
	Clause Node
}

Condition is a single root condition.

func (Condition) String

func (c Condition) String() string

Implements data.Node

func (Condition) Walk

func (c Condition) Walk(vis func(v Node) error) error

Walk Implements data.Node

type Conjunction

type Conjunction struct {
	Clauses []Node
}

Conjunction of several conditions.

func (Conjunction) String

func (c Conjunction) String() string

String Implements data.Node

func (Conjunction) Walk

func (c Conjunction) Walk(vis func(v Node) error) error

Walk Implements data.Node

type Constant

type Constant struct {
	Value     string
	IsNumeric bool
	IsInt     bool
	IsFloat32 bool
}

Constant is a simple constant.

func (Constant) String

func (c Constant) String() string

String Implements data.Node

func (Constant) Walk

func (c Constant) Walk(vis func(v Node) error) error

Walk Implements data.Node

type Datastore added in v0.2.0

type Datastore interface {
	// Configure has to be called once before the component can be used (Otherwise Execute will return an error)!
	Configure(appConf *configs.AppConfig, alias string) error

	// Execute translates the given Query-AST into a datastore's native query and executes the query afterward via the passed data.DatastoreExecutor.
	Execute(ctx context.Context, query Node) (bool, error)
}

Datastore is the interface that maps a generic designed AST returned by translate.AstTranslator to a native query-statement using the passed data.DatastoreTranslator and execute by the passed data.DatastoreExecutor. This should be generally done by translating the Query-AST into the datastore's native query language. If the query returns any result, the datastore should return true, otherwise false.

type DatastoreExecutor

type DatastoreExecutor interface {

	// Configure waits for the attached databases to be reachable by pinging the configured connection every 3 seconds for 1 minute
	// and then configures the Datastore itself.
	//
	// If the database isn't reachable or the Datastore itself fails during this process, the encountered error will be returned (otherwise nil).
	Configure(appConf *configs.AppConfig, alias string) error

	// Execute executes the native query and returns true if the query is not empty and false otherwise.
	Execute(ctx context.Context, query DatastoreQuery) (bool, error)
}

DatastoreExecutor is the interface that executes a native datastore query and returns the final decision (Allow/Deny) based on the query response. If the query returns any result, the executor returns true, otherwise false.

Please note, that connection-pool-handling should also be done by the DatastoreExecutor internally.

type DatastoreQuery added in v0.2.0

type DatastoreQuery struct {
	Statement  any
	Parameters []any
}

DatastoreQuery holds a prepared query statement and their parameters

type DatastoreTranslator

type DatastoreTranslator interface {

	// Configure has to be called once before the component can be used (Otherwise Execute will return an error)!
	Configure(appConf *configs.AppConfig, alias string) error

	// Execute translates the given Query-AST into a datastore's native query
	Execute(ctx context.Context, query Node) (DatastoreQuery, error)
}

DatastoreTranslator is the interface that maps a generic designed AST returned by translate.AstTranslator to a native query-statement which is understood by a matching data.DatastoreExecutor. This should be generally done by translating the Query-AST into the datastore's native query language.

type Disjunction

type Disjunction struct {
	Clauses []Node
}

Disjunction of several disjunctions.

func (Disjunction) String

func (d Disjunction) String() string

String Implements data.Node

func (Disjunction) Walk

func (d Disjunction) Walk(vis func(v Node) error) error

Walk Implements data.Node

type Entity

type Entity struct {
	Value string
}

Entity represents an entity

func (Entity) String

func (e Entity) String() string

String Implements data.Node

func (Entity) Walk

func (e Entity) Walk(vis func(v Node) error) error

Walk Implements data.Node

type Link struct {
	Entities []Entity
}

Link between a parent entity and a list of entities with corresponding conditions.

func (Link) String

func (l Link) String() string

String Implements data.Node

func (Link) Walk

func (l Link) Walk(vis func(v Node) error) error

Walk Implements data.Node

type Node

type Node interface {

	// String returns the current node as string representation (In case of a leave this will be the contained Value).
	String() string

	// Walk the current node (Buttom-Up, Left-to-Right).
	Walk(func(v Node) error) error
}

Node is the abstract interface that every Node of the Query-AST implements.

type Operator

type Operator struct {
	Value string
}

An Operator of the AST.

func (Operator) String

func (o Operator) String() string

String Implements data.Node

func (Operator) Walk

func (o Operator) Walk(vis func(v Node) error) error

Walk Implements data.Node

type Query

type Query struct {
	From      Entity
	Link      Link
	Condition Condition
}

Query which contains links between entities and a condition.

func (Query) String

func (q Query) String() string

String Implements data.Node

func (Query) Walk

func (q Query) Walk(vis func(v Node) error) error

Walk Implements data.Node

type Union

type Union struct {
	Clauses []Node
}

Union of multiple queries.

func (Union) String

func (u Union) String() string

String implements data.Node

func (Union) Walk

func (u Union) Walk(vis func(v Node) error) error

Walk implements data.Node

Jump to

Keyboard shortcuts

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