/vendor/plugins/surecheck_upload/lib/surecheck_upload/filters.rb

https://github.com/williamhall/dradisframework · Ruby · 68 lines · 42 code · 17 blank · 9 comment · 3 complexity · 35e436157cc2fd2fff3239b9227cbfa8 MD5 · raw file

  1. module SurecheckUpload
  2. private
  3. @@logger=nil
  4. public
  5. # This method will be called by the framework when the user selects your
  6. # plugin from the drop down list of the 'Import from file' dialog
  7. def self.import(params={})
  8. @@logger = params.fetch(:logger, Rails.logger)
  9. @@logger.info{ 'Parsing SureCheck output...' }
  10. screport = Surecheck::Parser.parsefile( params[:file] )
  11. @@logger.info{ 'Done.' }
  12. category = Category.find_by_name(Configuration.category)
  13. sc_node = Node.create( :label => Configuration.node_label)
  14. screport.findings.each do |finding|
  15. @@logger.info{ "Adding SureCheck Finding \##{finding.id.to_s}" }
  16. finding_detail = ''
  17. if finding.title
  18. finding_detail << "#[Title]#\n"
  19. finding_detail << finding.title
  20. finding_detail << "\n\n"
  21. end
  22. if finding.severity
  23. finding_detail << "\n#[Severity]#\n"
  24. finding_detail << finding.severity_before_type_cast
  25. finding_detail << "\n\n"
  26. end
  27. #finding_detail << "\n#[Priority]#\n"
  28. #finding_detail << issue.priority.to_s if issue.priority
  29. #finding_detail << "\n#[Content]#\n" if finding.content
  30. if finding.content
  31. # Convert section headers (e.g. ==Description==) into the Dradis format
  32. # (e.g. #[Description]#)
  33. content = finding.content.gsub(/==[\s]?(\w+)[\s]?==/) {|s| "\n#[" + $1.capitalize + "]#"}
  34. # Remove hypelink markup
  35. content.gsub!(/:\[\[(.+?)\]\]/) { $1 }
  36. # Remove table markup
  37. content.gsub!(/<<table-columns 10,90>>/, '')
  38. content.gsub!(/\|=\s(\w+?)\s\|\s##([\w\s\\]+?)##/) { "#{$1}: #{$2}" }
  39. finding_detail << content
  40. end
  41. Note.create(
  42. :node => sc_node,
  43. :author => Configuration.author,
  44. :category => category,
  45. :text => finding_detail.to_s
  46. )
  47. end
  48. @@logger.info{ 'SureCheck results successfully imported' }
  49. return true
  50. end
  51. end