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:
84
vendor/github.com/open-policy-agent/opa/internal/planner/rules.go
generated
vendored
84
vendor/github.com/open-policy-agent/opa/internal/planner/rules.go
generated
vendored
@@ -10,39 +10,51 @@ import (
|
||||
// document => planned function names. The structure supports Push and Pop
|
||||
// operations so that the planner can shadow planned functions when 'with'
|
||||
// statements are found.
|
||||
// The "gen" numbers indicate the "generations"; whenever a 'with' statement
|
||||
// is planned (a new map is `Push()`ed), it will jump to a previously unused
|
||||
// number.
|
||||
type funcstack struct {
|
||||
stack []map[string]string
|
||||
stack []taggedPairs
|
||||
next int
|
||||
}
|
||||
|
||||
type taggedPairs struct {
|
||||
pairs map[string]string
|
||||
gen int
|
||||
}
|
||||
|
||||
func newFuncstack() *funcstack {
|
||||
return &funcstack{
|
||||
stack: []map[string]string{
|
||||
map[string]string{},
|
||||
},
|
||||
gen: 0,
|
||||
}
|
||||
stack: []taggedPairs{{pairs: map[string]string{}, gen: 0}},
|
||||
next: 1}
|
||||
}
|
||||
|
||||
func (p funcstack) last() taggedPairs {
|
||||
return p.stack[len(p.stack)-1]
|
||||
}
|
||||
|
||||
func (p funcstack) Add(key, value string) {
|
||||
p.stack[len(p.stack)-1][key] = value
|
||||
p.last().pairs[key] = value
|
||||
}
|
||||
|
||||
func (p funcstack) Get(key string) (string, bool) {
|
||||
value, ok := p.stack[len(p.stack)-1][key]
|
||||
value, ok := p.last().pairs[key]
|
||||
return value, ok
|
||||
}
|
||||
|
||||
func (p *funcstack) Push(funcs map[string]string) {
|
||||
p.stack = append(p.stack, funcs)
|
||||
p.gen++
|
||||
p.stack = append(p.stack, taggedPairs{pairs: funcs, gen: p.next})
|
||||
p.next++
|
||||
}
|
||||
|
||||
func (p *funcstack) Pop() map[string]string {
|
||||
last := p.stack[len(p.stack)-1]
|
||||
last := p.last()
|
||||
p.stack = p.stack[:len(p.stack)-1]
|
||||
p.gen++
|
||||
return last
|
||||
return last.pairs
|
||||
}
|
||||
|
||||
func (p funcstack) gen() int {
|
||||
return p.last().gen
|
||||
}
|
||||
|
||||
// ruletrie implements a simple trie structure for organizing rules that may be
|
||||
@@ -154,3 +166,49 @@ func (t *ruletrie) Get(k ast.Value) *ruletrie {
|
||||
}
|
||||
return nodes[len(nodes)-1]
|
||||
}
|
||||
|
||||
type functionMocksStack struct {
|
||||
stack []*functionMocksElem
|
||||
}
|
||||
|
||||
type functionMocksElem []frame
|
||||
|
||||
type frame map[string]*ast.Term
|
||||
|
||||
func newFunctionMocksStack() *functionMocksStack {
|
||||
stack := &functionMocksStack{}
|
||||
stack.Push()
|
||||
return stack
|
||||
}
|
||||
|
||||
func newFunctionMocksElem() *functionMocksElem {
|
||||
return &functionMocksElem{}
|
||||
}
|
||||
|
||||
func (s *functionMocksStack) Push() {
|
||||
s.stack = append(s.stack, newFunctionMocksElem())
|
||||
}
|
||||
|
||||
func (s *functionMocksStack) Pop() {
|
||||
s.stack = s.stack[:len(s.stack)-1]
|
||||
}
|
||||
|
||||
func (s *functionMocksStack) PushFrame(f frame) {
|
||||
current := s.stack[len(s.stack)-1]
|
||||
*current = append(*current, f)
|
||||
}
|
||||
|
||||
func (s *functionMocksStack) PopFrame() {
|
||||
current := s.stack[len(s.stack)-1]
|
||||
*current = (*current)[:len(*current)-1]
|
||||
}
|
||||
|
||||
func (s *functionMocksStack) Lookup(f string) *ast.Term {
|
||||
current := *s.stack[len(s.stack)-1]
|
||||
for i := len(current) - 1; i >= 0; i-- {
|
||||
if t, ok := current[i][f]; ok {
|
||||
return t
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user