Skip to content
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

Remove "not available" message #10998

Merged
merged 2 commits into from
Aug 21, 2023
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
12 changes: 12 additions & 0 deletions utils/render-policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
20 changes: 17 additions & 3 deletions utils/render_all_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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__":
Expand Down
16 changes: 11 additions & 5 deletions utils/rendering/controls-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ <h2>{{{ control.id }}}: {{{ control.title }}}</h2>
{{% if control.selections -%}}
Selections:
<ul>
{{%- for ruleobj in control.selections -%}}
{{%- set rule_id = ruleobj|string %}}
{{%- if rule_id in rules %}}
<li><a href="https://github.com/ComplianceAsCode/content/tree/master/{{{ rules[rule_id].relative_definition_location }}}">{{{ rule_id }}}</a>: {{{ rules[rule_id].title }}}</li>
{{%- for selection in control.selections|sort -%}}
{{%- if '=' in selection %}}
{{% set value_id, value = selection.split('=') %}}
{{%- if value_id in values %}}
<li><a href="https://github.com/ComplianceAsCode/content/tree/master/{{{ values[value_id].relative_definition_location }}}">{{{ value_id }}}</a> = {{{ value }}}</li>
{{%- endif -%}}
{{%- else %}}
{{%- if selection in rules %}}
<li><a href="https://github.com/ComplianceAsCode/content/tree/master/{{{ rules[selection].relative_definition_location }}}">{{{ selection }}}</a>: {{{ rules[selection].title }}}</li>
{{%- else %}}
<li>{{{ rule_id }}} - not available for this product</li>
<li>{{{ selection }}} - not available for this product</li>
{{%- endif -%}}
{{%- endif -%}}
{{%- endfor %}}
</ul>
Expand Down