diff --git a/tests/trestlebot/tasks/authored/test_ssp.py b/tests/trestlebot/tasks/authored/test_ssp.py index 1b3d9b70..ed66eeaf 100644 --- a/tests/trestlebot/tasks/authored/test_ssp.py +++ b/tests/trestlebot/tasks/authored/test_ssp.py @@ -315,14 +315,27 @@ def test_create_new_with_filter(tmp_trestle_dir: str) -> None: ) assert model_path.exists() - assert len(ssp.system_implementation.components) == 1 + assert len(ssp.system_implementation.components) == 2 component_names = [ component.title for component in ssp.system_implementation.components ] assert test_comp_2 in component_names + assert const.SSP_MAIN_COMP_NAME in component_names assert test_comp not in component_names + # Main comp only + authored_ssp.create_new_with_filter(ssp_name, input_ssp, main_comp_only=True) + ssp, model_path = load_validate_model_name( + trestle_root, ssp_name, ossp.SystemSecurityPlan, FileContentType.JSON + ) + assert model_path.exists() + + assert len(ssp.system_implementation.components) == 1 + assert const.SSP_MAIN_COMP_NAME in [ + component.title for component in ssp.system_implementation.components + ] + # Check that the ssp_index is not updated ssp_name = "new_ssp_2" authored_ssp.create_new_with_filter( diff --git a/trestlebot/tasks/authored/ssp.py b/trestlebot/tasks/authored/ssp.py index 976ddae7..9a4de19c 100644 --- a/trestlebot/tasks/authored/ssp.py +++ b/trestlebot/tasks/authored/ssp.py @@ -10,6 +10,7 @@ import pathlib from typing import Any, Dict, List, Optional +from trestle.common.const import SSP_MAIN_COMP_NAME from trestle.common.err import TrestleError from trestle.common.model_utils import ModelUtils from trestle.core.commands.author.ssp import SSPFilter @@ -290,6 +291,7 @@ def create_new_with_filter( input_ssp: str, version: str = "", profile_name: str = "", + main_comp_only: bool = False, compdefs: Optional[List[str]] = None, implementation_status: Optional[List[str]] = None, control_origination: Optional[List[str]] = None, @@ -302,7 +304,9 @@ def create_new_with_filter( input_ssp: Input ssp to filter version: Optional version to include in the output ssp profile_name: Optional profile to filter by - compdefs: Optional list of component definitions to filter by + main_comp_only: Optional flag to include only the main component in the output ssp + compdefs: Optional list of component definitions to filter by. + The main component is added by default. implementation_status: Optional implementation status to filter by control_origination: Optional control origination to filter by @@ -318,7 +322,7 @@ def create_new_with_filter( components_title: Optional[List[str]] = None if compdefs: - components_title = [] + components_title = [SSP_MAIN_COMP_NAME] for comp_def_name in compdefs: comp_def, _ = ModelUtils.load_model_for_class( trestle_path, comp_def_name, ComponentDefinition @@ -326,6 +330,8 @@ def create_new_with_filter( components_title.extend( [component.title for component in comp_def.components] ) + elif main_comp_only: + components_title = [SSP_MAIN_COMP_NAME] try: exit_code = ssp_filter.filter_ssp(