From 6e72db4dd9776284c754eb3bb3eaed9dfcbd6dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= Date: Wed, 16 Aug 2023 14:10:34 +0200 Subject: [PATCH 1/2] Remove "not available" message In the HTML controls pages, the variables are shown with a "not available in this product" message, which is incorrect. This message makes sense only with rules selections but not with variables selections. --- utils/rendering/controls-template.html | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/utils/rendering/controls-template.html b/utils/rendering/controls-template.html index e62b5118300..6b5747a5dd4 100644 --- a/utils/rendering/controls-template.html +++ b/utils/rendering/controls-template.html @@ -22,12 +22,15 @@

{{{ control.id }}}: {{{ control.title }}}

{{% if control.selections -%}} Selections: From 58e33553d0bdc7b98e06a350ade486bd0155a9df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= Date: Mon, 21 Aug 2023 11:48:23 +0200 Subject: [PATCH 2/2] Add a HTML link to XCCDF Values The readers of the policy HTML page will be able to click on a link that leads to the upstream definition of an XCCDF Value on GitHub. This is similar to the link that we provide for rules. --- utils/render-policy.py | 12 ++++++++++++ utils/render_all_policies.py | 20 +++++++++++++++++--- utils/rendering/controls-template.html | 5 ++++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/utils/render-policy.py b/utils/render-policy.py index 5dba0b54ad7..d70c524268a 100755 --- a/utils/render-policy.py +++ b/utils/render-policy.py @@ -44,6 +44,17 @@ def set_policy(self, policy_file): .format(policy_title=policy.title, product=self.product) ) + def set_all_values_with_metadata(self): + resolved_values_dir = os.path.join(self.built_content_path, "values") + values = dict() + for v_file in os.listdir(resolved_values_dir): + v_file_path = os.path.join(resolved_values_dir, v_file) + val = ssg.build_yaml.Value.from_yaml(v_file_path) + val.relative_definition_location = val.definition_location.replace( + self.project_directory, "") + values[val.id_] = val + self.template_data["values"] = values + def parse_args(): parser = HtmlOutput.create_parser( @@ -59,5 +70,6 @@ def parse_args(): args = parse_args() renderer = HtmlOutput(args.product, args.build_dir) renderer.set_all_rules_with_metadata() + renderer.set_all_values_with_metadata() renderer.set_policy(args.policy) renderer.output_results(args) diff --git a/utils/render_all_policies.py b/utils/render_all_policies.py index c1a8c5c8a6d..7a65093bd0e 100644 --- a/utils/render_all_policies.py +++ b/utils/render_all_policies.py @@ -51,6 +51,18 @@ def get_rules(root_abspath: str, built_product_dir: str) -> dict: return rules +def get_values(root_abspath: str, built_product_dir: str) -> dict: + resolved_values_dir = os.path.join(built_product_dir, "values") + values = dict() + for v_file in os.listdir(resolved_values_dir): + v_file_path = os.path.join(resolved_values_dir, v_file) + val = ssg.build_yaml.Value.from_yaml(v_file_path) + val.relative_definition_location = val.definition_location.replace( + root_abspath, "") + values[val.id_] = val + return values + + def load_policy(controls_dir: str, policy_id: str) -> ssg.controls.Policy: policy_file = os.path.join(controls_dir, policy_id + ".yml") policy = ssg.controls.Policy(policy_file) @@ -60,12 +72,13 @@ def load_policy(controls_dir: str, policy_id: str) -> ssg.controls.Policy: def render_policy( policy: ssg.controls.Policy, product_id: str, rules: list, - output_dir: str) -> None: + values: list, output_dir: str) -> None: output_path = os.path.join(output_dir, policy.id + ".html") data = { "policy": policy, "title": f"Definition of {policy.title} for {product_id}", - "rules": rules + "rules": rules, + "values": values } utils.template_renderer.render_template( data, CONTROLS_TEMPLATE, output_path) @@ -79,11 +92,12 @@ def main(): policies_used_in_product = get_used_policies(built_product_dir) controls_dir = os.path.join(built_product_dir, "controls") rules = get_rules(root_path, built_product_dir) + values = get_values(root_path, built_product_dir) if not os.path.exists(args.output_dir): os.mkdir(args.output_dir) for policy_id in policies_used_in_product: policy = load_policy(controls_dir, policy_id) - render_policy(policy, args.product, rules, args.output_dir) + render_policy(policy, args.product, rules, values, args.output_dir) if __name__ == "__main__": diff --git a/utils/rendering/controls-template.html b/utils/rendering/controls-template.html index 6b5747a5dd4..89d41299b08 100644 --- a/utils/rendering/controls-template.html +++ b/utils/rendering/controls-template.html @@ -24,7 +24,10 @@

{{{ control.id }}}: {{{ control.title }}}