@@ -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,9 @@ 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 (
90
+ purl : str , flaw : str , replace : bool , debug : bool , latest : bool , cpes : bool
91
+ ) -> None :
89
92
"""Relate a purl to products in Trustify"""
90
93
if not debug :
91
94
config_logging (level = "INFO" )
@@ -104,9 +107,15 @@ def search(purl: str, flaw: str, replace: bool, debug: bool, latest: bool) -> No
104
107
return
105
108
106
109
prod_defs = ProdDefs ()
107
- prod_defs .extend_with_product_mappings (ancestor_trees )
110
+ prod_defs .extend_with_product_mappings (ancestor_trees , keep_cpes = cpes )
108
111
112
+ seen_trees = set ()
109
113
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 )
110
119
render_tree (tree .root )
111
120
112
121
if not flaw :
@@ -353,14 +362,15 @@ def _trees_with_cpes(ancestor_data: dict[str, Any]) -> list[Node]:
353
362
if tree .name .startswith ("pkg:rpm/" ):
354
363
if container_in_tree (tree ):
355
364
continue
365
+ _remove_non_cpe_branches (tree )
356
366
if not _has_cpe_node (tree ):
357
367
for leaf in tree .leaves :
358
368
logger .debug (
359
369
f"Found result { tree .name } with ancestor: { leaf .name } but no CPE parent"
360
370
)
361
371
else :
362
372
trees_with_cpes .append (tree )
363
- return [ _remove_non_cpe_branches ( tree ) for tree in trees_with_cpes ]
373
+ return trees_with_cpes
364
374
365
375
366
376
def container_in_tree (root : Node ) -> bool :
0 commit comments