10000 Stop processing templated remediations by Jinja by jan-cerny · Pull Request #13471 · ComplianceAsCode/content · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Stop processing templated remediations by Jinja #13471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions ssg/build_remediations.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,11 @@ def expand_env_yaml_from_rule(self):
self.local_env_yaml["rule_id"] = self.associated_rule.id_
self.local_env_yaml["cce_identifiers"] = self.associated_rule.identifiers

def parse_from_file_with_jinja(self, env_yaml, cpe_platforms):
return parse_from_file_with_jinja(self.file_path, env_yaml)
def parse_from_file(self, env_yaml, cpe_platforms):
if "fixes_from_templates" in self.file_path:
return parse_from_file_without_jinja(self.file_path)
else:
return parse_from_file_with_jinja(self.file_path, env_yaml)

def get_inherited_cpe_platform_names(self):
inherited_cpe_platform_names = set()
Expand Down Expand Up @@ -188,7 +191,7 @@ def process(remediation, env_yaml, cpe_platforms):
if not is_supported_filename(remediation.remediation_type, remediation.file_path):
return

result = remediation.parse_from_file_with_jinja(env_yaml, cpe_platforms)
result = remediation.parse_from_file(env_yaml, cpe_platforms)
platforms = result.config['platform']

if not platforms:
Expand All @@ -215,9 +218,9 @@ class BashRemediation(Remediation):
def __init__(self, file_path):
super(BashRemediation, self).__init__(file_path, "bash")

def parse_from_file_with_jinja(self, env_yaml, cpe_platforms):
def parse_from_file(self, env_yaml, cpe_platforms):
self.local_env_yaml.update(env_yaml)
result = super(BashRemediation, self).parse_from_file_with_jinja(
result = super(BashRemediation, self).parse_from_file(
self.local_env_yaml, cpe_platforms)

# Avoid platform wrapping empty fix text
Expand Down Expand Up @@ -266,9 +269,9 @@ def __init__(self, file_path):

self.body = None

def parse_from_file_with_jinja(self, env_yaml, cpe_platforms):
def parse_from_file(self, env_yaml, cpe_platforms):
self.local_env_yaml.update(env_yaml)
result = super(AnsibleRemediation, self).parse_from_file_with_jinja(
result = super(AnsibleRemediation, self).parse_from_file(
self.local_env_yaml, cpe_platforms)

if not self.associated_rule:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/ssg-module/test_build_remediations.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_ansible_class(env_yaml, cpe_platforms):
os.path.join(DATADIR, "ansible.yml"), os.path.join(DATADIR, "file_owner_grub2_cfg.yml")
)

remediation.parse_from_file_with_jinja(env_yaml, cpe_platforms)
remediation.parse_from_file(env_yaml, cpe_platforms)

assert remediation.metadata["reboot"] == 'false'
assert remediation.metadata["strategy"] == 'configure'
Expand All @@ -95,7 +95,7 @@ def test_ansible_conformance(env_yaml, cpe_platforms):
)
ref_remediation_dict = ordered_load(open(os.path.join(DATADIR, "ansible-resolved.yml")))

remediation.parse_from_file_with_jinja(env_yaml, cpe_platforms)
remediation.parse_from_file(env_yaml, cpe_platforms)
# The comparison has to be done this way due to possible order variations,
# which don't matter, but they make tests to fail.
assert set(remediation.body[0]["tags"]) == set(ref_remediation_dict[0]["tags"])
Expand Down
Loading
0