1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00
kyverno/pkg/engine/context/evaluate.go

26 lines
582 B
Go
Raw Normal View History

2019-12-11 09:45:22 -08:00
package context
import (
"github.com/golang/glog"
"github.com/jmespath/go-jmespath"
2019-12-11 09:45:22 -08:00
)
//Query searches for query in the context
func (ctx *Context) Query(query string) (interface{}, error) {
var emptyResult interface{}
// compile the query
queryPath, err := jmespath.Compile(query)
if err != nil {
glog.V(4).Infof("incorrect query %s: %v", query, err)
return emptyResult, err
}
// search
result, err := queryPath.Search(ctx.getData())
if err != nil {
glog.V(4).Infof("failed to search query %s: %v", query, err)
return emptyResult, err
}
return result, nil
}