Skip to content

Commit

Permalink
feature: oval: add oval_list_to_set
Browse files Browse the repository at this point in the history
Oval set can have only up to 2 items. This converts list to one set as
it can get quite tedious if done by hand.
  • Loading branch information
maage committed May 7, 2023
1 parent 693e513 commit bef2156
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion shared/macros/10-oval.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,44 @@ Generates the :code:`<affected>` tag for OVAL check using correct product platfo
{{%- endmacro %}}


{{#
Convert list to set, complicated as one set can contain 1 or 2 items, but list
can contain more thant that. Set needs to be build from sub sets of items or
previous level sets. Do it recursiverly.

:param list_to_handle: list of elements
:param _result_list: internal, do not set
#}}
{{%- macro oval_list_to_set(list_to_handle, _result_list=[]) -%}}
{{%- if (list_to_handle | length) == 0 -%}}
{{%- if (_result_list | length) == 1 -%}}
{{%- for item in _result_list %}}
{{{ item }}}
{{%- endfor -%}}
{{%- else -%}}
{{{ oval_list_to_set(_result_list, []) }}}
{{%- endif -%}}
{{%- else -%}}
{{%- set result_list_item -%}}
<set>
{{%- for item in list_to_handle -%}}
{{%- if loop.index0 < 2 %}}
{{{ item | indent }}}
{{%- endif -%}}
{{%- endfor %}}
</set>
{{%- endset -%}}
{{%- set next_list = namespace(lst=[]) -%}}
{{%- for item in list_to_handle -%}}
{{%- if loop.index0 >= 2 -%}}
{{%- set next_list.lst = next_list.lst + [item] -%}}
{{%- endif -%}}
{{%- endfor -%}}
{{{ oval_list_to_set(next_list.lst, _result_list + [result_list_item]) }}}
{{%- endif -%}}
{{%- endmacro -%}}


{{%- macro mount_active_criterion(path) %}}
<criterion comment="The path {{{ path }}} is an active (mounted) mount point"
test_ref="test_mount_active_{{{ path | escape_id }}}_exists" />
Expand Down Expand Up @@ -1038,4 +1076,3 @@ Generates the :code:`<affected>` tag for OVAL check using correct product platfo
<ind:instance datatype="int">1</ind:instance>
</ind:textfilecontent54_object>
{{%- endmacro %}}

0 comments on commit bef2156

Please sign in to comment.