-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathrego_builtins.go
44 lines (35 loc) · 1006 Bytes
/
rego_builtins.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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package checks
import (
"errors"
"strconv"
_ "embed"
"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/rego"
"github.com/open-policy-agent/opa/types"
)
//go:embed rego_helpers/datadog.rego
var helpers string
var regoBuiltins = []func(*rego.Rego){
octalLiteralFunc,
}
var octalLiteralFunc = rego.Function1(
®o.Function{
Name: "parse_octal",
Decl: types.NewFunction(types.Args(types.S), types.N),
},
func(_ rego.BuiltinContext, a *ast.Term) (*ast.Term, error) {
str, ok := a.Value.(ast.String)
if !ok {
return nil, errors.New("failed to parse octal literal")
}
value, err := strconv.ParseInt(string(str), 8, 0)
if err != nil {
return nil, err
}
return ast.IntNumberTerm(int(value)), err
},
)