1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/pkg/engine/jmespath/new.go

43 lines
1.1 KiB
Go
Raw Normal View History

package jmespath
import (
gojmespath "github.com/kyverno/go-jmespath"
"github.com/kyverno/kyverno/pkg/config"
)
type QueryProxy struct {
jmesPath *gojmespath.JMESPath
functionCaller *gojmespath.FunctionCaller
}
func (q *QueryProxy) Search(data interface{}) (interface{}, error) {
return q.jmesPath.Search(data, gojmespath.WithFunctionCaller(q.functionCaller))
}
func newJMESPath(query string, functionCaller *gojmespath.FunctionCaller) (*QueryProxy, error) {
jmesPath, err := gojmespath.Compile(query)
if err != nil {
return nil, err
}
return &QueryProxy{
jmesPath,
functionCaller,
}, nil
}
func newImplementation(configuration config.Configuration) Interface {
functionCaller := gojmespath.NewFunctionCaller()
functions := GetFunctions(configuration)
for _, f := range functions {
functionCaller.Register(f.FunctionEntry)
}
return implementation{
functionCaller,
}
}
func newExecution(fCall *gojmespath.FunctionCaller, query string, data interface{}) (interface{}, error) {
return gojmespath.Search(query, data, gojmespath.WithFunctionCaller(fCall))
}