Skip to content

Commit

Permalink
Merge pull request ComplianceAsCode#11667 from vojtapolasek/fix_gen_r…
Browse files Browse the repository at this point in the history
…endered_policies_index

utils/gen_rendered_policies_index.py: read compiled control files
  • Loading branch information
Mab879 authored Mar 8, 2024
2 parents 2c8422b + d7918d2 commit 945e80a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 2 additions & 0 deletions ssg/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def __init__(self, filepath, env_yaml=None):
def represent_as_dict(self):
data = dict()
data["id"] = self.id
data["policy"] = self.policy
data["title"] = self.title
data["source"] = self.source
data["definition_location"] = self.filepath
Expand Down Expand Up @@ -337,6 +338,7 @@ def load(self):
if controls_dir:
self.controls_dir = os.path.join(os.path.dirname(self.filepath), controls_dir)
self.id = ssg.utils.required_key(yaml_contents, "id")
self.policy = ssg.utils.required_key(yaml_contents, "policy")
self.title = ssg.utils.required_key(yaml_contents, "title")
self.source = yaml_contents.get("source", "")
self.reference_type = yaml_contents.get("reference_type", None)
Expand Down
23 changes: 11 additions & 12 deletions utils/gen_rendered_policies_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ def get_rendered_policies_ids(rendered_policies_dir):
return policy_ids


def get_policy_names(ssg_root):
def get_policy_names(ssg_root, products):
policy_names = dict()
p = pathlib.Path(ssg_root)
for control_file in p.glob("controls/*.yml"):
# only process files, ignore controls directories
if not os.path.isfile(control_file):
continue
policy_id = pathlib.Path(control_file).stem
with open(control_file, "r") as f:
policy_yaml = yaml.full_load(f)
policy_name = policy_yaml["policy"]
policy_names[policy_id] = policy_name
for product in products:
p = pathlib.Path(ssg_root, "build", product.id)
for control_file in p.glob("controls/*.yml"):
policy_id = pathlib.Path(control_file).stem
if policy_id not in policy_names:
with open(control_file, "r") as f:
policy_yaml = yaml.full_load(f)
policy_name = policy_yaml["policy"]
policy_names[policy_id] = policy_name
return policy_names


Expand Down Expand Up @@ -62,7 +61,7 @@ def get_products(ssg_root):

def get_data(ssg_root):
products = get_products(ssg_root)
policy_names = get_policy_names(ssg_root)
policy_names = get_policy_names(ssg_root, products)
data = {"products": products, "policy_names": policy_names}
return data

Expand Down

0 comments on commit 945e80a

Please sign in to comment.