From e54781898635ee764fd8c8397a9d75e431d368a6 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Mon, 21 Jul 2025 13:11:19 +0200 Subject: [PATCH 1/2] Added documentation on classfilterdata() Ticket: ENT-6193, CFE-3421 Signed-off-by: Lars Erik Wik --- .../functions/classfiltercsv.markdown | 2 +- .../functions/classfilterdata.markdown | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 content/reference/functions/classfilterdata.markdown diff --git a/content/reference/functions/classfiltercsv.markdown b/content/reference/functions/classfiltercsv.markdown index 08d713319..528c4a02a 100644 --- a/content/reference/functions/classfiltercsv.markdown +++ b/content/reference/functions/classfiltercsv.markdown @@ -46,7 +46,7 @@ minus `1`. *.sh text eol=lf ``` -**See also:** [`data_expand()`][data_expand], [`readcsv()`][readcsv], [`classmatch()`][classmatch] +**See also:** [`classfilterdata()`][classfilterdata], [`data_expand()`][data_expand], [`readcsv()`][readcsv], [`classmatch()`][classmatch] **History:** diff --git a/content/reference/functions/classfilterdata.markdown b/content/reference/functions/classfilterdata.markdown new file mode 100644 index 000000000..2091fa19d --- /dev/null +++ b/content/reference/functions/classfilterdata.markdown @@ -0,0 +1,55 @@ +--- +layout: default +title: classfilterdata +--- + +[%CFEngine_function_prototype(data_container, data_structure, key_or_index)%] + +**Description:** +This function filters a data container (`data_container`) based on defined +classes. Records within the data container containing a class expression located +at a given key or index (`key_or_index`) are filtered out when they evaluate to +false in the current context. The interpretation of the data container depends +on the specified data structure (`data_structure`). + +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. +- `"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. +- `"auto"`, the interpretation is automatically detected based on the data + structure. + +[%CFEngine_function_attributes(data_container, data_structure, key_or_index)%] + +**Example (with array of arrays):** + +**Policy:** + +[%CFEngine_include_snippet(classfilterdata_array_of_arrays.cf, #\+begin_src cfengine3, .*end_src)%] + +**Output:** + +[%CFEngine_include_snippet(classfilterdata_array_of_arrays.cf, #\+begin_src\s+example_output\s*, .*end_src)%] + +**Example (with array of objects):** + +**Policy:** + +[%CFEngine_include_snippet(classfilterdata_array_of_objects.cf, #\+begin_src cfengine3, .*end_src)%] + +**Output:** + +[%CFEngine_include_snippet(classfilterdata_array_of_objects.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])_. + +**See also:** [`classfiltercsv()`][classfiltercsv], [`data_expand()`][data_expand], [`classmatch()`][classmatch] + +**History:** + +- Introduced in CFEngine 3.27 From 81b1a3c1a2a4f42099b8c296360a4ae13424b138 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik <53906608+larsewi@users.noreply.github.com> Date: Wed, 23 Jul 2025 10:40:49 +0200 Subject: [PATCH 2/2] Update content/reference/functions/classfilterdata.markdown Co-authored-by: Nick Anderson --- content/reference/functions/classfilterdata.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/reference/functions/classfilterdata.markdown b/content/reference/functions/classfilterdata.markdown index 2091fa19d..dd4706fb8 100644 --- a/content/reference/functions/classfilterdata.markdown +++ b/content/reference/functions/classfilterdata.markdown @@ -52,4 +52,4 @@ This function can accept many types of data parameters _(See [collecting functio **History:** -- Introduced in CFEngine 3.27 +- Introduced in CFEngine 3.27.0