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

ensure navigator layer comments are easy to read #89

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
58 changes: 36 additions & 22 deletions src/mapex/write_parsed_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,39 +366,52 @@

# define metadata
metadata = []
if mapping.get("score_category"):
metadata.append(
{
"name": "category",
"value": mapping["score_category"],
}
)
if (
emeth1 marked this conversation as resolved.
Show resolved Hide resolved
mapping.get("score_category")
or mapping.get("score_value")
or mapping.get("comments")
):
if mapping.get("score_category"):
metadata.append(

Check warning on line 375 in src/mapex/write_parsed_mappings.py

View check run for this annotation

Codecov / codecov/patch

src/mapex/write_parsed_mappings.py#L374-L375

Added lines #L374 - L375 were not covered by tests
{
"name": "category",
"value": mapping["score_category"],
}
)

if mapping.get("score_value"):
metadata.append({"name": "value", "value": mapping["score_value"]})
if mapping.get("score_value"):
metadata.append({"name": "value", "value": mapping["score_value"]})

Check warning on line 383 in src/mapex/write_parsed_mappings.py

View check run for this annotation

Codecov / codecov/patch

src/mapex/write_parsed_mappings.py#L382-L383

Added lines #L382 - L383 were not covered by tests

if mapping.get("comments"):
metadata.append({"name": "comment", "value": mapping["comments"]})
if mapping.get("comments"):
metadata.append({"name": "comment", "value": mapping["comments"]})

Check warning on line 386 in src/mapex/write_parsed_mappings.py

View check run for this annotation

Codecov / codecov/patch

src/mapex/write_parsed_mappings.py#L385-L386

Added lines #L385 - L386 were not covered by tests

if techniques_dict.get(tehchnique_id):
emeth1 marked this conversation as resolved.
Show resolved Hide resolved
# add capability information to technique it is mapped to
techniques_dict[tehchnique_id]["capability_ids"].append(capability_id)
metadata_info = [{"name": "control", "value": mapping["capability_id"]}]
metadata_info.extend(metadata)
metadata_info.append({"divider": True})

if "metadata" in techniques_dict[tehchnique_id]:
metadata_info = []
if len(metadata) > 0:
metadata_info.extend(

Check warning on line 394 in src/mapex/write_parsed_mappings.py

View check run for this annotation

Codecov / codecov/patch

src/mapex/write_parsed_mappings.py#L392-L394

Added lines #L392 - L394 were not covered by tests
[
{"divider": True},
{"name": "control", "value": mapping["capability_id"]},
]
)
metadata_info.extend(metadata)

Check warning on line 400 in src/mapex/write_parsed_mappings.py

View check run for this annotation

Codecov / codecov/patch

src/mapex/write_parsed_mappings.py#L400

Added line #L400 was not covered by tests

if "metadata" in techniques_dict[tehchnique_id] and len(metadata_info) > 0:

Check warning on line 402 in src/mapex/write_parsed_mappings.py

View check run for this annotation

Codecov / codecov/patch

src/mapex/write_parsed_mappings.py#L402

Added line #L402 was not covered by tests
techniques_dict[tehchnique_id]["metadata"].extend(metadata_info)
else:
techniques_dict[tehchnique_id]["metadata"] = metadata_info
else:
# add capability information to technique it is mapped to
techniques_dict[tehchnique_id] = {"capability_ids": [capability_id]}
techniques_dict[tehchnique_id]["metadata"] = [
{"name": "control", "value": mapping["capability_id"]}
]
techniques_dict[tehchnique_id]["metadata"].extend(metadata)
techniques_dict[tehchnique_id]["metadata"].append({"divider": True})
if len(metadata) > 0:
techniques_dict[tehchnique_id]["metadata"] = [

Check warning on line 410 in src/mapex/write_parsed_mappings.py

View check run for this annotation

Codecov / codecov/patch

src/mapex/write_parsed_mappings.py#L410

Added line #L410 was not covered by tests
{"divider": True},
{"name": "control", "value": mapping["capability_id"]},
]
techniques_dict[tehchnique_id]["metadata"].extend(metadata)

Check warning on line 414 in src/mapex/write_parsed_mappings.py

View check run for this annotation

Codecov / codecov/patch

src/mapex/write_parsed_mappings.py#L414

Added line #L414 was not covered by tests

return techniques_dict

Expand Down Expand Up @@ -434,13 +447,14 @@

related_controls_string = ""
if len(capability_ids):
related_controls_string = ", ".join(capability_ids)
# formats ids in a bulleted list
related_controls_string = "\u2022" + "\n\u2022".join(capability_ids)

layer["techniques"].append(
{
"techniqueID": technique,
"score": len(techniques_dict[technique]["capability_ids"]),
"comment": f"Related to {related_controls_string}",
"comment": f" Related to: \n {related_controls_string}",
"metadata": techniques_dict[technique].get("metadata", []),
}
)
Expand Down
8 changes: 4 additions & 4 deletions tests/expected_results/expected_results_navigator_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
{
"techniqueID": "T1137",
"score": 1,
"comment": "Related to AC-10",
"metadata": [{"name": "control", "value": "AC-10"}, {"divider": True}],
"comment": " Related to: \n •AC-10",
"metadata": [],
},
{
"techniqueID": "T1137.002",
"score": 1,
"comment": "Related to AC-10",
"metadata": [{"name": "control", "value": "AC-10"}, {"divider": True}],
"comment": " Related to: \n •AC-10",
"metadata": [],
},
],
"gradient": {"colors": ["#ffe766", "#ffaf66"], "minValue": 1, "maxValue": 1},
Expand Down
Loading