oscerd commented on code in PR #29138:
URL: https://github.com/apache/camel/pull/29138#discussion_r4468189608
##########
components/camel-openfga/src/main/docs/openfga-component.adoc:
##########
@@ -521,6 +521,80 @@ resolved from the registry —
`conditionContext=#myContext`. A map rather than
every condition parameter in the authorization model (`int`, `bool`,
`timestamp`, `ipaddress`), and a map lets you
supply the right Java type instead of a string the server would reject.
+YAML, like a properties file, hands every value over as a string, the entries
of a map included. OpenFGA converts a
+string for an `int`, `uint`, `double`, `duration`, `timestamp` or `ipaddress`
parameter, so those can be written as
+they are, but it rejects one for a `bool` parameter: give that as
`#valueAs(boolean):true`. A `list` or `map` parameter
+cannot be written inline at all; declare it as a bean of its own and refer to
it with `#bean:`:
+
+[tabs]
+====
+Java::
++
+[source,java]
+------------------------------------------------------------
+Map<String, Object> networkContext = Map.of(
+ "trusted", true,
+ "allowed_regions", List.of("eu", "us"));
+context.getRegistry().bind("networkContext", networkContext);
+
+from("direct:checkFromTrustedNetwork")
+ .to("openfga:check?storeId={{fga.store}}&relation=reader"
+ + "&user=user:${exchangeProperty.CamelKeycloakTokenSubject}"
+ +
"&object=document:${header.documentId}&conditionContext=#networkContext");
+------------------------------------------------------------
+
+YAML::
++
+[source,yaml]
+----
+- beans:
+ - name: allowedRegions
+ type: java.util.ArrayList
+ properties:
+ "0": eu
+ "1": us
+ - name: networkContext
+ type: java.util.LinkedHashMap
+ properties:
+ # a bool parameter needs a boolean: the string "true" is rejected
+ trusted: "#valueAs(boolean):true"
+ # a list parameter needs a list
+ allowed_regions: "#bean:allowedRegions"
+- route:
+ from:
+ uri: direct:checkFromTrustedNetwork
+ steps:
+ - to:
+ uri: openfga:check
+ parameters:
+ storeId: "{{fga.store}}"
+ relation: reader
+ user: "user:${exchangeProperty.CamelKeycloakTokenSubject}"
+ object: "document:${header.documentId}"
+ conditionContext: "#networkContext"
Review Comment:
Thanks for looking, but `steps` nested under `from` is the layout the YAML
DSL expects, so the example is right as written:
- `OutputAwareFromDefinitionDeserializer` declares `steps` as a required
property of `from` (`@YamlProperty(name = "steps", ..., required = true)`) and
binds it in `case "steps": setSteps(target, val)`. An unknown key throws
`UnsupportedFieldException`; nothing is dropped silently.
- The suggested layout does not validate against the YAML DSL schema:
`required property 'steps' not found` at `/0/route/from`, and `property 'steps'
is not defined in the schema` at `/0/route`.
- I ran this exact block with `camel run --camel-version=4.23.0` against
OpenFGA v1.22.1: the `openfga:check` step ran and set
`CamelOpenFgaAllowed=true`.
The other YAML examples on the page use the same layout, so I am keeping it
as is.
_Claude Code on behalf of oscerd_
--
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]