Skip to content

Commit

Permalink
Add: Allow to set the number of results to request per page for NVD API
Browse files Browse the repository at this point in the history
Allow a user of the NVD API to specify the number of results within a
response. This allows to adjust the size of each "page".
  • Loading branch information
bjoernricks authored and greenbonebot committed Dec 7, 2023
1 parent fef8e2c commit 9fe1385
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
10 changes: 6 additions & 4 deletions pontos/nvd/cpe/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def cpes(
match_criteria_id: Optional[str] = None,
request_results: Optional[int] = None,
start_index: int = 0,
results_per_page: Optional[int] = None,
) -> NVDResults[CPE]:
"""
Get all CPEs for the provided arguments
Expand All @@ -162,6 +163,8 @@ def cpes(
to download all available CPEs.
start_index: Index of the first CPE to be returned. Useful only for
paginated requests that should not start at the first page.
results_per_page: Number of results in a single requests. Mostly
useful for paginated requests.
Returns:
A NVDResponse for CPEs
Expand Down Expand Up @@ -205,10 +208,9 @@ def cpes(
if match_criteria_id:
params["matchCriteriaId"] = match_criteria_id

results_per_page = (
request_results
if request_results and request_results < MAX_CPES_PER_PAGE
else MAX_CPES_PER_PAGE
results_per_page = min(
results_per_page or MAX_CPES_PER_PAGE,
request_results or MAX_CPES_PER_PAGE,
)

return NVDResults(
Expand Down
10 changes: 6 additions & 4 deletions pontos/nvd/cve/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def cves(
has_oval: Optional[bool] = None,
request_results: Optional[int] = None,
start_index: int = 0,
results_per_page: Optional[int] = None,
) -> NVDResults[CVE]:
"""
Get all CVEs for the provided arguments
Expand Down Expand Up @@ -174,6 +175,8 @@ def cves(
to download all available CVEs.
start_index: Index of the first CVE to be returned. Useful only for
paginated requests that should not start at the first page.
results_per_page: Number of results in a single requests. Mostly
useful for paginated requests.
Returns:
A NVDResponse for CVEs
Expand Down Expand Up @@ -252,10 +255,9 @@ def cves(
if has_oval:
params["hasOval"] = ""

results_per_page = (
request_results
if request_results and request_results < MAX_CVES_PER_PAGE
else MAX_CVES_PER_PAGE
results_per_page = min(
results_per_page or MAX_CVES_PER_PAGE,
request_results or MAX_CVES_PER_PAGE,
)
return NVDResults(
self,
Expand Down
10 changes: 6 additions & 4 deletions pontos/nvd/cve_changes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def changes(
event_name: Optional[Union[EventName, str]] = None,
request_results: Optional[int] = None,
start_index: int = 0,
results_per_page: Optional[int] = None,
) -> NVDResults[CVEChange]:
"""
Get all CVEs for the provided arguments
Expand All @@ -102,6 +103,8 @@ def changes(
start_index: Index of the first CVE change to be returned. Useful
only for paginated requests that should not start at the first
page.
results_per_page: Number of results in a single requests. Mostly
useful for paginated requests.
Returns:
A NVDResponse for CVE changes
Expand Down Expand Up @@ -146,10 +149,9 @@ def changes(
if event_name:
params["eventName"] = event_name

results_per_page = (
request_results
if request_results and request_results < MAX_CVE_CHANGES_PER_PAGE
else MAX_CVE_CHANGES_PER_PAGE
results_per_page = min(
results_per_page or MAX_CVE_CHANGES_PER_PAGE,
request_results or MAX_CVE_CHANGES_PER_PAGE,
)
return NVDResults(
self,
Expand Down

0 comments on commit 9fe1385

Please sign in to comment.