Skip to content

Commit 538464b

Browse files
committed
Add fixed_by_packages in V2 API
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 5cb0be0 commit 538464b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

vulnerabilities/api_v2.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,24 @@ class Meta:
195195
]
196196

197197
def get_affected_by_vulnerabilities(self, obj):
198-
return [vuln.vulnerability_id for vuln in obj.affected_by_vulnerabilities.all()]
198+
"""
199+
Return a dictionary with vulnerabilities as keys and their details, including fixed_by_packages.
200+
"""
201+
vulnerabilities = obj.affected_by_vulnerabilities.prefetch_related("fixed_by_packages")
202+
result = {}
203+
for vuln in vulnerabilities:
204+
result[vuln.vulnerability_id] = {
205+
"vulnerability_id": vuln.vulnerability_id,
206+
"fixed_by_packages": [
207+
package.package_url for package in vuln.fixed_by_packages.all()
208+
],
209+
}
210+
return result
199211

200212
def get_fixing_vulnerabilities(self, obj):
213+
"""
214+
Return a list of IDs of vulnerabilities that the package fixes.
215+
"""
201216
return [vuln.vulnerability_id for vuln in obj.fixing_vulnerabilities.all()]
202217

203218

0 commit comments

Comments
 (0)