forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
binary.go
43 lines (32 loc) · 927 Bytes
/
binary.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2017 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.
package topdown
import "github.com/open-policy-agent/opa/ast"
import "github.com/open-policy-agent/opa/topdown/builtins"
func builtinBinaryAnd(a ast.Value, b ast.Value) (ast.Value, error) {
s1, err := builtins.SetOperand(a, 1)
if err != nil {
return nil, err
}
s2, err := builtins.SetOperand(b, 2)
if err != nil {
return nil, err
}
return s1.Intersect(s2), nil
}
func builtinBinaryOr(a ast.Value, b ast.Value) (ast.Value, error) {
s1, err := builtins.SetOperand(a, 1)
if err != nil {
return nil, err
}
s2, err := builtins.SetOperand(b, 2)
if err != nil {
return nil, err
}
return s1.Union(s2), nil
}
func init() {
RegisterFunctionalBuiltin2(ast.And.Name, builtinBinaryAnd)
RegisterFunctionalBuiltin2(ast.Or.Name, builtinBinaryOr)
}