1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00
kyverno/pkg/cel/env.go

35 lines
679 B
Go
Raw Normal View History

package cel
import (
"github.com/google/cel-go/cel"
"github.com/google/cel-go/ext"
"k8s.io/apiserver/pkg/cel/library"
)
func NewEnv() (*cel.Env, error) {
// create new cel env
return cel.NewEnv(
// configure env
cel.HomogeneousAggregateLiterals(),
cel.EagerlyValidateDeclarations(true),
cel.DefaultUTCTimeZone(true),
cel.CrossTypeNumericComparisons(true),
// register common libs
cel.OptionalTypes(),
ext.Bindings(),
ext.Encoders(),
ext.Lists(),
ext.Math(),
ext.Protos(),
ext.Sets(),
ext.Strings(),
// register kubernetes libs
library.CIDR(),
library.Format(),
library.IP(),
library.Lists(),
library.Regex(),
library.URLs(),
)
}