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

chore: removes markdown creation from create_new_with_filter #159

Merged
merged 2 commits into from
Jan 31, 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
33 changes: 4 additions & 29 deletions tests/trestlebot/tasks/authored/test_ssp.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,35 +234,10 @@ def test_create_new_with_filter(tmp_trestle_dir: str) -> None:
_ = testutils.setup_for_profile(trestle_root, test_prof_filter, test_prof_filter)

ssp_name = "new_ssp"
new_md_path = os.path.join(markdown_dir, ssp_name)
input_ssp = test_ssp_output

# Call create_new_with_filter with new profile
authored_ssp.create_new_with_filter(
ssp_name, input_ssp, markdown_path=new_md_path, profile_name=test_prof_filter
)

ssp_index.reload()

assert ssp_index.get_profile_by_ssp(ssp_name) == test_prof_filter
assert test_comp in ssp_index.get_comps_by_ssp(ssp_name)
model_path = ModelUtils.get_model_path_for_name_and_class(
trestle_root, ssp_name, ossp.SystemSecurityPlan, FileContentType.JSON
)
assert model_path.exists()

ssp_name = "new_ssp_2"
new_md_path = os.path.join(markdown_dir, ssp_name)

# Call create_new_with_filter with a single compdef
authored_ssp.create_new_with_filter(
ssp_name, input_ssp, markdown_path=new_md_path, compdefs=[test_comp_2]
)

ssp_index.reload()
assert ssp_index.get_profile_by_ssp(ssp_name) == test_prof
assert test_comp not in ssp_index.get_comps_by_ssp(ssp_name)
assert test_comp_2 in ssp_index.get_comps_by_ssp(ssp_name)
authored_ssp.create_new_with_filter(ssp_name, input_ssp, compdefs=[test_comp_2])

ssp, model_path = load_validate_model_name(
trestle_root, ssp_name, ossp.SystemSecurityPlan, FileContentType.JSON
Expand All @@ -277,13 +252,13 @@ def test_create_new_with_filter(tmp_trestle_dir: str) -> None:
assert test_comp_2 in component_names
assert test_comp not in component_names

# Check that without markdown path the ssp_index is not updated
ssp_name = "new_ssp_3"
# Check that the ssp_index is not updated
ssp_name = "new_ssp_2"
authored_ssp.create_new_with_filter(
ssp_name, input_ssp, implementation_status=["implemented"]
)
ssp_index.reload()
with pytest.raises(
AuthoredObjectException, match="SSP new_ssp_3 does not exists in the index"
AuthoredObjectException, match="SSP new_ssp_2 does not exists in the index"
):
ssp_index.get_profile_by_ssp(ssp_name)
28 changes: 3 additions & 25 deletions trestlebot/tasks/authored/ssp.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ def create_new_with_filter(
ssp_name: str,
input_ssp: str,
version: str = "",
markdown_path: str = "",
profile_name: str = "",
compdefs: Optional[List[str]] = None,
implementation_status: Optional[List[str]] = None,
Expand All @@ -254,16 +253,15 @@ def create_new_with_filter(
Args:
ssp_name: Output name for ssp
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
implementation_status: Optional implementation status to filter by
control_origination: Optional control origination to filter by
markdown_path: Optional top-level markdown path to write to for continued editing.

Notes:
This will transform the SSP with filters. If markdown_path is provided, it will
also generate SSP markdown and an index entry for a new managed SSP for continued
management in the workspace.
The purpose of this function is to allow users to create a new SSP for reporting
purposes without having to modify the source SSP.
"""

# Create new ssp by filtering input ssp
Expand Down Expand Up @@ -303,23 +301,3 @@ def create_new_with_filter(
raise AuthoredObjectException(
f"Trestle filtering failed for {input_ssp}: {e}"
)

# If markdown_path is provided, create a new managed ssp.
# this will eventually need to have a JSON to MD recovery to
# reduce manual editing.
if markdown_path:
if not profile_name:
profile_name = self.ssp_index.get_profile_by_ssp(input_ssp)

if not compdefs:
compdefs = self.ssp_index.get_comps_by_ssp(input_ssp)

leveraged_ssp = self.ssp_index.get_leveraged_by_ssp(input_ssp)

self.create_new_default(
ssp_name,
profile_name,
compdefs,
markdown_path,
leveraged_ssp,
)
Loading