Skip to content
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

Change: Introduce more flexible NVDResults class #936

Merged
merged 1 commit into from
Nov 30, 2023
Merged

Conversation

bjoernricks
Copy link
Contributor

What

Before all NVD API classes methods returned an async iterator. This didn't allow much control of what the user actually wants and how the requests are issued. To improve the situation a new NVDResults class is returned which itself is an async iterator so that the previous API is kept compatible.

But additionally the NVDResults instance allows to get the plain JSON data, the number of available results and also to iterate over chunks of results (which the NVD API is always returning).

Most important improvement the NVDResults instance keeps the state. That means if an http error occurs it is possible to request the same data again. With the old API the requests need to start from the beginning if something did go wrong. For example if we downloaded already 100k CVEs and a http error was raised we needed to start from CVE number 1 again. With the new implementation we can just continue with the last request again.

Why

Allow much more flexible queries to the NVD API and allow to resume on errors.

References

DEVOPS-472

Checklist

  • Tests

@bjoernricks bjoernricks requested a review from a team as a code owner November 29, 2023 16:27
@greenbonebot greenbonebot enabled auto-merge (rebase) November 29, 2023 16:27
Copy link

Conventional Commits Report

Type Number
Changed 1

🚀 Conventional commits found.

Before all NVD API classes methods returned an async iterator. This
didn't allow much control of what the user actually wants and how the
requests are issued. To improve the situation a new NVDResults class is
returned which itself is an async iterator so that the previous API is
kept compatible.

But additionally the NVDResults instance allows to get the plain JSON
data, the number of available results and also to iterate over chunks of
results (which the NVD API is always returning).

Most important improvement the NVDResults instance keeps the state. That
means if an http error occurs it is possible to request the same data
again. With the old API the requests need to start from the beginning if
something did go wrong. For example if we downloaded already 100k CVEs
and a http error was raised we needed to start from CVE number 1 again.
With the new implementation we can just continue with the last request
again.
Copy link

codecov bot commented Nov 29, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (1ebde9f) 90.38% compared to head (0b6b52b) 90.51%.

Files Patch % Lines
pontos/nvd/api.py 95.29% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #936      +/-   ##
==========================================
+ Coverage   90.38%   90.51%   +0.13%     
==========================================
  Files          97       97              
  Lines        6778     6814      +36     
  Branches      976      973       -3     
==========================================
+ Hits         6126     6168      +42     
+ Misses        446      445       -1     
+ Partials      206      201       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@greenbonebot greenbonebot merged commit 7913e97 into main Nov 30, 2023
21 checks passed
@greenbonebot greenbonebot deleted the nvd-api-rework branch November 30, 2023 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants