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
Jim Bugwadia 296578a456
create interpreter once and reuse across searches (#8299)
* create interpreter once and reuse across searches

Signed-off-by: Jim Bugwadia <jim@nirmata.com>

* fix excessive logs

Signed-off-by: Jim Bugwadia <jim@nirmata.com>

* refactor(jmespath): reuse fCall instead of intr

Signed-off-by: Khaled Emara <khaled.emara@nirmata.com>

* refactor(jmespath): use new api

Use the new JMESPath API to decouple Interpreter from FunctionCaller

Signed-off-by: Khaled Emara <khaled.emara@nirmata.com>

* chore: bump go-jmespath

Signed-off-by: Khaled Emara <khaled.emara@nirmata.com>

* fix(jmespath): test case using older API

Signed-off-by: Khaled Emara <khaled.emara@nirmata.com>

---------

Signed-off-by: Jim Bugwadia <jim@nirmata.com>
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
Signed-off-by: Khaled Emara <khaled.emara@nirmata.com>
Co-authored-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
Co-authored-by: shuting <shuting@nirmata.com>
Co-authored-by: Khaled Emara <khaled.emara@nirmata.com>
Co-authored-by: Khaled Emara <KhaledEmaraDev@gmail.com>
2023-11-30 16:59:11 +01:00

42 lines
1.1 KiB
Go

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))
}