-
-
Notifications
You must be signed in to change notification settings - Fork 237
Add PySec Live V2 Importer Pipeline #1983
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
base: main
Are you sure you want to change the base?
Conversation
* Add PySec Live V2 Importer * Add tests for the PySec Live V2 Importer * Tested functionally using the Live Evaluation API in #1969 Signed-off-by: Michael Ehab Mikhail <[email protected]>
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.
@michaelehab Great job 👍 A few functions could be refactored to improve readability.
from vulnerabilities.pipelines.v2_importers.pysec_live_importer import PySecLiveImporterPipeline | ||
|
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.
Move import PySecLiveImporterPipeline to the top of the test
from vulnerabilities.pipelines.v2_importers.pysec_live_importer import PySecLiveImporterPipeline |
|
||
|
||
def test_package_with_version_not_affected(mock_zip_data): | ||
from vulnerabilities.pipelines.v2_importers.pysec_live_importer import PySecLiveImporterPipeline |
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.
from vulnerabilities.pipelines.v2_importers.pysec_live_importer import PySecLiveImporterPipeline |
from vulnerabilities.pipelines.v2_importers.pysec_live_importer import PySecLiveImporterPipeline | ||
|
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.
from vulnerabilities.pipelines.v2_importers.pysec_live_importer import PySecLiveImporterPipeline |
if not file_name.startswith("PYSEC-"): | ||
continue | ||
with zip_file.open(file_name) as f: | ||
import json |
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.
Move import json
to the top
try: | ||
v = PypiVersion(version) | ||
except Exception: | ||
return False |
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.
Catch only InvalidVersion instead of all errors.
return False | ||
for entry in affected: | ||
ranges = entry.get("ranges", []) | ||
for r in ranges: |
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.
r in for r in ranges: could be renamed to something clearer like version_range/data_range for readability.
ranges = entry.get("ranges", []) | ||
for r in ranges: |
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.
ranges = entry.get("ranges", []) | |
for r in ranges: | |
for event in r.get("events", []): |
events = r.get("events", []) | ||
introduced = None | ||
fixed = None | ||
for event in events: |
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.
for event in events: | |
for event in r.get("events", []): |
for entry in affected: | ||
ranges = entry.get("ranges", []) | ||
for r in ranges: | ||
events = r.get("events", []) |
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.
events = r.get("events", []) |
if not self._is_version_affected(advisory_dict, self.purl.version): | ||
continue | ||
|
||
f.seek(0) |
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.
Why do we need f.seek(0)
here? Could we just read the file once instead?
Solves #1981
Add PySec Live V2 Importer
Add tests for the PySec Live V2 Importer
Tested functionally using the Live Evaluation API in Add Live Evaluation API endpoint and PyPa live pipeline importer #1969