Upgrade dependent version: github.com/open-policy-agent/opa (#5315)
Upgrade dependent version: github.com/open-policy-agent/opa v0.18.0 -> v0.45.0 Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io>
This commit is contained in:
58
vendor/github.com/open-policy-agent/opa/topdown/walk.go
generated
vendored
58
vendor/github.com/open-policy-agent/opa/topdown/walk.go
generated
vendored
@@ -8,57 +8,61 @@ import (
|
||||
"github.com/open-policy-agent/opa/ast"
|
||||
)
|
||||
|
||||
func evalWalk(bctx BuiltinContext, args []*ast.Term, iter func(*ast.Term) error) error {
|
||||
func evalWalk(_ BuiltinContext, args []*ast.Term, iter func(*ast.Term) error) error {
|
||||
input := args[0]
|
||||
filter := getOutputPath(args)
|
||||
var path ast.Array
|
||||
return walk(filter, path, input, iter)
|
||||
return walk(filter, nil, input, iter)
|
||||
}
|
||||
|
||||
func walk(filter, path ast.Array, input *ast.Term, iter func(*ast.Term) error) error {
|
||||
func walk(filter, path *ast.Array, input *ast.Term, iter func(*ast.Term) error) error {
|
||||
|
||||
if len(filter) == 0 {
|
||||
if err := iter(ast.ArrayTerm(ast.NewTerm(path), input)); err != nil {
|
||||
if filter == nil || filter.Len() == 0 {
|
||||
if path == nil {
|
||||
path = ast.NewArray()
|
||||
}
|
||||
|
||||
if err := iter(ast.ArrayTerm(ast.NewTerm(path.Copy()), input)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if len(filter) > 0 {
|
||||
key := filter[0]
|
||||
filter = filter[1:]
|
||||
if filter != nil && filter.Len() > 0 {
|
||||
key := filter.Elem(0)
|
||||
filter = filter.Slice(1, -1)
|
||||
if key.IsGround() {
|
||||
if term := input.Get(key); term != nil {
|
||||
return walk(filter, append(path, key), term, iter)
|
||||
path = pathAppend(path, key)
|
||||
return walk(filter, path, term, iter)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
switch v := input.Value.(type) {
|
||||
case ast.Array:
|
||||
for i := range v {
|
||||
path = append(path, ast.IntNumberTerm(i))
|
||||
if err := walk(filter, path, v[i], iter); err != nil {
|
||||
case *ast.Array:
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
path = pathAppend(path, ast.IntNumberTerm(i))
|
||||
if err := walk(filter, path, v.Elem(i), iter); err != nil {
|
||||
return err
|
||||
}
|
||||
path = path[:len(path)-1]
|
||||
path = path.Slice(0, path.Len()-1)
|
||||
}
|
||||
case ast.Object:
|
||||
return v.Iter(func(k, v *ast.Term) error {
|
||||
path = append(path, k)
|
||||
path = pathAppend(path, k)
|
||||
if err := walk(filter, path, v, iter); err != nil {
|
||||
return err
|
||||
}
|
||||
path = path[:len(path)-1]
|
||||
path = path.Slice(0, path.Len()-1)
|
||||
return nil
|
||||
})
|
||||
case ast.Set:
|
||||
return v.Iter(func(elem *ast.Term) error {
|
||||
path = append(path, elem)
|
||||
path = pathAppend(path, elem)
|
||||
if err := walk(filter, path, elem, iter); err != nil {
|
||||
return err
|
||||
}
|
||||
path = path[:len(path)-1]
|
||||
path = path.Slice(0, path.Len()-1)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -66,11 +70,19 @@ func walk(filter, path ast.Array, input *ast.Term, iter func(*ast.Term) error) e
|
||||
return nil
|
||||
}
|
||||
|
||||
func getOutputPath(args []*ast.Term) ast.Array {
|
||||
func pathAppend(path *ast.Array, key *ast.Term) *ast.Array {
|
||||
if path == nil {
|
||||
return ast.NewArray(key)
|
||||
}
|
||||
|
||||
return path.Append(key)
|
||||
}
|
||||
|
||||
func getOutputPath(args []*ast.Term) *ast.Array {
|
||||
if len(args) == 2 {
|
||||
if arr, ok := args[1].Value.(ast.Array); ok {
|
||||
if len(arr) == 2 {
|
||||
if path, ok := arr[0].Value.(ast.Array); ok {
|
||||
if arr, ok := args[1].Value.(*ast.Array); ok {
|
||||
if arr.Len() == 2 {
|
||||
if path, ok := arr.Elem(0).Value.(*ast.Array); ok {
|
||||
return path
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user