Documentation
¶
Overview ¶
Package eval provides a simple interface for evaluating or partially evaluating a policy node in a given environment.
Index ¶
- Variables
- func Eval(n ast.IsNode, env Env) (types.Value, error)
- func PartialError(err error) ast.IsNode
- func PartialPolicy(env Env, p *ast.Policy) (policy *ast.Policy, keep bool)
- func PolicyToNode(p *ast.Policy) ast.Node
- func ToPartialError(n ast.IsNode) (err error, ok bool)
- func ToVariable(v types.Value) (types.String, bool)
- func TypeName(v types.Value) string
- func Variable(v types.String) types.Value
- type Env
Constants ¶
This section is empty.
Variables ¶
var ErrType = eval.ErrType
ErrType is the error type for type errors.
Functions ¶
func PartialError ¶ added in v1.2.6
PartialError returns a node that represents a partial error.
func PartialPolicy ¶ added in v1.2.6
PartialPolicy returns a partially evaluated version of the policy and a boolean indicating if the policy should be kept. (Policies that are determined to evaluate to false are not kept.)
it is supposed to use `PartialPolicy` to partially evaluate a policy, and then use `PolicyToNode` to compile the policy to a node. but you can also use `PartialPolicy` directly.
All the env parts (PARC) must be specified, but you can specify `Variable` as `Variable("principal")` or `Variable("action")` or `Variable("resource")` or `Variable("context")`. also you can specify part of Context to be a `Variable`, such as `key` in `Context` could be `
context := types.NewRecord(types.RecordMap{
"key": Variable("key"),
})
`
when the node is kept, it can be one of three kinds: 1. it is a `ValueNode`, and Must be `ast.True()` (e.g. `ast.True()`) 2. it is a `Node` contains `Variable` (e.g. `ast.Permit().When(ast.Context().Access("key").Equal(ast.Long(42)))`) 3. it is a `Node` contains `PartialError` (e.g. `ast.ExtensionCall(partialErrorName, ast.String("type error: expected comparable value, got string"))`)
you can use the partial evaluation result `ast.Node` to do any additional work you want for example, you can convert it to an sql query. in which case the variable should be a column name and binary node should be an sql expression.
func PolicyToNode ¶ added in v1.2.6
PolicyToNode returns a node compiled from a policy.
func ToPartialError ¶ added in v1.2.6
ToPartialError returns the error if the node is a partial error.
func ToVariable ¶ added in v1.2.6
ToVariable converts a value to a variable.