data

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: Apache-2.0 Imports: 2 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

Implements data.Node

func (Attribute) Walk

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

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

Implements data.Node

func (Call) Walk

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

Implements data.Node

type CallOpMapper

type CallOpMapper interface {

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

	// Return 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
}

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

Implements data.Node

type Conjunction

type Conjunction struct {
	Clauses []Node
}

Conjunction of several conditions.

func (Conjunction) String

func (c Conjunction) String() string

Implements data.Node

func (Conjunction) Walk

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

Implements data.Node

type Constant

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

A simple Constant.

func (Constant) String

func (c Constant) String() string

Implements data.Node

func (Constant) Walk

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

Implements data.Node

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(statement interface{}, params []interface{}) (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 DatastoreTranslator

type DatastoreTranslator interface {

	// Please note that 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 afterwards via the passed data.DatastoreExecutor.
	Execute(query Node) (bool, error)
}

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

type Disjunction

type Disjunction struct {
	Clauses []Node
}

Disjunction of several disjunctions.

func (Disjunction) String

func (d Disjunction) String() string

Implements data.Node

func (Disjunction) Walk

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

Implements data.Node

type Entity

type Entity struct {
	Value string
}

An Entity

func (Entity) String

func (e Entity) String() string

Implements data.Node

func (Entity) Walk

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

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

Implements data.Node

func (Link) Walk

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

Implements data.Node

type Node

type Node interface {

	// Get 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

Implements data.Node

func (Operator) Walk

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

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

Implements data.Node

func (Query) Walk

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

Implements data.Node

type Union

type Union struct {
	Clauses []Node
}

Union of multiple queries.

func (Union) String

func (u Union) String() string

Implements data.Node

func (Union) Walk

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

Implements data.Node

Jump to

Keyboard shortcuts

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