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: adds main_comp_only to create_new_with_filter in ssp.py #179

Merged
merged 2 commits into from
Mar 1, 2024
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
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
Loading