From 4448831e262060bd2306ed97b99e527885371e7e Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 5 Aug 2025 16:49:21 +0200 Subject: [PATCH] classfilterdata(): added docs for object of arrays/objects Ticket: CFE-4562 Signed-off-by: Lars Erik Wik --- .../functions/classfilterdata.markdown | 52 ++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/content/reference/functions/classfilterdata.markdown b/content/reference/functions/classfilterdata.markdown index a1344cf19..b188a5320 100644 --- a/content/reference/functions/classfilterdata.markdown +++ b/content/reference/functions/classfilterdata.markdown @@ -16,10 +16,18 @@ If the `data_structure` argument is specified to be: - `"array_of_arrays"`, the `data_container` argument is interpreted as an array of arrays, and the `key_or_index` argument is interpreted as an index within - the children arrays. + the children arrays. The `key_or_index` argument is required. - `"array_of_objects"`, the `data_container` argument is interpreted as an array of objects, and the `key_or_index` argument is interpreted as a key within the - children objects. + children objects. The `key_or_index` argument is required. +- `"object_of_arrays"`, the `data_container` argument is interpreted as an object + of arrays, and the `key_or_index` argument is interpreted as an index within + the children arrays (if specified). If the `key_or_index` argument is omitted, + the key of the child array itself is used as a class expression. +- `"object_of_objects"`, the `data_container` argument is interpreted as an object + if objects, and the `key_or_index` argument is interpreted as a key within the + children objects (if specified). If the `key_or_index` argument is omitted, the + key of the child object itself is used as a class expression. - `"auto"`, the interpretation is automatically detected based on the data structure. @@ -45,6 +53,46 @@ If the `data_structure` argument is specified to be: {{< CFEngine_include_snippet(classfilterdata_array_of_objects.cf, #\+begin_src\s+example_output\s*, .*end_src) >}} +**Example (with object of arrays):** + +**Policy:** + +{{< CFEngine_include_snippet(classfilterdata_object_of_arrays.cf, #\+begin_src cfengine3, .*end_src) >}} + +**Output:** + +{{< CFEngine_include_snippet(classfilterdata_object_of_arrays.cf, #\+begin_src\s+example_output\s*, .*end_src) >}} + +**Example (with object of objects):** + +**Policy:** + +{{< CFEngine_include_snippet(classfilterdata_object_of_objects.cf, #\+begin_src cfengine3, .*end_src) >}} + +**Output:** + +{{< CFEngine_include_snippet(classfilterdata_object_of_objects.cf, #\+begin_src\s+example_output\s*, .*end_src) >}} + +**Example (with object of arrays using exogenous key):** + +**Policy:** + +{{< CFEngine_include_snippet(classfilterdata_object_of_arrays_exogenous_key.cf, #\+begin_src cfengine3, .*end_src) >}} + +**Output:** + +{{< CFEngine_include_snippet(classfilterdata_object_of_arrays_exogenous_key.cf, #\+begin_src\s+example_output\s*, .*end_src) >}} + +**Example (with object of objects using exogenous key):** + +**Policy:** + +{{< CFEngine_include_snippet(classfilterdata_object_of_objects_exogenous_key.cf, #\+begin_src cfengine3, .*end_src) >}} + +**Output:** + +{{< CFEngine_include_snippet(classfilterdata_object_of_objects_exogenous_key.cf, #\+begin_src\s+example_output\s*, .*end_src) >}} + **Notes:** This function can accept many types of data parameters _(See [collecting function][Functions#collecting functions])_.