rlm_rest: Parsing the response attributes
Hi, My REST API service returns something like: { "count": 1, "next": null, "previous": null, "results": [ ... ] } The rest module of FR tells me: rest: Failed parsing attribute: Invalid vendor name in attribute name "count", skipping Is there any possibility to map the return attributes from my REST service to FR attributes? Michael Schwartzkopff
On 24/07/2024 06:49, Michael Schwartzkopff via Freeradius-Users wrote:
rest: Failed parsing attribute: Invalid vendor name in attribute name "count", skipping
FreeRADIUS version 3 expects that JSON responses will match one of a number of defined formats: { "<attribute0>":{ "do_xlat":<bool>, "is_json":<bool>, "op":"<operator>", "value":[<value0>,<value1>,<valueN>] }, "<attribute1>":{ "value":{ "<nested-attribute0>":{ "op":"<operator>", "value":<value0> } } }, "<attribute2>":"<value0>", "<attributeN>":[<value0>,<value1>,<valueN>] } Your sample data most closely matches the example "attribute2" in the format - so FreeRADIUS is looking to populate an attribute "count" with the provided value, but that does not exist in the dictionary. You could define local attributes matching the names found in your JSON responses, which will then be populated with the data in the response. It will be important to define all the possible objects which will be returned even if they are not used. FreeRADIUS v4 will make this much easier with the "json map" construct which allows arbitrary objects from a json structure to be used in populating attributes. -- Nick Porter
On 24.07.24 12:38, Nick Porter wrote:
On 24/07/2024 06:49, Michael Schwartzkopff via Freeradius-Users wrote:
rest: Failed parsing attribute: Invalid vendor name in attribute name "count", skipping
FreeRADIUS version 3 expects that JSON responses will match one of a number of defined formats:
{ "<attribute0>":{ "do_xlat":<bool>, "is_json":<bool>, "op":"<operator>", "value":[<value0>,<value1>,<valueN>] }, "<attribute1>":{ "value":{ "<nested-attribute0>":{ "op":"<operator>", "value":<value0> } } }, "<attribute2>":"<value0>", "<attributeN>":[<value0>,<value1>,<valueN>] }
Your sample data most closely matches the example "attribute2" in the format - so FreeRADIUS is looking to populate an attribute "count" with the provided value, but that does not exist in the dictionary.
You could define local attributes matching the names found in your JSON responses, which will then be populated with the data in the response.
It will be important to define all the possible objects which will be returned even if they are not used.
FreeRADIUS v4 will make this much easier with the "json map" construct which allows arbitrary objects from a json structure to be used in populating attributes.
Thanks. Defining a custom dictionary solved the problem for now.
participants (2)
-
Michael Schwartzkopff -
Nick Porter