Class: Dradis::Plugins::Brakeman::Importer

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.templatesObject



4
5
6
# File 'lib/dradis/plugins/brakeman/importer.rb', line 4

def self.templates
  { issue: 'warning' }
end

Instance Method Details

#import(params = {}) ⇒ Object

The framework will call this function if the user selects this plugin from the dropdown list and uploads a file.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dradis/plugins/brakeman/importer.rb', line 11

def import(params={})

  file_content = File.read( params[:file] )

  # Parse the uploaded file into a Ruby Hash
  logger.info { "Parsing Brakeman output from #{ params[:file] }..." }
  data = MultiJson.decode(file_content)
  logger.info { 'Done.' }

  unless data.key?("scan_info")
    logger.error "ERROR: no 'scan_info' field present in the provided "\
                 "data. Are you sure you uploaded a Brakeman file?"
    exit(-1)
  end

  # choose a different parent based on the application path?
  scan_info = template_service.process_template(template: 'scan_info', data: data['scan_info'])
  content_service.create_note text: scan_info

  logger.info { "#{data['warnings'].count} Warnings\n===========" }

  data['warnings'].each do |warning|
    logger.info { "* [#{warning['warning_type']}] #{warning['message']}" }

    warning_info = template_service.process_template(template: 'warning', data: warning)
    content_service.create_issue text: warning_info, id: warning['warning_code']
  end

end