-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
46 lines (36 loc) · 1.2 KB
/
main.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
44
45
46
package main
// THis code built based on: https://www.openpolicyagent.org/docs/latest/extensions/
import (
"fmt"
"os"
"github.com/hexa-org/policy-opa/server/conditionEvaluator"
"github.com/hexa-org/policy-opa/server/hexaFilter"
"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/cmd"
"github.com/open-policy-agent/opa/rego"
"github.com/open-policy-agent/opa/types"
)
func main() {
fmt.Println("Hexa extended OPA Server")
fmt.Println(" registering plugin " + hexaFilter.PluginName)
rego.RegisterBuiltin2(
®o.Function{
Name: hexaFilter.PluginName,
Decl: types.NewFunction(types.Args(types.A, types.S), types.S),
Memoize: false, // function may get called several times in same query for different expressions
Nondeterministic: true,
},
func(_ rego.BuiltinContext, a, b *ast.Term) (*ast.Term, error) {
var expression, input string
if err := ast.As(a.Value, &expression); err != nil {
return nil, err
}
input = b.Value.String()
res, err := conditionEvaluator.Evaluate(expression, input)
return ast.BooleanTerm(res), err
})
if err := cmd.RootCommand.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}