gnodet-bot commented on code in PR #29841:
URL: https://github.com/apache/camel/pull/29841#discussion_r4627428321
##########
components/camel-openfga/src/main/java/org/apache/camel/component/openfga/OpenFgaProducer.java:
##########
@@ -236,40 +326,43 @@ private List<String> clientBatchCheck(
options.consistency(authorizer.getConsistency());
}
- List<ClientBatchCheckClientResponse> responses = authorizer.await(
- exchange, "batch check " + relation + " for " + user,
- () -> authorizer.getClient().clientBatchCheck(requests,
options),
- // the batch fans out one request per object,
maxParallelRequests at a time, so it needs more than a
- // single request's budget - otherwise a large batch against a
slow server is cancelled mid-flight
- authorizer.batchAwaitTimeoutMillis(requests.size(),
maxParallelRequests));
-
- Set<String> permitted = new HashSet<>();
- for (ClientBatchCheckClientResponse response : responses) {
- if (response.getThrowable() != null) {
- // one check in the batch never got an answer. Returning the
rest would quietly present a partial
- // filter as a complete one, so the whole operation fails -
and unlike a single check, there is no
- // failOpen here, because "proceed" for a filter would mean
handing back everything unfiltered
- throw new OpenFgaEvaluationException(
- "OpenFGA failed to answer part of a batch check for "
+ user, exchange,
- response.getThrowable());
- }
- if (Boolean.TRUE.equals(response.getAllowed())) {
- permitted.add(response.getRequest().getObject());
- }
- }
- // filter the body rather than collect the answers: the SDK issues the
checks in parallel and hands them back
- // in whatever order they completed, so building the result from the
responses would reorder the caller's list
- // between runs. A route that filters a list to render it wants the
order it asked in
- List<String> allowed = new ArrayList<>();
- for (String object : objects) {
- if (permitted.contains(object)) {
- allowed.add(object);
- }
- }
- return allowed;
+ return invocation(authorizer, exchange, "batch check " + relation + "
for " + user,
+ () -> authorizer.getClient().clientBatchCheck(requests,
options), responses -> {
+
+ Set<String> permitted = new HashSet<>();
+ for (ClientBatchCheckClientResponse response : responses) {
+ if (response.getThrowable() != null) {
+ // one check in the batch never got an answer.
Returning the rest would quietly present a partial
+ // filter as a complete one, so the whole
operation fails - and unlike a single check, there is no
+ // failOpen here, because "proceed" for a filter
would mean handing back everything unfiltered
+ throw new CompletionException(
+ new OpenFgaEvaluationException(
+ "OpenFGA failed to answer part of
a batch check for " + user, exchange,
+ response.getThrowable()));
+ }
+ if (Boolean.TRUE.equals(response.getAllowed())) {
+ permitted.add(response.getRequest().getObject());
+ }
+ }
+ // filter the body rather than collect the answers: the
SDK issues the checks in parallel and hands them back
+ // in whatever order they completed, so building the
result from the responses would reorder the caller's list
+ // between runs. A route that filters a list to render it
wants the order it asked in
+ List<String> allowed = new ArrayList<>();
+ for (String object : objects) {
+ if (permitted.contains(object)) {
+ allowed.add(object);
+ }
+ }
+ exchange.getMessage().setHeader(OpenFgaConstants.ALLOWED,
!allowed.isEmpty());
+ exchange.getMessage().setBody(allowed);
+ }, authorizer.batchAwaitTimeoutMillis(requests.size(),
maxParallelRequests));
}
- private List<String> serverBatchCheck(Exchange exchange, OpenFgaAuthorizer
authorizer, List<ClientCheckRequest> requests)
+ /**
+ * Lists the objects of the configured type the subject can reach through
the relation.
+ */
+ private PreparedOperation prepareServerBatchCheck(
+ Exchange exchange, OpenFgaAuthorizer authorizer,
List<ClientCheckRequest> requests)
Review Comment:
🐛 **Copy-paste Javadoc artifact**: this description (`"Lists the objects of
the configured type the subject can reach through the relation."`) belongs to
the old `listObjects`/`prepareListObjects` method above — the Javadoc moved
with the wrong method during the `serverBatchCheck`→`prepareServerBatchCheck`
refactor.
```suggestion
/**
* Checks objects against one subject using the server-side BatchCheck
API.
*/
private PreparedOperation prepareServerBatchCheck(
```
--
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]