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/interface.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

31 lines
719 B
Go

package jmespath
import (
gojmespath "github.com/kyverno/go-jmespath"
"github.com/kyverno/kyverno/pkg/config"
)
type Query interface {
Search(interface{}) (interface{}, error)
}
type Interface interface {
Query(string) (Query, error)
Search(string, interface{}) (interface{}, error)
}
type implementation struct {
functionCaller *gojmespath.FunctionCaller
}
func New(configuration config.Configuration) Interface {
return newImplementation(configuration)
}
func (i implementation) Query(query string) (Query, error) {
return newJMESPath(query, i.functionCaller)
}
func (i implementation) Search(query string, data interface{}) (interface{}, error) {
return newExecution(i.functionCaller, query, data)
}