Skip to content

Commit 8c194b8

Browse files
committed
do some more cleanup of trees
1 parent c214d3a commit 8c194b8

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/trustshell/product_definitions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def _clean_cpe(cpe: str) -> str:
213213
def extend_with_product_mappings(
214214
self, ancestor_trees: list[Node], keep_cpes: bool = False
215215
) -> None:
216-
"""Create a new list of results with any matching streams or module as ancestors
216+
"""Update the ancestor_trees with any matching streams or module as descendants
217217
218218
Args:
219219
ancestor_trees: List of Node trees to extend with product mappings

src/trustshell/products.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def prime_cache(check: bool, debug: bool) -> None:
7272
is_eager=True,
7373
)
7474
@click.option("--latest", "-l", is_flag=True, default=True)
75+
@click.option("--cpes", "-c", is_flag=True, default=False)
7576
@click.option("--flaw", "-f", help="OSIDB flaw uuid or CVE")
7677
@click.option(
7778
"--replace",
@@ -85,7 +86,9 @@ def prime_cache(check: bool, debug: bool) -> None:
8586
"purl",
8687
type=click.STRING,
8788
)
88-
def search(purl: str, flaw: str, replace: bool, debug: bool, latest: bool) -> None:
89+
def search(
90+
purl: str, flaw: str, replace: bool, debug: bool, latest: bool, cpes: bool
91+
) -> None:
8992
"""Relate a purl to products in Trustify"""
9093
if not debug:
9194
config_logging(level="INFO")
@@ -104,9 +107,15 @@ def search(purl: str, flaw: str, replace: bool, debug: bool, latest: bool) -> No
104107
return
105108

106109
prod_defs = ProdDefs()
107-
prod_defs.extend_with_product_mappings(ancestor_trees)
110+
prod_defs.extend_with_product_mappings(ancestor_trees, keep_cpes=cpes)
108111

112+
seen_trees = set()
109113
for tree in ancestor_trees:
114+
_remove_duplicate_branches(tree)
115+
tree_signature = _get_branch_signature(tree.root)
116+
if tree_signature in seen_trees:
117+
continue
118+
seen_trees.add(tree_signature)
110119
render_tree(tree.root)
111120

112121
if not flaw:
@@ -351,14 +360,15 @@ def _trees_with_cpes(ancestor_data: dict[str, Any]) -> list[Node]:
351360
if tree.name.startswith("pkg:rpm/"):
352361
if container_in_tree(tree):
353362
continue
363+
_remove_non_cpe_branches(tree)
354364
if not _has_cpe_node(tree):
355365
for leaf in tree.leaves:
356366
logger.debug(
357367
f"Found result {tree.name} with ancestor: {leaf.name} but no CPE parent"
358368
)
359369
else:
360370
trees_with_cpes.append(tree)
361-
return [_remove_non_cpe_branches(tree) for tree in trees_with_cpes]
371+
return trees_with_cpes
362372

363373

364374
def container_in_tree(root: Node) -> bool:

0 commit comments

Comments
 (0)