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

feat: add a framework property to capture the CaC profile id #442

Merged
merged 5 commits into from
Feb 13, 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
28 changes: 14 additions & 14 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ trestlebot = "trestlebot.cli.root:root_cmd"
[tool.poetry.dependencies]
python = '^3.8.1'
gitpython = "^3.1.41"
compliance-trestle = "^3.5.0"
compliance-trestle = "^3.7.0"
github3-py = "^4.0.1"
python-gitlab = "^4.2.0"
ruamel-yaml = "^0.18.5"
Expand Down
2 changes: 1 addition & 1 deletion tests/trestlebot/cli/test_create_cmd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Red Hat, Inc.

""" Unit test for create commands ssp and cd"""
"""Unit test for create commands ssp and cd"""
import pathlib
from typing import Tuple

Expand Down
7 changes: 6 additions & 1 deletion tests/trestlebot/cli/test_sync_cac_content_cmd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Red Hat, Inc.

""" Unit test for sync-cac-content command"""
"""Unit test for sync-cac-content command"""
import pathlib
from typing import Any, Generator, Tuple

Expand Down Expand Up @@ -306,6 +306,11 @@ def test_sync_product(tmp_repo: Tuple[str, Repo]) -> None:
# Check control_implementations are attached
ci = component.control_implementations[0]
assert ci.source == "trestle://profiles/simplified_nist_profile/profile.json"

assert len(ci.props) == 1
assert ci.props[0].name == "Framework_Short_Name"
assert ci.props[0].value == "example"

set_parameters = ci.set_parameters
assert len(set_parameters) == 2
set_params_ids = []
Expand Down
2 changes: 1 addition & 1 deletion trestlebot/cli/commands/autosync.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Red Hat, Inc.

""" Autosync command"""
"""Autosync command"""

import logging
import sys
Expand Down
2 changes: 1 addition & 1 deletion trestlebot/cli/commands/init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Red Hat, Inc.

""""
"""
Module for Trestle-bot init command
"""
import argparse
Expand Down
2 changes: 1 addition & 1 deletion trestlebot/cli/commands/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Red Hat, Inc.

""" Version command """
"""Version command"""
7 changes: 7 additions & 0 deletions trestlebot/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@
# Trestlebot init constants
TRESTLEBOT_CONFIG_DIR = ".trestlebot"
TRESTLEBOT_KEEP_FILE = ".keep"

# Props

# TODO(jpower432): Propose upstream as to be populated
# by the profile or catalog "name" based on trestle workspace
# conventions.
FRAMEWORK_SHORT_NAME = "Framework_Short_Name"
2 changes: 1 addition & 1 deletion trestlebot/tasks/sync_cac_content_profile_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def create_oscal_profile(
self.oscal_catalog, name_update, resolved_controls
)
if not written:
logger.info(f"No updated for profile {name_update}")
logger.info(f"No update for profile {name_update}")

def execute(self) -> int:
# calling to get_control_ids _by_level and checking for valid control file name
Expand Down
22 changes: 19 additions & 3 deletions trestlebot/tasks/sync_cac_content_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
from ssg.products import load_product_yaml, product_yaml_path
from ssg.profiles import _load_yaml_profile_file, get_profiles_from_products
from trestle.common.common_types import TypeWithProps
from trestle.common.const import IMPLEMENTATION_STATUS, REPLACE_ME, TRESTLE_HREF_HEADING
from trestle.common.const import (
IMPLEMENTATION_STATUS,
REPLACE_ME,
TRESTLE_GENERIC_NS,
TRESTLE_HREF_HEADING,
)
from trestle.common.list_utils import as_list, none_if_empty
from trestle.common.model_utils import ModelUtils
from trestle.core.generators import generate_sample_model
Expand Down Expand Up @@ -107,6 +112,8 @@ def __init__(
self.controls: List[Control] = list()
self.rules_by_id: Dict[str, RuleInfo] = dict()

self.cac_profile_id = os.path.basename(cac_profile).split(".profile")[0]

self.profile_href: str = ""
self.profile_path: str = ""
self.catalog_helper = CatalogControlResolver()
Expand All @@ -116,9 +123,8 @@ def __init__(
def _collect_rules(self) -> None:
"""Collect all rules from the product profile."""
profiles = get_profiles_from_products(self.cac_content_root, [self.product])
cac_profile_id = os.path.basename(self.cac_profile).split(".profile")[0]
for profile in profiles:
if profile.profile_id == cac_profile_id:
if profile.profile_id == self.cac_profile_id:
self.rules = profile.rules
break

Expand Down Expand Up @@ -376,6 +382,16 @@ def _create_control_implementation(self) -> ControlImplementation:
all_implement_reqs.append(implemented_req)
ci.implemented_requirements = all_implement_reqs
self._add_set_parameters(ci)

# Add framework prop for complytime consumption. This should be the
# orginating CaC profile name.
ci.props = as_list(ci.props)
frameworkProp = generate_sample_model(Property)
frameworkProp.name = const.FRAMEWORK_SHORT_NAME
frameworkProp.value = self.cac_profile_id
frameworkProp.ns = TRESTLE_GENERIC_NS
ci.props.append(frameworkProp)

return ci

def _add_control_implementations(
Expand Down
2 changes: 1 addition & 1 deletion trestlebot/transformers/trestle_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def get_default_rule() -> TrestleRule:

# Adapted from https://docs.pydantic.dev/latest/errors/errors/
def location_to_dot_separation(
location: Tuple[Union[str, int], ...]
location: Tuple[Union[str, int], ...],
) -> str: # pragma: no cover
"""Convert a tuple of strings and integers to a dot separated string."""
path: str = ""
Expand Down
Loading