2021-04-16 23:17:00 +00:00
|
|
|
package jmespath
|
|
|
|
|
|
|
|
import (
|
2023-07-07 10:22:26 +00:00
|
|
|
gojmespath "github.com/kyverno/go-jmespath"
|
2023-04-13 16:13:40 +00:00
|
|
|
"github.com/kyverno/kyverno/pkg/config"
|
2021-04-16 23:17:00 +00:00
|
|
|
)
|
|
|
|
|
2023-11-30 15:59:11 +00:00
|
|
|
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)
|
2021-04-16 23:17:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-11-30 15:59:11 +00:00
|
|
|
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,
|
2021-04-16 23:17:00 +00:00
|
|
|
}
|
2023-11-30 15:59:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newExecution(fCall *gojmespath.FunctionCaller, query string, data interface{}) (interface{}, error) {
|
|
|
|
return gojmespath.Search(query, data, gojmespath.WithFunctionCaller(fCall))
|
2021-04-16 23:17:00 +00:00
|
|
|
}
|