Class: Dradis::Plugins::CSV::Importer

Inherits:
Upload::Importer
  • Object
show all
Defined in:
lib/dradis/plugins/csv/importer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.templatesObject



3
4
5
# File 'lib/dradis/plugins/csv/importer.rb', line 3

def self.templates
  {}
end

Instance Method Details

#import(params = {}) ⇒ Object



7
8
9
10
11
# File 'lib/dradis/plugins/csv/importer.rb', line 7

def import(params={})
  logger.info { 'Uploading CSV file...' }

  logger.info { 'Done' }
end

#import_csv(params) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dradis/plugins/csv/importer.rb', line 13

def import_csv(params)
  logger.info { 'Worker process starting background task.' }

  mappings_groups = params[:mappings].group_by { |index, mapping| mapping['type'] }

  filename = File.basename(params[:file])
  id_index = Integer(mappings_groups['identifier']&.first&.first, exception: false)
  @evidence_mappings = mappings_groups['evidence'] || []
  @issue_lookup = {}
  @issue_mappings = mappings_groups['issue'] || []
  @node_index = Integer(mappings_groups['node']&.first&.first, exception: false)


  CSV.foreach(params[:file], headers: true).with_index do |row, index|
    csv_id = row[id_index] || "#{filename}-#{index}"
    process_issue(csv_id: csv_id, row: row)
    process_node(csv_id: csv_id, row: row)
  end

  true
end