mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-06 16:06:56 +00:00
* initial commit * variable substitution * update tests * update test * refactor engine packages for validate & generate * update vendor * update toml * support variable substitution in overlay mutation * missing update * fix indentation in logs * store context values as single JSON document using merge patches. * remove duplicate functions * fix message string * Handle processing of policies in background (#569) * remove condition check while generating mutation patch as conditions are verified in the first iteration * initial commit * background policy validation * correct message * skip non-background policy process for add/update * fix order to correct policy registration * update comment Co-authored-by: shuting <shutting06@gmail.com> * refactor Co-authored-by: shuting <shutting06@gmail.com>
35 lines
802 B
Go
35 lines
802 B
Go
package context
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/golang/glog"
|
|
"github.com/jmespath/go-jmespath"
|
|
)
|
|
|
|
//Query the JSON context with JMESPATH search path
|
|
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
|
|
ctx.mu.RLock()
|
|
defer ctx.mu.RUnlock()
|
|
|
|
var data interface{}
|
|
if err := json.Unmarshal(ctx.jsonRaw, &data); err != nil {
|
|
glog.V(4).Infof("failed to unmarshall context")
|
|
return emptyResult, err
|
|
}
|
|
|
|
result, err := queryPath.Search(data)
|
|
if err != nil {
|
|
glog.V(4).Infof("failed to search query %s: %v", query, err)
|
|
return emptyResult, err
|
|
}
|
|
return result, nil
|
|
}
|