-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.go
89 lines (78 loc) · 2.06 KB
/
options.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package runtime
import (
"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/plugins"
"github.com/open-policy-agent/opa/rego"
"github.com/open-policy-agent/opa/storage"
)
type Option func(*Runtime)
func WithPlugin(name string, factory plugins.Factory) Option {
return func(r *Runtime) {
r.plugins[name] = factory
}
}
func WithBuiltin1(decl *rego.Function, impl rego.Builtin1) Option {
return func(r *Runtime) {
r.builtins1[decl] = impl
r.builtins = append(r.builtins, rego.Function1(decl, impl))
r.compilerBuiltins[decl.Name] = &ast.Builtin{
Name: decl.Name,
Decl: decl.Decl,
}
}
}
func WithBuiltin2(decl *rego.Function, impl rego.Builtin2) Option {
return func(r *Runtime) {
r.builtins2[decl] = impl
r.builtins = append(r.builtins, rego.Function2(decl, impl))
r.compilerBuiltins[decl.Name] = &ast.Builtin{
Name: decl.Name,
Decl: decl.Decl,
}
}
}
func WithBuiltin3(decl *rego.Function, impl rego.Builtin3) Option {
return func(r *Runtime) {
r.builtins3[decl] = impl
r.builtins = append(r.builtins, rego.Function3(decl, impl))
r.compilerBuiltins[decl.Name] = &ast.Builtin{
Name: decl.Name,
Decl: decl.Decl,
}
}
}
func WithBuiltin4(decl *rego.Function, impl rego.Builtin4) Option {
return func(r *Runtime) {
r.builtins4[decl] = impl
r.builtins = append(r.builtins, rego.Function4(decl, impl))
r.compilerBuiltins[decl.Name] = &ast.Builtin{
Name: decl.Name,
Decl: decl.Decl,
}
}
}
func WithBuiltinDyn(decl *rego.Function, impl rego.BuiltinDyn) Option {
return func(r *Runtime) {
r.builtinsDyn[decl] = impl
r.builtins = append(r.builtins, rego.FunctionDyn(decl, impl))
r.compilerBuiltins[decl.Name] = &ast.Builtin{
Name: decl.Name,
Decl: decl.Decl,
}
}
}
func WithStorage(storageInterface storage.Store) Option {
return func(r *Runtime) {
r.storage = storageInterface
}
}
func WithImport(imp string) Option {
return func(r *Runtime) {
r.imports = append(r.imports, imp)
}
}
func WithImports(imp []string) Option {
return func(r *Runtime) {
r.imports = append(r.imports, imp...)
}
}