Skip to content

Commit

Permalink
feat: adds main_comp_only to create_new_with_filter in ssp.py (#179)
Browse files Browse the repository at this point in the history
The main component is needed in a trestle SSP for it be valid.
This has been added by default when filtering by components in
workspace component definitions and option added to filter out all
component but the main.

Signed-off-by: Jennifer Power <[email protected]>
  • Loading branch information
jpower432 authored Mar 1, 2024
1 parent 588d988 commit 398c196
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
15 changes: 14 additions & 1 deletion tests/trestlebot/tasks/authored/test_ssp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 8 additions & 2 deletions trestlebot/tasks/authored/ssp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -318,14 +322,16 @@ 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
)
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(
Expand Down

0 comments on commit 398c196

Please sign in to comment.