-
-
Notifications
You must be signed in to change notification settings - Fork 233
Add base pipeline for importers and migrate PyPa importer to aboutcode pipeline #1559
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ec59d7a
Add base importer pipeline
keshav-space 48e8527
Migrate PyPa importer to aboutcode pipeline
keshav-space 29d96d3
Add step to import newly collected advisory
keshav-space 3ea12c3
Add test for base and pypa importer pipeline
keshav-space bb5c006
Do not keep new advisories in memory while importing
keshav-space ce1ea4c
Fix failing test
keshav-space 6b8b978
Add docstring for get_advisory_url
keshav-space 1c39cc1
Inline test fixtures
keshav-space d73cfd4
Log the full stack trace on error
keshav-space File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# | ||
# Copyright (c) nexB Inc. and others. All rights reserved. | ||
# VulnerableCode is a trademark of nexB Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text. | ||
# See https://github.com/nexB/vulnerablecode for support or download. | ||
# See https://aboutcode.org for more information about nexB OSS projects. | ||
# | ||
import logging | ||
from pathlib import Path | ||
from typing import Iterable | ||
|
||
import saneyaml | ||
from fetchcode.vcs import fetch_via_vcs | ||
|
||
from vulnerabilities.importer import AdvisoryData | ||
from vulnerabilities.importers.osv import parse_advisory_data | ||
from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipeline | ||
from vulnerabilities.utils import get_advisory_url | ||
|
||
module_logger = logging.getLogger(__name__) | ||
|
||
|
||
class PyPaImporterPipeline(VulnerableCodeBaseImporterPipeline): | ||
"""Collect advisories from PyPA GitHub repository.""" | ||
|
||
spdx_license_expression = "CC-BY-4.0" | ||
license_url = "https://github.com/pypa/advisory-database/blob/main/LICENSE" | ||
repo_url = "git+https://github.com/pypa/advisory-database" | ||
importer_name = "Pypa Importer" | ||
|
||
@classmethod | ||
def steps(cls): | ||
return ( | ||
cls.clone, | ||
cls.collect_and_store_advisories, | ||
cls.import_new_advisories, | ||
cls.clean_downloads, | ||
) | ||
|
||
def clone(self): | ||
self.log(f"Cloning `{self.repo_url}`") | ||
self.vcs_response = fetch_via_vcs(self.repo_url) | ||
|
||
def advisories_count(self): | ||
vulns_directory = Path(self.vcs_response.dest_dir) / "vulns" | ||
return sum(1 for _ in vulns_directory.rglob("*.yaml")) | ||
|
||
def collect_advisories(self) -> Iterable[AdvisoryData]: | ||
base_directory = Path(self.vcs_response.dest_dir) | ||
vulns_directory = base_directory / "vulns" | ||
self.advisories_count = sum(1 for _ in vulns_directory.rglob("*.yaml")) | ||
|
||
for advisory in vulns_directory.rglob("*.yaml"): | ||
advisory_url = get_advisory_url( | ||
file=advisory, | ||
base_path=base_directory, | ||
url="https://github.com/pypa/advisory-database/blob/main/", | ||
) | ||
advisory_dict = saneyaml.load(advisory.read_text()) | ||
yield parse_advisory_data( | ||
raw_data=advisory_dict, | ||
supported_ecosystems=["pypi"], | ||
advisory_url=advisory_url, | ||
) | ||
|
||
def clean_downloads(self): | ||
if self.vcs_response: | ||
self.log(f"Removing cloned repository") | ||
self.vcs_response.delete() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.