forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype.go
82 lines (72 loc) · 1.84 KB
/
type.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
// Copyright 2022 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"
)
func builtinIsNumber(a ast.Value) (ast.Value, error) {
switch a.(type) {
case ast.Number:
return ast.Boolean(true), nil
default:
return ast.Boolean(false), nil
}
}
func builtinIsString(a ast.Value) (ast.Value, error) {
switch a.(type) {
case ast.String:
return ast.Boolean(true), nil
default:
return ast.Boolean(false), nil
}
}
func builtinIsBoolean(a ast.Value) (ast.Value, error) {
switch a.(type) {
case ast.Boolean:
return ast.Boolean(true), nil
default:
return ast.Boolean(false), nil
}
}
func builtinIsArray(a ast.Value) (ast.Value, error) {
switch a.(type) {
case *ast.Array:
return ast.Boolean(true), nil
default:
return ast.Boolean(false), nil
}
}
func builtinIsSet(a ast.Value) (ast.Value, error) {
switch a.(type) {
case ast.Set:
return ast.Boolean(true), nil
default:
return ast.Boolean(false), nil
}
}
func builtinIsObject(a ast.Value) (ast.Value, error) {
switch a.(type) {
case ast.Object:
return ast.Boolean(true), nil
default:
return ast.Boolean(false), nil
}
}
func builtinIsNull(a ast.Value) (ast.Value, error) {
switch a.(type) {
case ast.Null:
return ast.Boolean(true), nil
default:
return ast.Boolean(false), nil
}
}
func init() {
RegisterFunctionalBuiltin1(ast.IsNumber.Name, builtinIsNumber)
RegisterFunctionalBuiltin1(ast.IsString.Name, builtinIsString)
RegisterFunctionalBuiltin1(ast.IsBoolean.Name, builtinIsBoolean)
RegisterFunctionalBuiltin1(ast.IsArray.Name, builtinIsArray)
RegisterFunctionalBuiltin1(ast.IsSet.Name, builtinIsSet)
RegisterFunctionalBuiltin1(ast.IsObject.Name, builtinIsObject)
RegisterFunctionalBuiltin1(ast.IsNull.Name, builtinIsNull)
}