@@ -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 :
@@ -351,14 +360,15 @@ def _trees_with_cpes(ancestor_data: dict[str, Any]) -> list[Node]:
351
360
if tree .name .startswith ("pkg:rpm/" ):
352
361
if container_in_tree (tree ):
353
362
continue
363
+ _remove_non_cpe_branches (tree )
354
364
if not _has_cpe_node (tree ):
355
365
for leaf in tree .leaves :
356
366
logger .debug (
357
367
f"Found result { tree .name } with ancestor: { leaf .name } but no CPE parent"
358
368
)
359
369
else :
360
370
trees_with_cpes .append (tree )
361
- return [ _remove_non_cpe_branches ( tree ) for tree in trees_with_cpes ]
371
+ return trees_with_cpes
362
372
363
373
364
374
def container_in_tree (root : Node ) -> bool :
0 commit comments