Update dependencies (#5518)

This commit is contained in:
hongming
2023-02-12 23:09:20 +08:00
committed by GitHub
parent d3b35fb2da
commit a979342f56
1486 changed files with 126660 additions and 71128 deletions

View File

@@ -119,6 +119,7 @@ type EvalContext struct {
ndBuiltinCache builtins.NDBCache
resolvers []refResolver
sortSets bool
copyMaps bool
printHook print.Hook
capabilities *ast.Capabilities
}
@@ -277,6 +278,13 @@ func EvalSortSets(yes bool) EvalOption {
}
}
// EvalCopyMaps causes the evaluator to copy `map[string]interface{}`s before returning them.
func EvalCopyMaps(yes bool) EvalOption {
return func(e *EvalContext) {
e.copyMaps = yes
}
}
// EvalPrintHook sets the object to use for handling print statement outputs.
func EvalPrintHook(ph print.Hook) EvalOption {
return func(e *EvalContext) {
@@ -520,6 +528,7 @@ type Rego struct {
interQueryBuiltinCache cache.InterQueryCache
ndBuiltinCache builtins.NDBCache
strictBuiltinErrors bool
builtinErrorList *[]topdown.Error
resolvers []refResolver
schemaSet *ast.SchemaSet
target string // target type (wasm, rego, etc.)
@@ -528,6 +537,7 @@ type Rego struct {
printHook print.Hook
enablePrintStatements bool
distributedTacingOpts tracing.Options
strict bool
}
// Function represents a built-in function that is callable in Rego.
@@ -1046,6 +1056,13 @@ func StrictBuiltinErrors(yes bool) func(r *Rego) {
}
}
// BuiltinErrorList supplies an error slice to store built-in function errors.
func BuiltinErrorList(list *[]topdown.Error) func(r *Rego) {
return func(r *Rego) {
r.builtinErrorList = list
}
}
// Resolver sets a Resolver for a specified ref path.
func Resolver(ref ast.Ref, r resolver.Resolver) func(r *Rego) {
return func(rego *Rego) {
@@ -1107,6 +1124,13 @@ func EnablePrintStatements(yes bool) func(r *Rego) {
}
}
// Strict enables or disables strict-mode in the compiler
func Strict(yes bool) func(r *Rego) {
return func(r *Rego) {
r.strict = yes
}
}
// New returns a new Rego object.
func New(options ...func(r *Rego)) *Rego {
@@ -1130,7 +1154,9 @@ func New(options ...func(r *Rego)) *Rego {
WithDebug(r.dump).
WithSchemas(r.schemaSet).
WithCapabilities(r.capabilities).
WithEnablePrintStatements(r.enablePrintStatements)
WithEnablePrintStatements(r.enablePrintStatements).
WithStrict(r.strict).
WithUseTypeCheckAnnotations(r.schemaSet != nil)
}
if r.store == nil {
@@ -1311,7 +1337,7 @@ func (r *Rego) Compile(ctx context.Context, opts ...CompileOption) (*CompileResu
}
var queries []ast.Body
var modules []*ast.Module
modules := make([]*ast.Module, 0, len(r.compiler.Modules))
if cfg.partial {
@@ -1663,7 +1689,14 @@ func (r *Rego) prepare(ctx context.Context, qType queryType, extras []extraStage
}
func (r *Rego) parseModules(ctx context.Context, txn storage.Transaction, m metrics.Metrics) error {
if len(r.modules) == 0 {
ids, err := r.store.ListPolicies(ctx, txn)
if err != nil {
return err
}
// if there are no raw modules, nor modules in the store, then there
// is nothing to do.
if len(r.modules) == 0 && len(ids) == 0 {
return nil
}
@@ -1674,11 +1707,6 @@ func (r *Rego) parseModules(ctx context.Context, txn storage.Transaction, m metr
// Parse any modules in the are saved to the store, but only if
// another compile step is going to occur (ie. we have parsed modules
// that need to be compiled).
ids, err := r.store.ListPolicies(ctx, txn)
if err != nil {
return err
}
for _, id := range ids {
// if it is already on the compiler we're using
// then don't bother to re-parse it from source
@@ -1910,7 +1938,8 @@ func (r *Rego) compileQuery(query ast.Body, imports []*ast.Import, m metrics.Met
qc := r.compiler.QueryCompiler().
WithContext(qctx).
WithUnsafeBuiltins(r.unsafeBuiltins).
WithEnablePrintStatements(r.enablePrintStatements)
WithEnablePrintStatements(r.enablePrintStatements).
WithStrict(false)
for _, extra := range extras {
qc = qc.WithStageAfter(extra.after, extra.stage)
@@ -1940,6 +1969,7 @@ func (r *Rego) eval(ctx context.Context, ectx *EvalContext) (ResultSet, error) {
WithEarlyExit(ectx.earlyExit).
WithInterQueryBuiltinCache(ectx.interQueryBuiltinCache).
WithStrictBuiltinErrors(r.strictBuiltinErrors).
WithBuiltinErrorList(r.builtinErrorList).
WithSeed(ectx.seed).
WithPrintHook(ectx.printHook).
WithDistributedTracingOpts(r.distributedTacingOpts)
@@ -2574,5 +2604,9 @@ func newFunction(decl *Function, f topdown.BuiltinFunc) func(*Rego) {
}
func generateJSON(term *ast.Term, ectx *EvalContext) (interface{}, error) {
return ast.JSONWithOpt(term.Value, ast.JSONOpt{SortSets: ectx.sortSets})
return ast.JSONWithOpt(term.Value,
ast.JSONOpt{
SortSets: ectx.sortSets,
CopyMaps: ectx.copyMaps,
})
}