-
Notifications
You must be signed in to change notification settings - Fork 12
OSIDB-4923 - Add helper function to pull cpe list #1253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
7c1734f
bb2d409
fa056a0
6bb043b
a36d034
9169a82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| from typing import Union | ||
| from typing import List, Optional, Union | ||
|
|
||
| import nvdlib | ||
| from celery.utils.log import get_task_logger | ||
|
|
@@ -65,6 +65,20 @@ def response2result(self, vulnerabilities: list) -> list: | |
| filtering out everything unnecessary and simplifying | ||
| """ | ||
|
|
||
| def get_cpe_list(data: CVE) -> Optional[List[str]]: | ||
| """ | ||
| Return a list of CPEs from the CVE `data` | ||
| """ | ||
| cpe_list = [] | ||
| if "cpe" in data and len(data.cpe) > 0: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| for entry in data.cpe: | ||
| cpe_list.append(entry.criteria) | ||
|
|
||
| if len(cpe_list) > 0: | ||
| return cpe_list | ||
| else: | ||
| return None | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should be fine with just returning the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. Updated in bb2d409 |
||
|
|
||
| def get_cvss_metric(data: CVE, version: str) -> Union[dict, None]: | ||
| """ | ||
| Return CVSS metric from `data` for the given `version`. | ||
|
|
@@ -104,6 +118,7 @@ def get_cvss_metric(data: CVE, version: str) -> Union[dict, None]: | |
| ], | ||
| ) | ||
| ), | ||
| "nvd_cpes": get_cpe_list(vulnerability), | ||
| } | ||
| ) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be reduced to
hasattr(data, "cpe")since we are checking if the field exists. An emptydata.cpewill just mean that the following loop wouldn't run.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good call. Changed that in fa056a0