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:
hongzhouzi
2022-10-31 10:58:55 +08:00
committed by GitHub
parent 668fca1773
commit ef03b1e3df
363 changed files with 277341 additions and 13544 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -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
}

View File

@@ -6,7 +6,7 @@ package planner
import (
"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/internal/ir"
"github.com/open-policy-agent/opa/ir"
)
type varstack []map[ast.Var]ir.Local
@@ -42,6 +42,19 @@ func (vs varstack) Get(k ast.Var) (ir.Local, bool) {
return 0, false
}
func (vs varstack) GetOpOrEmpty(k ast.Var) ir.Operand {
l := vs.GetOrEmpty(k)
return ir.Operand{Value: l}
}
func (vs varstack) GetOp(k ast.Var) (ir.Operand, bool) {
l, ok := vs.Get(k)
if !ok {
return ir.Operand{}, false
}
return ir.Operand{Value: l}, true
}
func (vs varstack) Put(k ast.Var, v ir.Local) {
vs[len(vs)-1][k] = v
}