11#
2- # Copyright (c) 2017 nexB Inc. and others. All rights reserved.
2+ # Copyright (c) nexB Inc. and others. All rights reserved.
33# http://nexb.com and https://github.com/nexB/vulnerablecode/
44# The VulnerableCode software is licensed under the Apache License version 2.0.
55# Data generated with VulnerableCode require an acknowledgment.
1818# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
1919# VulnerableCode should be considered or used as legal advice. Consult an Attorney
2020# for any legal advice.
21- # VulnerableCode is a free software code scanning tool from nexB Inc. and others.
21+ # VulnerableCode is a free software tool from nexB Inc. and others.
2222# Visit https://github.com/nexB/vulnerablecode/ for support and download.
2323
2424import importlib
@@ -39,11 +39,10 @@ class Vulnerability(models.Model):
3939 A software vulnerability with minimal information. Identifiers other than CVE ID are stored as
4040 VulnerabilityReference.
4141 """
42- cve_id = models .CharField (
43- max_length = 50 , help_text = 'CVE ID' , unique = True , null = True )
44- summary = models .TextField (
45- help_text = 'Summary of the vulnerability' , blank = True )
46- cvss = models .FloatField (max_length = 100 , help_text = 'CVSS Score' , null = True )
42+
43+ cve_id = models .CharField (max_length = 50 , help_text = "CVE ID" , unique = True , null = True )
44+ summary = models .TextField (help_text = "Summary of the vulnerability" , blank = True )
45+ cvss = models .FloatField (max_length = 100 , help_text = "CVSS Score" , null = True )
4746
4847 @property
4948 def vulnerable_to (self ):
@@ -57,36 +56,37 @@ def __str__(self):
5756 return self .cve_id or self .summary
5857
5958 class Meta :
60- verbose_name_plural = ' Vulnerabilities'
59+ verbose_name_plural = " Vulnerabilities"
6160
6261
6362class VulnerabilityReference (models .Model ):
6463 """
6564 A reference to a vulnerability such as a security advisory from a Linux distribution or language
6665 package manager.
6766 """
68- vulnerability = models .ForeignKey (
69- Vulnerability , on_delete = models .CASCADE )
70- source = models .CharField (
71- max_length = 50 , help_text = 'Source(s) name eg:NVD' , blank = True )
67+
68+ vulnerability = models .ForeignKey (Vulnerability , on_delete = models .CASCADE )
69+ source = models .CharField (max_length = 50 , help_text = "Source(s) name eg:NVD" , blank = True )
7270 reference_id = models .CharField (
73- max_length = 50 , help_text = ' Reference ID, eg:DSA-4465-1' , blank = True )
74- url = models . URLField (
75- max_length = 1024 , help_text = ' URL of Vulnerability data' , blank = True )
71+ max_length = 50 , help_text = " Reference ID, eg:DSA-4465-1" , blank = True
72+ )
73+ url = models . URLField ( max_length = 1024 , help_text = " URL of Vulnerability data" , blank = True )
7674
7775 class Meta :
78- unique_together = (' vulnerability' , ' source' , ' reference_id' , ' url' )
76+ unique_together = (" vulnerability" , " source" , " reference_id" , " url" )
7977
8078 def __str__ (self ):
81- return f' { self .source } { self .reference_id } { self .url } '
79+ return f" { self .source } { self .reference_id } { self .url } "
8280
8381
8482class Package (PackageURLMixin ):
8583 """
8684 A software package with links to relevant vulnerabilities.
8785 """
86+
8887 vulnerabilities = models .ManyToManyField (
89- to = 'Vulnerability' , through = 'PackageRelatedVulnerability' )
88+ to = "Vulnerability" , through = "PackageRelatedVulnerability"
89+ )
9090
9191 @property
9292 def vulnerable_to (self ):
@@ -97,17 +97,17 @@ def resolved_to(self):
9797 return self .packagerelatedvulnerability_set .filter (is_vulnerable = False )
9898
9999 class Meta :
100- unique_together = (' name' , ' namespace' , ' type' ,
101- 'version' , 'qualifiers' , 'subpath' )
100+ unique_together = (" name" , " namespace" , " type" , "version" , "qualifiers" , "subpath" )
101+
102102 # Remove the `qualifers` and `set_package_url` overrides after
103103 # https://github.com/package-url/packageurl-python/pull/35 gets merged
104104 qualifiers = pgfields .JSONField (
105105 default = dict ,
106106 help_text = _ (
107- ' Extra qualifying data for a package such as the name of an OS, '
108- ' architecture, distro, etc.'
107+ " Extra qualifying data for a package such as the name of an OS, "
108+ " architecture, distro, etc."
109109 ),
110- null = True
110+ null = True ,
111111 )
112112
113113 def set_package_url (self , package_url ):
@@ -123,8 +123,7 @@ def set_package_url(self, package_url):
123123 model_field = self ._meta .get_field (field_name )
124124
125125 if value and len (value ) > model_field .max_length :
126- raise ValidationError (
127- _ ('Value too long for field "{}".' .format (field_name )))
126+ raise ValidationError (_ ('Value too long for field "{}".' .format (field_name )))
128127
129128 setattr (self , field_name , value or None )
130129
@@ -142,7 +141,7 @@ class Meta:
142141 # Technically 'is_vulnerable' doesn't belong here. The idea is to
143142 # later filter out for a pairs of ('package', 'vulnerability') which have both
144143 # values of 'is_vulnerable' and ping the data providers to resolve such entries.
145- unique_together = (' package' , ' vulnerability' , ' is_vulnerable' )
144+ unique_together = (" package" , " vulnerability" , " is_vulnerable" )
146145
147146
148147class ImportProblem (models .Model ):
@@ -155,26 +154,23 @@ class Importer(models.Model):
155154 Metadata and pointer to the implementation for a source of vulnerability data (aka security
156155 advisories)
157156 """
158- name = models . CharField ( max_length = 100 , unique = True ,
159- help_text = ' Name of the importer' )
157+
158+ name = models . CharField ( max_length = 100 , unique = True , help_text = " Name of the importer" )
160159
161160 license = models .CharField (
162- max_length = 100 ,
163- blank = True ,
164- help_text = 'License of the vulnerability data' ,
161+ max_length = 100 , blank = True , help_text = "License of the vulnerability data" ,
165162 )
166163
167- last_run = models .DateTimeField (
168- null = True , help_text = 'UTC Timestamp of the last run' )
164+ last_run = models .DateTimeField (null = True , help_text = "UTC Timestamp of the last run" )
169165
170166 data_source = models .CharField (
171167 max_length = 100 ,
172- help_text = ' Name of the data source implementation importable from vulnerabilities.importers'
168+ help_text = " Name of the data source implementation importable from vulnerabilities.importers" , # nopep8
173169 )
174170 data_source_cfg = pgfields .JSONField (
175171 null = False ,
176172 default = dict ,
177- help_text = ' Implementation-specific configuration for the data source' ,
173+ help_text = " Implementation-specific configuration for the data source" ,
178174 )
179175
180176 def make_data_source (self , batch_size : int , cutoff_date : datetime = None ) -> DataSource :
@@ -184,7 +180,7 @@ def make_data_source(self, batch_size: int, cutoff_date: datetime = None) -> Dat
184180 batch_size - max. number of records to return on each iteration
185181 cutoff_date - optional timestamp of the oldest data to include in the import
186182 """
187- importers_module = importlib .import_module (' vulnerabilities.importers' )
183+ importers_module = importlib .import_module (" vulnerabilities.importers" )
188184 klass = getattr (importers_module , self .data_source )
189185
190186 ds = klass (
0 commit comments