11import os
22import urllib .request
3- import saneyaml
4-
3+ from itertools import chain
54from shutil import rmtree
65from urllib .error import HTTPError
76from zipfile import ZipFile
8- from itertools import chain
7+
8+ import saneyaml
99from dephell_specifier import RangeSpecifier
1010
1111RUBYCVE_LINK = 'https://github.com/rubysec/ruby-advisory-db/archive/master.zip'
1212DOWNLOAD_PATH = os .path .dirname (os .path .realpath (__file__ ))
1313
1414
1515def get_rubycve_db ():
16- pathToZip , _ = urllib .request .urlretrieve (
16+ path_to_zip , _ = urllib .request .urlretrieve (
1717 RUBYCVE_LINK , os .path .join (
1818 DOWNLOAD_PATH , 'ruby.zip' ))
19- ZipFile (pathToZip ).extractall (DOWNLOAD_PATH )
20- os .remove (pathToZip )
19+ ZipFile (path_to_zip ).extractall (DOWNLOAD_PATH )
20+ os .remove (path_to_zip )
2121
2222
2323def path_of_yaml_of_all_packages ():
24- gemPath = os .path .join (DOWNLOAD_PATH , 'ruby-advisory-db-master' , 'gems' )
25- rubiesPath = os .path .join (
24+ gem_path = os .path .join (DOWNLOAD_PATH , 'ruby-advisory-db-master' , 'gems' )
25+ rubies_path = os .path .join (
2626 DOWNLOAD_PATH ,
2727 'ruby-advisory-db-master' ,
2828 'rubies' )
2929 for (
30- packagePath ,
30+ package_path ,
3131 _ ,
32- yamlNames ) in chain (
33- os .walk (gemPath ),
34- os .walk (rubiesPath )):
35- for yamlName in yamlNames :
36- yield os .path .join (packagePath , yamlName )
32+ yaml_names ) in chain (
33+ os .walk (gem_path ),
34+ os .walk (rubies_path )):
35+ for yaml_name in yaml_names :
36+ yield os .path .join (package_path , yaml_name )
3737
3838
3939def get_all_versions_of_package (package_name ):
@@ -64,8 +64,8 @@ def import_vulnerabilities():
6464 ids = set ()
6565 vulnerability_to_package_map = []
6666 for vulnerability_path in path_of_yaml_of_all_packages ():
67- with open (vulnerability_path ) as yamlFile :
68- vulnerability = saneyaml .load (yamlFile )
67+ with open (vulnerability_path ) as yaml_file :
68+ vulnerability = saneyaml .load (yaml_file )
6969 package_name = vulnerability .get (
7070 'engine' , vulnerability .get ('gem' ))
7171 summary = vulnerability .get ('description' , '' )
@@ -78,27 +78,27 @@ def import_vulnerabilities():
7878 continue
7979 severity = vulnerability .get (
8080 'cvss_v3' , vulnerability .get ('cvss_v2' ))
81- advisoryUrl = vulnerability .get ('url' )
81+ advisory_url = vulnerability .get ('url' )
8282 specs = list (
8383 get_patched_range (
8484 vulnerability .get ('patched_versions' )))
85- allVersions = set (list (get_all_versions_of_package (package_name )))
85+ all_versions = set (list (get_all_versions_of_package (package_name )))
8686 unaffected_versions = set ()
8787 if specs :
88- for version in allVersions :
88+ for version in all_versions :
8989 for spec in specs :
90- if ( version in spec ) :
90+ if version in spec :
9191 unaffected_versions .add (version )
9292 break
93- affected_versions = allVersions - unaffected_versions
93+ affected_versions = all_versions - unaffected_versions
9494 vulnerability_to_package_map .append ({
9595 'package_name' : package_name ,
9696 'summary' : summary ,
9797 'cve_id' : vulnerability_id ,
9898 'fixed_versions' : unaffected_versions ,
9999 'affected_versions' : affected_versions ,
100100 'severity' : severity ,
101- 'advisory' : advisoryUrl
101+ 'advisory' : advisory_url
102102 })
103103 rmtree (os .path .join (DOWNLOAD_PATH , 'ruby-advisory-db-master' ))
104104 return vulnerability_to_package_map
0 commit comments