Skip to content

Commit

Permalink
Include product title in profiles objects
Browse files Browse the repository at this point in the history
The product title is also useful to give more context about the product
id and the cost to include it in the profile objects is minimal, so it
was included to simplify collection of profiles information.

Signed-off-by: Marcus Burghardt <[email protected]>
  • Loading branch information
marcusburghardt committed Jan 9, 2025
1 parent 7e7e11c commit 0c74b57
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
20 changes: 12 additions & 8 deletions ssg/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ class ProfileSelections:
-----------
profile_id : str
The unique identifier for the profile.
product : str
The product associated with the profile.
variables : dict
A dictionary containing the variables for the profile.
"""
def __init__(self, profile_id, profile_title, product):
profile_title : str
The profile title associated with the profile id.
product_id : str
The product id associated with the profile.
product_title : str
The product title associated with the product id.
"""
def __init__(self, profile_id, profile_title, product_id, product_title):
self.profile_id = profile_id
self.profile_title = profile_title
self.product = product
self.product_id = product_id
self.product_title = product_title
self.rules = []
self.unselected_rules = []
self.variables = {}
Expand Down Expand Up @@ -325,13 +328,14 @@ def get_profiles_from_products(content_dir: str, products: list,

for product in products:
product_yaml = _load_product_yaml(content_dir, product)
product_title = product_yaml.get("full_name")
profiles_files = get_profile_files_from_root(product_yaml, product_yaml)
controls_manager = _load_controls_manager(controls_dir, product_yaml)
for file in profiles_files:
profile_id = os.path.basename(file).split('.profile')[0]
profile_yaml = _load_yaml_profile_file(file)
profile_title = profile_yaml.get("title")
profile = ProfileSelections(profile_id, profile_title, product)
profile = ProfileSelections(profile_id, profile_title, product, product_title)
profile = _process_profile(profile, profile_yaml, profiles_files,
controls_manager.policies)
profiles.append(profile)
Expand Down
2 changes: 1 addition & 1 deletion ssg/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def get_variables_from_profiles(profiles: list) -> dict_type:
variables = defaultdict(lambda: defaultdict(dict))
for profile in profiles:
for variable, value in profile.variables.items():
variables[variable][profile.product][profile.profile_id] = value
variables[variable][profile.product_id][profile.profile_id] = value
return variables


Expand Down
2 changes: 1 addition & 1 deletion tests/unit/ssg-module/test_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ def test_get_profiles_from_products():
profiles = get_profiles_from_products(content_dir, products, sorted=True)

assert len(profiles) == count_profiles_in_products_dir(products[0])
assert 'rhel' in profiles[0].product
assert 'rhel' in profiles[0].product_id
assert len(profiles[0].rules) > 0
assert len(profiles[0].variables) > 0
5 changes: 2 additions & 3 deletions tests/unit/ssg-module/test_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,10 @@ def test_get_variable_values(tmp_path):
assert result["test"]["product1"]["profile1"] == "value1"
assert result["test"]["product2"]["profile2"] == "value2"


def test_get_variables_from_profiles():
class MockProfile:
def __init__(self, product, profile_id, variables):
self.product = product
def __init__(self, product_id, profile_id, variables):
self.product_id = product_id
self.profile_id = profile_id
self.variables = variables

Expand Down

0 comments on commit 0c74b57

Please sign in to comment.