Update dependencies (#5518)
This commit is contained in:
63
vendor/github.com/open-policy-agent/opa/topdown/query.go
generated
vendored
63
vendor/github.com/open-policy-agent/opa/topdown/query.go
generated
vendored
@@ -54,6 +54,8 @@ type Query struct {
|
||||
interQueryBuiltinCache cache.InterQueryCache
|
||||
ndBuiltinCache builtins.NDBCache
|
||||
strictBuiltinErrors bool
|
||||
builtinErrorList *[]Error
|
||||
strictObjects bool
|
||||
printHook print.Hook
|
||||
tracingOpts tracing.Options
|
||||
}
|
||||
@@ -255,6 +257,14 @@ func (q *Query) WithStrictBuiltinErrors(yes bool) *Query {
|
||||
return q
|
||||
}
|
||||
|
||||
// WithBuiltinErrorList supplies a pointer to an Error slice to store built-in function errors
|
||||
// encountered during evaluation. This error slice can be inspected after evaluation to determine
|
||||
// which built-in function errors occurred.
|
||||
func (q *Query) WithBuiltinErrorList(list *[]Error) *Query {
|
||||
q.builtinErrorList = list
|
||||
return q
|
||||
}
|
||||
|
||||
// WithResolver configures an external resolver to use for the given ref.
|
||||
func (q *Query) WithResolver(ref ast.Ref, r resolver.Resolver) *Query {
|
||||
q.external.Put(ref, r)
|
||||
@@ -272,6 +282,15 @@ func (q *Query) WithDistributedTracingOpts(tr tracing.Options) *Query {
|
||||
return q
|
||||
}
|
||||
|
||||
// WithStrictObjects tells the evaluator to avoid the "lazy object" optimization
|
||||
// applied when reading objects from the store. It will result in higher memory
|
||||
// usage and should only be used temporarily while adjusting code that breaks
|
||||
// because of the optimization.
|
||||
func (q *Query) WithStrictObjects(yes bool) *Query {
|
||||
q.strictObjects = yes
|
||||
return q
|
||||
}
|
||||
|
||||
// PartialRun executes partial evaluation on the query with respect to unknown
|
||||
// values. Partial evaluation attempts to evaluate as much of the query as
|
||||
// possible without requiring values for the unknowns set on the query. The
|
||||
@@ -337,6 +356,7 @@ func (q *Query) PartialRun(ctx context.Context) (partials []ast.Body, support []
|
||||
earlyExit: q.earlyExit,
|
||||
builtinErrors: &builtinErrors{},
|
||||
printHook: q.printHook,
|
||||
strictObjects: q.strictObjects,
|
||||
}
|
||||
|
||||
if len(q.disableInlining) > 0 {
|
||||
@@ -408,8 +428,25 @@ func (q *Query) PartialRun(ctx context.Context) (partials []ast.Body, support []
|
||||
|
||||
support = e.saveSupport.List()
|
||||
|
||||
if q.strictBuiltinErrors && len(e.builtinErrors.errs) > 0 {
|
||||
err = e.builtinErrors.errs[0]
|
||||
if len(e.builtinErrors.errs) > 0 {
|
||||
if q.strictBuiltinErrors {
|
||||
err = e.builtinErrors.errs[0]
|
||||
} else if q.builtinErrorList != nil {
|
||||
// If a builtinErrorList has been supplied, we must use pointer indirection
|
||||
// to append to it. builtinErrorList is a slice pointer so that errors can be
|
||||
// appended to it without returning a new slice and changing the interface
|
||||
// of PartialRun.
|
||||
for _, err := range e.builtinErrors.errs {
|
||||
if tdError, ok := err.(*Error); ok {
|
||||
*(q.builtinErrorList) = append(*(q.builtinErrorList), *tdError)
|
||||
} else {
|
||||
*(q.builtinErrorList) = append(*(q.builtinErrorList), Error{
|
||||
Code: BuiltinErr,
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for i := range support {
|
||||
@@ -480,6 +517,7 @@ func (q *Query) Iter(ctx context.Context, iter func(QueryResult) error) error {
|
||||
builtinErrors: &builtinErrors{},
|
||||
printHook: q.printHook,
|
||||
tracingOpts: q.tracingOpts,
|
||||
strictObjects: q.strictObjects,
|
||||
}
|
||||
e.caller = e
|
||||
q.metrics.Timer(metrics.RegoQueryEval).Start()
|
||||
@@ -492,8 +530,25 @@ func (q *Query) Iter(ctx context.Context, iter func(QueryResult) error) error {
|
||||
return iter(qr)
|
||||
})
|
||||
|
||||
if q.strictBuiltinErrors && err == nil && len(e.builtinErrors.errs) > 0 {
|
||||
err = e.builtinErrors.errs[0]
|
||||
if len(e.builtinErrors.errs) > 0 {
|
||||
if q.strictBuiltinErrors {
|
||||
err = e.builtinErrors.errs[0]
|
||||
} else if q.builtinErrorList != nil {
|
||||
// If a builtinErrorList has been supplied, we must use pointer indirection
|
||||
// to append to it. builtinErrorList is a slice pointer so that errors can be
|
||||
// appended to it without returning a new slice and changing the interface
|
||||
// of Iter.
|
||||
for _, err := range e.builtinErrors.errs {
|
||||
if tdError, ok := err.(*Error); ok {
|
||||
*(q.builtinErrorList) = append(*(q.builtinErrorList), *tdError)
|
||||
} else {
|
||||
*(q.builtinErrorList) = append(*(q.builtinErrorList), Error{
|
||||
Code: BuiltinErr,
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
q.metrics.Timer(metrics.RegoQueryEval).Stop()
|
||||
|
||||
Reference in New Issue
Block a user