3232
3333
3434class Command (BaseCommand ):
35- help = ' Import vulnerability data'
35+ help = " Import vulnerability data"
3636
3737 def add_arguments (self , parser ):
3838 parser .add_argument (
39- '--list' ,
40- action = 'store_true' ,
41- help = 'List available data sources' ,
39+ "--list" ,
40+ action = "store_true" ,
41+ help = "List available data sources" ,
42+ )
43+ parser .add_argument (
44+ "--all" , action = "store_true" , help = "Import data from all available sources"
4245 )
43- parser .add_argument ('--all' , action = 'store_true' ,
44- help = 'Import data from all available sources' )
4546
4647 parser .add_argument (
47- ' --cutoff-date' ,
48+ " --cutoff-date" ,
4849 type = datetime .fromisoformat ,
49- help = ' ISO8601 formatted timestamp denoting the maximum age of vulnerability '
50- ' information to import.' ,
50+ help = " ISO8601 formatted timestamp denoting the maximum age of vulnerability "
51+ " information to import." ,
5152 )
52- parser .add_argument ('sources' , nargs = '*' ,
53- help = 'Data sources from which to import' )
53+ parser .add_argument ("sources" , nargs = "*" , help = "Data sources from which to import" )
5454
5555 parser .add_argument (
56- '--batch_size' , help = 'The batch size to be used for bulk inserting data' )
56+ "--batch_size" , help = "The batch size to be used for bulk inserting data"
57+ )
58+
59+ parser .add_argument (
60+ "--cv" ,
61+ action = "store_true" ,
62+ help = "This will import and assign id's to vulnerabilities without any identifiers" ,
63+ )
5764
5865 def handle (self , * args , ** options ):
5966 # load_importers() seeds the DB with Importers
6067 load_importers ()
61- if options [' list' ]:
68+ if options [" list" ]:
6269 self .list_sources ()
6370 return
6471
65- if options ['batch_size' ]:
66- self .batch_size = options ['batch_size' ]
72+ if options ["batch_size" ]:
73+ self .batch_size = options ["batch_size" ]
74+
75+ self .create_vulcodes = options ["cv" ]
6776
68- if options [' all' ]:
69- self ._import_data (Importer .objects .all (), options [' cutoff_date' ])
77+ if options [" all" ]:
78+ self ._import_data (Importer .objects .all (), options [" cutoff_date" ])
7079 return
7180
72- sources = options [' sources' ]
81+ sources = options [" sources" ]
7382 if not sources :
7483 raise CommandError (
75- 'Please provide at least one data source to import from or use "--all".' )
84+ 'Please provide at least one data source to import from or use "--all".'
85+ )
7686
77- self .import_data (sources , options [' cutoff_date' ])
87+ self .import_data (sources , options [" cutoff_date" ])
7888
7989 def list_sources (self ):
8090 importers = Importer .objects .all ()
81- self .stdout .write (
82- 'Vulnerability data can be imported from the following sources:' )
83- self .stdout .write (', ' .join ([i .name for i in importers ]))
91+ self .stdout .write ("Vulnerability data can be imported from the following sources:" )
92+ self .stdout .write (", " .join ([i .name for i in importers ]))
8493
8594 def import_data (self , names , cutoff_date ):
8695 importers = []
@@ -93,15 +102,18 @@ def import_data(self, names, cutoff_date):
93102 unknown_importers .add (name )
94103
95104 if unknown_importers :
96- unknown_importers = ', ' .join (unknown_importers )
97- raise CommandError (f' Unknown data sources: { unknown_importers } ' )
105+ unknown_importers = ", " .join (unknown_importers )
106+ raise CommandError (f" Unknown data sources: { unknown_importers } " )
98107
99108 self ._import_data (importers , cutoff_date )
100109
101110 def _import_data (self , importers , cutoff_date ):
102111 for importer in importers :
103- self .stdout .write (f'Importing data from { importer .name } ' )
104- batch_size = int (getattr (self , 'batch_size' , 10 ))
105- ImportRunner (importer , batch_size ).run (cutoff_date = cutoff_date )
112+ self .stdout .write (f"Importing data from { importer .name } " )
113+ batch_size = int (getattr (self , "batch_size" , 10 ))
114+ ImportRunner (importer , batch_size ).run (
115+ cutoff_date = cutoff_date , create_vulcodes = self .create_vulcodes
116+ )
106117 self .stdout .write (
107- self .style .SUCCESS (f'Successfully imported data from { importer .name } ' ))
118+ self .style .SUCCESS (f"Successfully imported data from { importer .name } " )
119+ )
0 commit comments