From 3e0d2c0a0c8d0cb367920ec57058e2a57d825b88 Mon Sep 17 00:00:00 2001 From: Evgeny Kolesnikov Date: Thu, 24 Nov 2022 05:43:27 +0100 Subject: [PATCH] Refactor build_yaml Clean up imports and fix small problems. --- ssg/build_yaml.py | 11 +++++------ ssg/entities/common.py | 2 +- tests/unit/ssg-module/data/templates/extra_ovals.yml | 3 +++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ssg/build_yaml.py b/ssg/build_yaml.py index 4b9e4abc430..c87ccf8444c 100644 --- a/ssg/build_yaml.py +++ b/ssg/build_yaml.py @@ -12,7 +12,7 @@ import ssg.build_remediations -from .build_cpe import CPEDoesNotExist, CPEALLogicalTest, CPEALFactRef, ProductCPEs +from .build_cpe import CPEALLogicalTest, CPEALFactRef, ProductCPEs from .constants import (XCCDF12_NS, OSCAP_BENCHMARK, OSCAP_GROUP, @@ -40,8 +40,7 @@ from .yaml import DocumentationNotComplete, open_and_macro_expand from .utils import required_key, mkdir_p -from .xml import ElementTree as ET, add_xhtml_namespace, register_namespaces, parse_file -from .shims import unicode_func +from .xml import ElementTree as ET, register_namespaces, parse_file import ssg.build_stig from .entities.common import add_sub_element, make_items_product_specific, \ @@ -280,7 +279,7 @@ def process_input_dict(cls, input_contents, env_yaml, product_cpes): return data def represent_as_dict(self): - data = super(Benchmark, cls).represent_as_dict() + data = super(Benchmark, self).represent_as_dict() data["rear-matter"] = data["rear_matter"] del data["rear_matter"] @@ -678,9 +677,9 @@ class Rule(XCCDFEntity, Templatable): inherited_cpe_platform_names=lambda: set(), bash_conditional=lambda: None, fixes=lambda: dict(), - ** XCCDFEntity.KEYS, - ** Templatable.KEYS + **XCCDFEntity.KEYS ) + KEYS.update(**Templatable.KEYS) MANDATORY_KEYS = { "title", diff --git a/ssg/entities/common.py b/ssg/entities/common.py index 58043c7c667..d7179ac4b95 100644 --- a/ssg/entities/common.py +++ b/ssg/entities/common.py @@ -399,7 +399,7 @@ def get_template_vars(self, env_yaml): # A better name is '_entity_id' (as in XCCDF Entity). template_vars["_rule_id"] = self.id_ - return make_items_product_specific(template_vars, env_yaml["product"]) + return make_items_product_specific(template_vars, env_yaml["product"], allow_overwrites=True) def get_template_backend_langs(self): """ diff --git a/tests/unit/ssg-module/data/templates/extra_ovals.yml b/tests/unit/ssg-module/data/templates/extra_ovals.yml index 78a223af8e4..c9b7e00725b 100644 --- a/tests/unit/ssg-module/data/templates/extra_ovals.yml +++ b/tests/unit/ssg-module/data/templates/extra_ovals.yml @@ -2,3 +2,6 @@ package_avahi_installed: name: package_installed vars: pkgname: avahi + pkgname@ubuntu2004: avahi-daemon + pkgname@rhel8: avahi8 +