Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-6559 Add ability to create decision labels within a policy #6681

Open
wants to merge 114 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
9f44854
topdown/http: Respect raise_error flag during input validation
ashutosh-narkar Jan 26, 2024
6d20abb
Updating the Decision Log to include new Field
tsidebottom Feb 21, 2024
5ce2305
Adding new Built-in to builtins.go
tsidebottom Feb 21, 2024
7cd3dac
Creating shell files for the actual Built-in
tsidebottom Feb 21, 2024
f448f68
Update decision_label_add.go
tsidebottom Feb 21, 2024
f40c4cb
Early work on Builtin Code
tsidebottom Feb 23, 2024
7cd66e1
Add DecisionLabel to Rego
tsidebottom Feb 26, 2024
689db4c
Started adding Decision Label to Rego instance
tsidebottom Feb 26, 2024
f837330
Added DecisionLabel to Rego Struct and Populated
tsidebottom Feb 28, 2024
0458e28
Changed how DecisionLabel is assigned to the EvalContext
tsidebottom Feb 28, 2024
86cf054
Mimicked NDBuiltinCache for DecisionLabel
tsidebottom Feb 28, 2024
588b7e2
(Hopefully) fixed the Object Functions for DecisionLabel
tsidebottom Feb 29, 2024
b7f9b66
Added DecisionLabel to BuiltinContext Struct
tsidebottom Feb 29, 2024
d1f2340
Added DecisionLabel to the BuiltinContext instantiation
tsidebottom Mar 5, 2024
07aec2e
Added Builtin Code
tsidebottom Mar 6, 2024
1fce17f
Made the error to return from Builtin
tsidebottom Mar 8, 2024
e3fef3e
Fixing Typo in DecisionLabel Object Name
tsidebottom Mar 18, 2024
efb46c1
Added test for DecisionLabel field
tsidebottom Mar 18, 2024
207fb34
Added test for DecisionLabel Field
tsidebottom Mar 18, 2024
b77ad1f
Added test for DecisionLabel Field
tsidebottom Mar 18, 2024
4a69899
More Typos
tsidebottom Mar 19, 2024
34d2b30
Started new builtin test file
tsidebottom Mar 19, 2024
e99b651
Update decision_label_add_test.go
tsidebottom Apr 2, 2024
6ae291b
Update decision_label_add_test.go
tsidebottom Apr 2, 2024
c62c9d4
Aligned Map Types and removed unintended Recursion
tsidebottom Apr 5, 2024
c464aee
Updating Tests to conform to new Input Types
tsidebottom Apr 5, 2024
c29960f
Potential Update for nil interface{} test failure
tsidebottom Apr 5, 2024
46fc50f
Add DecisionLabel to list of Decision Log fields
tsidebottom Apr 5, 2024
9da9647
Comment Cleanup
tsidebottom Apr 5, 2024
2595c69
Updated logos for Permit.io and OPAL in integrations (#6562)
danielbass37 Jan 31, 2024
4e7c680
build(deps): bump github.com/spf13/viper from 1.18.1 to 1.18.2
dependabot[bot] Jan 30, 2024
cd5a3ad
docs: use application/yaml instead of application/x-yaml (#6565)
anderseknert Feb 1, 2024
4d6ac90
build(deps): bump github.com/containerd/containerd from 1.7.12 to 1.7.13
dependabot[bot] Feb 1, 2024
90001b9
docs: Udpate description of the url path usage for v1/data GET and PO…
ashutosh-narkar Feb 3, 2024
75f06a2
build(deps): bump aquasecurity/trivy-action from 0.16.1 to 0.17.0
dependabot[bot] Feb 6, 2024
26e8ac9
Update ADOPTERS.md
orouz Feb 6, 2024
a6c7730
build(deps): bump github.com/opencontainers/image-spec
dependabot[bot] Feb 6, 2024
6ca599e
build(deps): bump github.com/foxcpp/go-mockdns from 1.0.0 to 1.1.0
dependabot[bot] Feb 8, 2024
dc4e18c
build(deps): bump golang.org/x/net from 0.19.0 to 0.21.0
dependabot[bot] Feb 8, 2024
b968f0c
fix(oci): add missing method WithBundleParserOpts to oci_downloader_u…
slonka Feb 8, 2024
8c2930f
build(deps): bump google.golang.org/grpc from 1.61.0 to 1.61.1
dependabot[bot] Feb 14, 2024
f87a9c9
ast+cmd: Allowing bundle to contain calls to unknown Rego functions w…
johanfylling Feb 15, 2024
95dec3a
build(go): bump golang, build with 1.22, support 1.20+ (#6595)
srenatus Feb 20, 2024
606ee87
build(deps): bump google.golang.org/grpc from 1.61.1 to 1.62.0
dependabot[bot] Feb 22, 2024
0263cec
cleanup: use errors.Join
srenatus Feb 27, 2024
2fa18d5
build(deps): bump github.com/prometheus/client_golang
dependabot[bot] Feb 28, 2024
2f5efe9
build: update .go-version to unblock netlify build (#6605)
srenatus Feb 29, 2024
8578f92
Prepare v0.62.0 release
ashutosh-narkar Feb 28, 2024
816ff48
Prepare v0.63.0 development
ashutosh-narkar Feb 29, 2024
21ee2e9
Add Trino to OPA ecosystem
mosabua Feb 29, 2024
ecc2075
build(deps): bump aquasecurity/trivy-action from 0.17.0 to 0.18.0
dependabot[bot] Feb 29, 2024
c6fd25c
update: ADOPTERS.md (#6608)
fredmaggiowski Mar 4, 2024
391af88
build(deps): bump golang.org/x/net from 0.21.0 to 0.22.0
dependabot[bot] Mar 5, 2024
8348eff
build: bump golang 1.22.0 -> 1.22.1 (#6616)
srenatus Mar 6, 2024
4e1a5ed
docs: fix broken schema link (#6617)
charlieegan3 Mar 6, 2024
4aa7b45
Release v0.62.1 (#6618)
srenatus Mar 6, 2024
5818386
Prep development (#6619)
srenatus Mar 6, 2024
579ec7a
build(deps): bump google.golang.org/grpc from 1.62.0 to 1.62.1 (#6621)
dependabot[bot] Mar 6, 2024
83c9862
build(deps): bump github.com/golang/protobuf from 1.5.3 to 1.5.4 (#6620)
dependabot[bot] Mar 6, 2024
10a4d3b
format: Preserve brackets around set union operation
ashutosh-narkar Mar 5, 2024
289665c
Docs: mention homebrew install option
anderseknert Mar 8, 2024
59ebef4
aws: support for Unsigned Payload or provided content sha256 in AWS s…
Feb 14, 2024
e1ed59c
Add Tunnelmole as an open source tunneling option in the Cloudformati…
robbie-cahill Mar 12, 2024
979d79f
build(deps): bump github.com/containerd/containerd from 1.7.13 to 1.7.14
dependabot[bot] Mar 12, 2024
bde6179
Adding integration for Backstage (#6629)
Parsifal-M Mar 13, 2024
e619cde
Add some docs on using env vars in place of CLI flags (#6631)
anderseknert Mar 15, 2024
15c75ce
docs: Update generated CLI docs
Mar 15, 2024
6ae6a8e
test/e2e: Fix missing import in benchmark. (#6632)
philipaconrad Mar 15, 2024
6ff8bbe
cmd/exec: Add timeout flag to help prevent infinite hangs. (#6633)
philipaconrad Mar 18, 2024
12d1066
docs: fix typo (#6637)
setchy Mar 18, 2024
2c9f86f
ADOPTERS.md: Add Facets.cloud to the list
ashutosh-narkar Mar 20, 2024
7705ada
topdown: Fixing overactive Early Exit suppression
johanfylling Mar 21, 2024
d624d8b
chore: remove repetitive words
occupyhabit Mar 23, 2024
1d01ef4
docs: Update delta bundle patch doc for remove op
0marq Mar 26, 2024
25e071c
plugins/rest: Add support to get temp creds via AssumeRole
ashutosh-narkar Mar 15, 2024
a63e9bf
Adding a new function crypto.x509.parse_and_verify_certificates_with_…
yogisinha Mar 27, 2024
8a654f7
download: Surface bundle download errors via debug logging
ashutosh-narkar Mar 26, 2024
9bea8ed
plugins/rest: Update service name while generating signature
ashutosh-narkar Mar 27, 2024
17a11ef
Add Rego v1 keywords (#6649)
anderseknert Mar 28, 2024
cb636c2
docs: Clear up some uses of future keywords (#6653)
charlieegan3 Mar 28, 2024
888db97
Prepare v0.63.0 release (#6656)
johanfylling Mar 28, 2024
79f0a40
Prepare v0.64.0 development
johanfylling Mar 28, 2024
6dc0689
build(deps): bump aquasecurity/trivy-action from 0.18.0 to 0.19.0
dependabot[bot] Mar 28, 2024
29e126d
Refresh maintainers term
ashutosh-narkar Mar 8, 2024
037a023
build(deps): bump peaceiris/actions-hugo from 2 to 3
dependabot[bot] Apr 2, 2024
0d89511
add env0 integration & organization files (#6658)
yarivg Apr 3, 2024
ea137bf
docs: Add Rego comparisons and update env0 (#6663)
charlieegan3 Apr 3, 2024
a165fb1
server: Remove an unnecessary AST-to-JSON conversion for the eval input.
koponen-styra Apr 3, 2024
aa632b5
sdk: expose manager options
xico42 Apr 3, 2024
16ca6ad
compile/compile: Fix panic from CLI + metadata entrypoint overlaps.
philipaconrad Apr 3, 2024
6a86953
server: Remove unnecessary AST-to-JSON conversions.
koponen-styra Apr 3, 2024
c5147b4
build(go): bump 1.22.1 -> 1.22.2 (#6672)
srenatus Apr 4, 2024
bb98609
build(deps): bump golang.org/x/net from 0.22.0 to 0.23.0 (#6671)
dependabot[bot] Apr 4, 2024
1565092
build(deps): bump google.golang.org/grpc from 1.62.1 to 1.63.0 (#6673)
dependabot[bot] Apr 4, 2024
1c14d55
build(deps): bump github.com/prometheus/client_model from 0.5.0 to 0.6.1
dependabot[bot] Apr 4, 2024
322ad38
server: Retry cert reloading & test case step
charlieegan3 Apr 4, 2024
18af050
topdown: Add `json.marshal_with_options()` builtin for indented/"pret…
sean-r-williams Apr 5, 2024
4de5051
go.{mod,sum}: update (#6678)
srenatus Apr 5, 2024
5a08d27
build(deps): bump golang.org/x/net from 0.23.0 to 0.24.0 (#6680)
dependabot[bot] Apr 5, 2024
593c877
build(deps): bump github.com/containerd/containerd from 1.7.14 to 1.7.15
dependabot[bot] Apr 8, 2024
6eb1929
build(deps): bump google.golang.org/grpc from 1.63.0 to 1.63.2
dependabot[bot] Apr 9, 2024
248337c
deps: Improving `deps` command performance (#6688)
johanfylling Apr 9, 2024
76686c9
Removed MustJSON as a test
tsidebottom Apr 10, 2024
db398bd
fixes #6206; using cuboid rather than cube
kd-labs Apr 10, 2024
b0579b3
Add `rego_version` attribute to bundle manifest (#6579)
johanfylling Apr 10, 2024
1cea30f
sdk: fix bug while activating v1 bundle with the bundle plugin (#6689)
xico42 Apr 11, 2024
3952857
Updating test input format
tsidebottom Apr 11, 2024
27a308a
docs: Updating OPA v1.0 docs
johanfylling Apr 11, 2024
b837581
Removed Test for impossible Scenario
tsidebottom Apr 15, 2024
ed9ada0
Merge branch 'main' into main
tsidebottom Apr 17, 2024
aa3ebd5
Update decision_label_add_test.go
tsidebottom Apr 17, 2024
4070f53
Added new Builtin to capabilities.json
tsidebottom Apr 18, 2024
4430cb1
Adding DecisionLabelAdd to builtin_metadata.json
tsidebottom Apr 18, 2024
af3a710
Finished adding Builtin to builtin_metadata.json
tsidebottom Apr 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions ast/builtins.go
Expand Up @@ -243,6 +243,9 @@ var DefaultBuiltins = [...]*Builtin{
// HTTP
HTTPSend,

// Decision Labels
DecisionLabelAdd,

// GraphQL
GraphQLParse,
GraphQLParseAndVerify,
Expand Down Expand Up @@ -2701,6 +2704,24 @@ var HTTPSend = &Builtin{
Nondeterministic: true,
}

/**
* Decision Labels
*/

// DecisionLabelAdd takes in Policy result data and adds it to the Decision Label property
var DecisionLabelAdd = &Builtin{
Name: "decision.label.add",
Description: "adds Policy results to the Decision Label Property",
Decl: types.NewFunction(
types.Args(
types.Named("label", types.S).Description("string label of the tag"),
types.Named("value", types.A).Description("string value of the tag"),
),
types.Named("labels", types.NewObject(nil, types.NewDynamicProperty(types.S, types.A))),
),
Nondeterministic: true,
}

/**
* GraphQL
*/
Expand Down
27 changes: 27 additions & 0 deletions builtin_metadata.json
Expand Up @@ -49,6 +49,9 @@
"crypto.x509.parse_keypair",
"crypto.x509.parse_rsa_private_key"
],
"decision": [
"decision.label.add"
],
"encoding": [
"base64.decode",
"base64.encode",
Expand Down Expand Up @@ -4822,6 +4825,30 @@
},
"wasm": false
},
"decision.label.add": {
"args": [
{
"description": "string label of the tag",
"name": "label",
"type": "string"
},
{
"description": "string value of the tag",
"name": "value",
"type": "any"
}
],
"available": [
"edge"
],
"description": "adds Policy results to the Decision Label Property",
"introduced": "edge",
"result": {
"name": "labels",
"type": "object[string: any]"
},
"wasm": false
},
"div": {
"args": [
{
Expand Down
26 changes: 26 additions & 0 deletions capabilities.json
Expand Up @@ -895,6 +895,32 @@
"type": "function"
}
},
{
"name": "decision.label.add",
"decl": {
"args": [
{
"type": "string"
},
{
"type": "any"
}
],
"result": {
"dynamic": {
"key": {
"type": "string"
},
"value": {
"type": "any"
}
},
"type": "object"
},
"type": "function"
},
"nondeterministic": true
},
{
"name": "div",
"decl": {
Expand Down
37 changes: 19 additions & 18 deletions docs/content/management-decision-logs.md

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions plugins/logs/plugin.go
Expand Up @@ -57,6 +57,7 @@ type EventV1 struct {
Result *interface{} `json:"result,omitempty"`
MappedResult *interface{} `json:"mapped_result,omitempty"`
NDBuiltinCache *interface{} `json:"nd_builtin_cache,omitempty"`
DecisionLabel *interface{} `json:"decision_label,omitempty"`
Erased []string `json:"erased,omitempty"`
Masked []string `json:"masked,omitempty"`
Error error `json:"error,omitempty"`
Expand Down Expand Up @@ -93,6 +94,7 @@ var inputKey = ast.StringTerm("input")
var resultKey = ast.StringTerm("result")
var mappedResultKey = ast.StringTerm("mapped_result")
var ndBuiltinCacheKey = ast.StringTerm("nd_builtin_cache")
var decisionLabelKey = ast.StringTerm("decision_label")
var erasedKey = ast.StringTerm("erased")
var maskedKey = ast.StringTerm("masked")
var errorKey = ast.StringTerm("error")
Expand Down Expand Up @@ -174,6 +176,14 @@ func (e *EventV1) AST() (ast.Value, error) {
event.Insert(ndBuiltinCacheKey, ast.NewTerm(ndbCache))
}

if e.DecisionLabel != nil {
decisionLabel, err := roundtripJSONToAST(e.DecisionLabel)
if err != nil {
return nil, err
}
event.Insert(decisionLabelKey, ast.NewTerm(decisionLabel))
}

if len(e.Erased) > 0 {
erased := make([]*ast.Term, len(e.Erased))
for i, v := range e.Erased {
Expand Down Expand Up @@ -609,6 +619,7 @@ func (p *Plugin) Log(ctx context.Context, decision *server.Info) error {
Result: decision.Results,
MappedResult: decision.MappedResults,
NDBuiltinCache: decision.NDBuiltinCache,
DecisionLabel: decision.DecisionLabel,
RequestedBy: decision.RemoteAddr,
Timestamp: decision.Timestamp,
RequestID: decision.RequestID,
Expand Down
23 changes: 23 additions & 0 deletions plugins/logs/plugin_test.go
Expand Up @@ -2502,6 +2502,10 @@ func TestEventV1ToAST(t *testing.T) {
}),
}.AsValue())

var decisionLabel interface{} = builtins.DecisionLabel{
"foo": "bar",
}

cases := []struct {
note string
event EventV1
Expand Down Expand Up @@ -2639,6 +2643,25 @@ func TestEventV1ToAST(t *testing.T) {
NDBuiltinCache: &ndbCacheExample,
},
},
{
note: "event with decision_label",
event: EventV1{
Labels: map[string]string{"foo": "1", "bar": "2"},
DecisionID: "1234567890",
Bundles: map[string]BundleInfoV1{
"b1": {"revision7"},
"b2": {"0"},
"b3": {},
},
Input: &goInput,
Path: "/http/authz/allow",
RequestedBy: "[::1]:59943",
Result: &result,
Timestamp: time.Now(),
inputAST: astInput,
DecisionLabel: &decisionLabel,
},
},
{
note: "event with req id",
event: EventV1{
Expand Down
13 changes: 12 additions & 1 deletion rego/rego.go
Expand Up @@ -118,6 +118,7 @@ type EvalContext struct {
earlyExit bool
interQueryBuiltinCache cache.InterQueryCache
ndBuiltinCache builtins.NDBCache
decisionLabel builtins.DecisionLabel
resolvers []refResolver
sortSets bool
copyMaps bool
Expand Down Expand Up @@ -382,6 +383,7 @@ func (pq preparedQuery) newEvalContext(ctx context.Context, options []EvalOption
printHook: pq.r.printHook,
capabilities: pq.r.capabilities,
strictBuiltinErrors: pq.r.strictBuiltinErrors,
decisionLabel: pq.r.decisionLabel,
}

for _, o := range options {
Expand Down Expand Up @@ -580,6 +582,7 @@ type Rego struct {
skipBundleVerification bool
interQueryBuiltinCache cache.InterQueryCache
ndBuiltinCache builtins.NDBCache
decisionLabel builtins.DecisionLabel
strictBuiltinErrors bool
builtinErrorList *[]topdown.Error
resolvers []refResolver
Expand Down Expand Up @@ -1112,6 +1115,13 @@ func NDBuiltinCache(c builtins.NDBCache) func(r *Rego) {
}
}

// DecisionLabel sets the Policy result data.
func DecisionLabel(dl builtins.DecisionLabel) func(r *Rego) {
return func(r *Rego) {
r.decisionLabel = dl
}
}

// StrictBuiltinErrors tells the evaluator to treat all built-in function errors as fatal errors.
func StrictBuiltinErrors(yes bool) func(r *Rego) {
return func(r *Rego) {
Expand Down Expand Up @@ -2085,7 +2095,8 @@ func (r *Rego) eval(ctx context.Context, ectx *EvalContext) (ResultSet, error) {
WithBuiltinErrorList(r.builtinErrorList).
WithSeed(ectx.seed).
WithPrintHook(ectx.printHook).
WithDistributedTracingOpts(r.distributedTacingOpts)
WithDistributedTracingOpts(r.distributedTacingOpts).
WithDecisionLabel(r.decisionLabel)

if !ectx.time.IsZero() {
q = q.WithTime(ectx.time)
Expand Down
15 changes: 15 additions & 0 deletions rego/rego_test.go
Expand Up @@ -2574,6 +2574,21 @@ func TestNDBCacheMarshalUnmarshalJSON(t *testing.T) {
}
}

func TestEvalWithDecisionLabel(t *testing.T) {

query := "decision.label.add(\"foo\", \"bar\")"

decisionLabel := builtins.DecisionLabel{"foo": "bar"}

ctx := context.Background()

_, err := New(Query(query), DecisionLabel(decisionLabel)).Eval(ctx)
if err != nil {
t.Fatal(err)
}

}

func TestStrictBuiltinErrors(t *testing.T) {
_, err := New(Query("1/0"), StrictBuiltinErrors(true)).Eval(context.Background())
if err == nil {
Expand Down
5 changes: 5 additions & 0 deletions sdk/opa.go
Expand Up @@ -261,6 +261,8 @@ func (opa *OPA) Decision(ctx context.Context, options DecisionOptions) (*Decisio
}
}

dl := builtins.DecisionLabel{}

result, err := opa.executeTransaction(
ctx,
&record,
Expand All @@ -273,6 +275,7 @@ func (opa *OPA) Decision(ctx context.Context, options DecisionOptions) (*Decisio
queryCache: s.queryCache,
interQueryCache: s.interQueryBuiltinCache,
ndbcache: ndbc,
decisionLabel: dl,
txn: record.Txn,
now: record.Timestamp,
path: record.Path,
Expand Down Expand Up @@ -506,6 +509,7 @@ type evalArgs struct {
path string
input interface{}
ndbcache builtins.NDBCache
decisionLabel builtins.DecisionLabel
m metrics.Metrics
strictBuiltinErrors bool
tracer topdown.QueryTracer
Expand Down Expand Up @@ -548,6 +552,7 @@ func evaluate(ctx context.Context, args evalArgs) (interface{}, types.Provenance
rego.PrintHook(args.printHook),
rego.StrictBuiltinErrors(args.strictBuiltinErrors),
rego.Instrument(args.instrument),
rego.DecisionLabel(args.decisionLabel),
rego.Runtime(args.runtime)).PrepareForEval(ctx)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions server/buffer.go
Expand Up @@ -30,6 +30,7 @@ type Info struct {
Results *interface{}
MappedResults *interface{}
NDBuiltinCache *interface{}
DecisionLabel *interface{}
Error error
Metrics metrics.Metrics
Trace []*topdown.Event
Expand Down
37 changes: 19 additions & 18 deletions topdown/builtins.go
Expand Up @@ -35,24 +35,25 @@ type (
// BuiltinContext contains context from the evaluator that may be used by
// built-in functions.
BuiltinContext struct {
Context context.Context // request context that was passed when query started
Metrics metrics.Metrics // metrics registry for recording built-in specific metrics
Seed io.Reader // randomization source
Time *ast.Term // wall clock time
Cancel Cancel // atomic value that signals evaluation to halt
Runtime *ast.Term // runtime information on the OPA instance
Cache builtins.Cache // built-in function state cache
InterQueryBuiltinCache cache.InterQueryCache // cross-query built-in function state cache
NDBuiltinCache builtins.NDBCache // cache for non-deterministic built-in state
Location *ast.Location // location of built-in call
Tracers []Tracer // Deprecated: Use QueryTracers instead
QueryTracers []QueryTracer // tracer objects for trace() built-in function
TraceEnabled bool // indicates whether tracing is enabled for the evaluation
QueryID uint64 // identifies query being evaluated
ParentID uint64 // identifies parent of query being evaluated
PrintHook print.Hook // provides callback function to use for printing
DistributedTracingOpts tracing.Options // options to be used by distributed tracing.
rand *rand.Rand // randomization source for non-security-sensitive operations
Context context.Context // request context that was passed when query started
Metrics metrics.Metrics // metrics registry for recording built-in specific metrics
Seed io.Reader // randomization source
Time *ast.Term // wall clock time
Cancel Cancel // atomic value that signals evaluation to halt
Runtime *ast.Term // runtime information on the OPA instance
Cache builtins.Cache // built-in function state cache
InterQueryBuiltinCache cache.InterQueryCache // cross-query built-in function state cache
NDBuiltinCache builtins.NDBCache // cache for non-deterministic built-in state
DecisionLabel builtins.DecisionLabel // map of non-deterministic Policy result data
Location *ast.Location // location of built-in call
Tracers []Tracer // Deprecated: Use QueryTracers instead
QueryTracers []QueryTracer // tracer objects for trace() built-in function
TraceEnabled bool // indicates whether tracing is enabled for the evaluation
QueryID uint64 // identifies query being evaluated
ParentID uint64 // identifies parent of query being evaluated
PrintHook print.Hook // provides callback function to use for printing
DistributedTracingOpts tracing.Options // options to be used by distributed tracing.
rand *rand.Rand // randomization source for non-security-sensitive operations
Capabilities *ast.Capabilities
}

Expand Down
14 changes: 14 additions & 0 deletions topdown/builtins/builtins.go
Expand Up @@ -109,6 +109,20 @@ func (c *NDBCache) UnmarshalJSON(data []byte) error {
return nil
}

// DecisionLabel contains the Policy result data. The expected
// inputs will be Strings, with the value representing a JSON
// message body.
type DecisionLabel map[ast.String]ast.String

func (dl DecisionLabel) Add(k ast.String, v ast.String) {
dl[k] = v
} // end Add function

func (dl DecisionLabel) Get(k ast.String) (ast.String, bool) {
v, ok := dl[k]
return v, ok
} // end Get function

// ErrOperand represents an invalid operand has been passed to a built-in
// function. Built-ins should return ErrOperand to indicate a type error has
// occurred.
Expand Down