@@ -72,6 +72,7 @@ def prime_cache(check: bool, debug: bool) -> None:
72
72
is_eager = True ,
73
73
)
74
74
@click .option ("--latest" , "-l" , is_flag = True , default = True )
75
+ @click .option ("--cpes" , "-c" , is_flag = True , default = False )
75
76
@click .option ("--flaw" , "-f" , help = "OSIDB flaw uuid or CVE" )
76
77
@click .option (
77
78
"--replace" ,
@@ -85,7 +86,7 @@ def prime_cache(check: bool, debug: bool) -> None:
85
86
"purl" ,
86
87
type = click .STRING ,
87
88
)
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 :
89
90
"""Relate a purl to products in Trustify"""
90
91
if not debug :
91
92
config_logging (level = "INFO" )
@@ -104,9 +105,15 @@ def search(purl: str, flaw: str, replace: bool, debug: bool, latest: bool) -> No
104
105
return
105
106
106
107
prod_defs = ProdDefs ()
107
- prod_defs .extend_with_product_mappings (ancestor_trees )
108
+ prod_defs .extend_with_product_mappings (ancestor_trees , keep_cpes = cpes )
108
109
110
+ seen_trees = set ()
109
111
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 )
110
117
render_tree (tree .root )
111
118
112
119
if not flaw :
@@ -351,14 +358,15 @@ def _trees_with_cpes(ancestor_data: dict[str, Any]) -> list[Node]:
351
358
if tree .name .startswith ("pkg:rpm/" ):
352
359
if container_in_tree (tree ):
353
360
continue
361
+ _remove_non_cpe_branches (tree )
354
362
if not _has_cpe_node (tree ):
355
363
for leaf in tree .leaves :
356
364
logger .debug (
357
365
f"Found result { tree .name } with ancestor: { leaf .name } but no CPE parent"
358
366
)
359
367
else :
360
368
trees_with_cpes .append (tree )
361
- return [ _remove_non_cpe_branches ( tree ) for tree in trees_with_cpes ]
369
+ return trees_with_cpes
362
370
363
371
364
372
def container_in_tree (root : Node ) -> bool :
0 commit comments