Skip to content

Commit 8e014a3

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

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-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: 11 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,7 @@ 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(purl: str, flaw: str, replace: bool, debug: bool, latest: bool, cpes: bool) -> None:
8990
"""Relate a purl to products in Trustify"""
9091
if not debug:
9192
config_logging(level="INFO")
@@ -104,9 +105,15 @@ def search(purl: str, flaw: str, replace: bool, debug: bool, latest: bool) -> No
104105
return
105106

106107
prod_defs = ProdDefs()
107-
prod_defs.extend_with_product_mappings(ancestor_trees)
108+
prod_defs.extend_with_product_mappings(ancestor_trees, keep_cpes=cpes)
108109

110+
seen_trees = set()
109111
for tree in ancestor_trees:
112+
_remove_duplicate_branches(tree)
113+
tree_signature = _get_branch_signature(tree.root)
114+
if tree_signature in seen_trees:
115+
continue
116+
seen_trees.add(tree_signature)
110117
render_tree(tree.root)
111118

112119
if not flaw:
@@ -351,14 +358,15 @@ def _trees_with_cpes(ancestor_data: dict[str, Any]) -> list[Node]:
351358
if tree.name.startswith("pkg:rpm/"):
352359
if container_in_tree(tree):
353360
continue
361+
_remove_non_cpe_branches(tree)
354362
if not _has_cpe_node(tree):
355363
for leaf in tree.leaves:
356364
logger.debug(
357365
f"Found result {tree.name} with ancestor: {leaf.name} but no CPE parent"
358366
)
359367
else:
360368
trees_with_cpes.append(tree)
361-
return [_remove_non_cpe_branches(tree) for tree in trees_with_cpes]
369+
return trees_with_cpes
362370

363371

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

0 commit comments

Comments
 (0)