Skip to content

Commit 1df13c6

Browse files
committed
wip
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 2a08e55 commit 1df13c6

File tree

12 files changed

+61
-5
lines changed

12 files changed

+61
-5
lines changed

vulnerabilities/importers/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from vulnerabilities.importers import ubuntu_usn
3333
from vulnerabilities.importers import vulnrichment
3434
from vulnerabilities.importers import xen
35+
from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipelineV2
3536
from vulnerabilities.pipelines import alpine_linux_importer
3637
from vulnerabilities.pipelines import github_importer
3738
from vulnerabilities.pipelines import gitlab_importer
@@ -189,3 +190,9 @@
189190
collect_fix_commits_v2.CollectGitlabFixCommitsPipeline,
190191
]
191192
)
193+
194+
TODO_EXCLUDED_PIPELINES = [
195+
key
196+
for key, value in IMPORTERS_REGISTRY.items()
197+
if issubclass(value, VulnerableCodeBaseImporterPipelineV2) and value.exclude_from_package_todo
198+
]

vulnerabilities/models.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,11 +2877,7 @@ def latest_for_avid(self, avid: str):
28772877
)
28782878

28792879
def latest_per_avid(self):
2880-
return self.order_by(
2881-
"avid",
2882-
F("date_collected").desc(nulls_last=True),
2883-
"-id",
2884-
).distinct("avid")
2880+
return self.filter(is_latest=True)
28852881

28862882
def latest_for_avids(self, avids):
28872883
return self.filter(avid__in=avids).latest_per_avid()
@@ -2953,6 +2949,12 @@ def latest_advisories_for_purl(self, purl):
29532949
qs = self.filter(id__in=Subquery(adv_ids))
29542950
return qs.latest_per_avid()
29552951

2952+
def todo_excluded(self):
2953+
"""Exclude advisory ineligible for ToDo computation."""
2954+
from vulnerabilities.importers import TODO_EXCLUDED_PIPELINES
2955+
2956+
return self.exclude(datasource_id__in=TODO_EXCLUDED_PIPELINES)
2957+
29562958

29572959
class AdvisorySet(models.Model):
29582960

@@ -2998,6 +3000,7 @@ class AdvisoryV2(models.Model):
29983000
max_length=200,
29993001
blank=False,
30003002
null=False,
3003+
db_index=True,
30013004
help_text="Unique ID for the datasource used for this advisory ." "e.g.: nginx_importer_v2",
30023005
)
30033006

@@ -3081,6 +3084,14 @@ class AdvisoryV2(models.Model):
30813084
help_text="UTC Date on which the advisory was collected",
30823085
)
30833086

3087+
is_latest = models.BooleanField(
3088+
default=False,
3089+
blank=False,
3090+
null=False,
3091+
db_index=True,
3092+
help_text="Indicates whether this is the latest version of the advisory identified by its AVID.",
3093+
)
3094+
30843095
original_advisory_text = models.TextField(
30853096
blank=True,
30863097
null=True,
@@ -3133,6 +3144,11 @@ class AdvisoryV2(models.Model):
31333144
class Meta:
31343145
unique_together = ["datasource_id", "advisory_id", "unique_content_id"]
31353146
ordering = ["datasource_id", "advisory_id", "date_published", "unique_content_id"]
3147+
constraints = [
3148+
models.UniqueConstraint(
3149+
fields=["avid"], condition=Q(is_latest=True), name="unique_latest_per_avid"
3150+
)
3151+
]
31363152
indexes = [
31373153
models.Index(
31383154
fields=["avid", "-date_collected", "-id"],

vulnerabilities/pipelines/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ class VulnerableCodeBaseImporterPipelineV2(VulnerableCodePipeline):
278278
ignorable_versions = []
279279
precedence = 0
280280

281+
# Set this to True if computing fixed/affected package ToDo is not fruitful for this source.
282+
# An example of such advisory would be pipeline dedicated to collecting issues,
283+
# pull requests, commit messages, EPSS, exploits, etc.
284+
exclude_from_package_todo = False
285+
281286
# Control how often progress log is shown (range: 1–100, higher value = less frequent log)
282287
progress_step = 10
283288

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# VulnerableCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#

vulnerabilities/pipelines/v2_importers/aosp_importer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class AospImporterPipeline(VulnerableCodeBaseImporterPipelineV2):
3232
license_url = "https://github.com/quarkslab/aosp_dataset/blob/master/LICENSE"
3333

3434
precedence = 200
35+
exclude_from_package_todo = True
3536

3637
@classmethod
3738
def steps(cls):

vulnerabilities/pipelines/v2_importers/epss_importer_v2.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class EPSSImporterPipeline(VulnerableCodeBaseImporterPipelineV2):
3030
spdx_license_expression = "unknown"
3131
importer_name = "EPSS Importer"
3232

33+
exclude_from_package_todo = True
34+
3335
precedence = 200
3436

3537
def advisories_count(self):

vulnerabilities/pipelines/v2_importers/nvd_importer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class NVDImporterPipeline(VulnerableCodeBaseImporterPipelineV2):
7171
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
7272
"""
7373

74+
exclude_from_package_todo = True
75+
7476
precedence = 100
7577

7678
@classmethod

vulnerabilities/pipelines/v2_importers/project_kb_msr2019_importer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class ProjectKBMSR2019Pipeline(VulnerableCodeBaseImporterPipelineV2):
3030
license_url = "https://github.com/SAP/project-kb/blob/main/LICENSE.txt"
3131
repo_url = "git+https://github.com/SAP/project-kb"
3232

33+
exclude_from_package_todo = True
34+
3335
precedence = 200
3436

3537
@classmethod

vulnerabilities/pipelines/v2_importers/project_kb_statements_importer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class ProjectKBStatementsPipeline(VulnerableCodeBaseImporterPipelineV2):
3737
license_url = "https://github.com/SAP/project-kb/blob/main/LICENSE.txt"
3838
repo_url = "git+https://github.com/SAP/project-kb@vulnerability-data"
3939

40+
exclude_from_package_todo = True
41+
4042
precedence = 200
4143

4244
@classmethod

vulnerabilities/pipelines/v2_importers/suse_score_importer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class SUSESeverityScoreImporterPipeline(VulnerableCodeBaseImporterPipelineV2):
2323
pipeline_id = "suse_importer_v2"
2424
url = "https://ftp.suse.com/pub/projects/security/yaml/suse-cvss-scores.yaml"
2525

26+
exclude_from_package_todo = True
27+
2628
@classmethod
2729
def steps(cls):
2830
return (

0 commit comments

Comments
 (0)