davsclaus commented on code in PR #26679:
URL: https://github.com/apache/camel/pull/26679#discussion_r4061811431
##########
components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaPolicyEvaluator.java:
##########
@@ -125,6 +126,98 @@ public boolean evaluate(Exchange exchange) throws
OpaPolicyEvaluationException {
*/
protected abstract Object evaluateDecision(Map<String, Object> input)
throws Exception;
+ /**
+ * Evaluates one input document per element in a single batch. The map is
keyed so a result can be matched back to
+ * its element; each value carries either the decision or the failure that
stopped it being reached. Only the REST
+ * evaluator implements this - wasm evaluates in-process, where batching
saves nothing - so the default refuses.
+ */
+ protected Map<String, BatchElement> evaluateBatchDecisions(Map<String,
Map<String, Object>> inputs) throws Exception {
+ throw new UnsupportedOperationException("batch evaluation is only
supported with evaluationMode=rest");
+ }
+
+ /**
+ * Authorizes a list in one call and records the per-element verdicts in
{@link OpaConstants#BATCH_DECISION}, a
+ * {@code List<Boolean>} parallel to the input.
+ * <p/>
+ * Fail-closed is per element: an element whose evaluation could not be
reached is denied (or allowed under
+ * {@code failOpen}) while the others decide normally. Only a batch call
that fails as a whole - the server could
+ * not be reached at all - denies (or, under {@code failOpen}, allows)
every element.
+ */
+ public List<Boolean> evaluateBatch(Exchange exchange, List<?> elements)
throws OpaPolicyEvaluationException {
+ clearDecisionHeaders(exchange);
Review Comment:
With an empty `List` body this still calls `client.evaluateBatch(path, {})`.
If the SDK or the server rejects an empty batch, the `catch (Exception)` below
turns that into an `OpaPolicyEvaluationException` - fail-closed on a body with
nothing to authorize. A short-circuit before the call would make the empty case
deterministic regardless of the SDK:
```java
if (elements.isEmpty()) {
exchange.getMessage().setHeader(OpaConstants.BATCH_DECISION, List.of());
return List.of();
}
```
(Not verified against the SDK's actual behaviour for an empty map - hence a
question rather than a finding.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]