2023-04-13 13:29:40 +02:00
|
|
|
package jmespath
|
|
|
|
|
2023-11-30 07:59:11 -08:00
|
|
|
import (
|
|
|
|
gojmespath "github.com/kyverno/go-jmespath"
|
|
|
|
"github.com/kyverno/kyverno/pkg/config"
|
|
|
|
)
|
2023-04-13 13:29:40 +02:00
|
|
|
|
|
|
|
type Query interface {
|
|
|
|
Search(interface{}) (interface{}, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Interface interface {
|
|
|
|
Query(string) (Query, error)
|
|
|
|
Search(string, interface{}) (interface{}, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type implementation struct {
|
2023-11-30 07:59:11 -08:00
|
|
|
functionCaller *gojmespath.FunctionCaller
|
2023-04-13 13:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func New(configuration config.Configuration) Interface {
|
2023-11-30 07:59:11 -08:00
|
|
|
return newImplementation(configuration)
|
2023-04-13 13:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (i implementation) Query(query string) (Query, error) {
|
2023-11-30 07:59:11 -08:00
|
|
|
return newJMESPath(query, i.functionCaller)
|
2023-04-13 13:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (i implementation) Search(query string, data interface{}) (interface{}, error) {
|
2023-11-30 07:59:11 -08:00
|
|
|
return newExecution(i.functionCaller, query, data)
|
2023-04-13 13:29:40 +02:00
|
|
|
}
|