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:
88
vendor/github.com/open-policy-agent/opa/topdown/input.go
generated
vendored
88
vendor/github.com/open-policy-agent/opa/topdown/input.go
generated
vendored
@@ -10,18 +10,14 @@ import (
|
||||
"github.com/open-policy-agent/opa/ast"
|
||||
)
|
||||
|
||||
var errConflictingDoc = fmt.Errorf("conflicting documents")
|
||||
var errBadPath = fmt.Errorf("bad document path")
|
||||
|
||||
func mergeTermWithValues(exist *ast.Term, pairs [][2]*ast.Term) (*ast.Term, error) {
|
||||
|
||||
var result *ast.Term
|
||||
var init bool
|
||||
|
||||
if exist != nil {
|
||||
result = exist.Copy()
|
||||
}
|
||||
|
||||
for _, pair := range pairs {
|
||||
for i, pair := range pairs {
|
||||
|
||||
if err := ast.IsValidImportPath(pair[0].Value); err != nil {
|
||||
return nil, errBadPath
|
||||
@@ -29,33 +25,55 @@ func mergeTermWithValues(exist *ast.Term, pairs [][2]*ast.Term) (*ast.Term, erro
|
||||
|
||||
target := pair[0].Value.(ast.Ref)
|
||||
|
||||
if len(target) == 1 {
|
||||
result = pair[1]
|
||||
} else if result == nil {
|
||||
result = ast.NewTerm(makeTree(target[1:], pair[1]))
|
||||
} else {
|
||||
node := result
|
||||
done := false
|
||||
for i := 1; i < len(target)-1 && !done; i++ {
|
||||
if child := node.Get(target[i]); child == nil {
|
||||
obj, ok := node.Value.(ast.Object)
|
||||
if !ok {
|
||||
return nil, errConflictingDoc
|
||||
}
|
||||
obj.Insert(target[i], ast.NewTerm(makeTree(target[i+1:], pair[1])))
|
||||
done = true
|
||||
} else {
|
||||
node = child
|
||||
}
|
||||
}
|
||||
if !done {
|
||||
obj, ok := node.Value.(ast.Object)
|
||||
if !ok {
|
||||
return nil, errConflictingDoc
|
||||
}
|
||||
obj.Insert(target[len(target)-1], pair[1])
|
||||
// Copy the value if subsequent pairs in the slice would modify it.
|
||||
for j := i + 1; j < len(pairs); j++ {
|
||||
other := pairs[j][0].Value.(ast.Ref)
|
||||
if len(other) > len(target) && other.HasPrefix(target) {
|
||||
pair[1] = pair[1].Copy()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if len(target) == 1 {
|
||||
result = pair[1]
|
||||
init = true
|
||||
} else {
|
||||
if !init {
|
||||
result = exist.Copy()
|
||||
init = true
|
||||
}
|
||||
if result == nil {
|
||||
result = ast.NewTerm(makeTree(target[1:], pair[1]))
|
||||
} else {
|
||||
node := result
|
||||
done := false
|
||||
for i := 1; i < len(target)-1 && !done; i++ {
|
||||
obj, ok := node.Value.(ast.Object)
|
||||
if !ok {
|
||||
result = ast.NewTerm(makeTree(target[i:], pair[1]))
|
||||
done = true
|
||||
continue
|
||||
}
|
||||
if child := obj.Get(target[i]); !isObject(child) {
|
||||
obj.Insert(target[i], ast.NewTerm(makeTree(target[i+1:], pair[1])))
|
||||
done = true
|
||||
} else { // child is object
|
||||
node = child
|
||||
}
|
||||
}
|
||||
if !done {
|
||||
if obj, ok := node.Value.(ast.Object); ok {
|
||||
obj.Insert(target[len(target)-1], pair[1])
|
||||
} else {
|
||||
result = ast.NewTerm(makeTree(target[len(target)-1:], pair[1]))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !init {
|
||||
result = exist
|
||||
}
|
||||
|
||||
return result, nil
|
||||
@@ -72,3 +90,11 @@ func makeTree(k ast.Ref, v *ast.Term) ast.Object {
|
||||
obj = ast.NewObject(ast.Item(k[0], v))
|
||||
return obj
|
||||
}
|
||||
|
||||
func isObject(x *ast.Term) bool {
|
||||
if x == nil {
|
||||
return false
|
||||
}
|
||||
_, ok := x.Value.(ast.Object)
|
||||
return ok
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user