module Dradis::Plugins::Upload

Public Class Methods

new(args={}) click to toggle source
# File lib/dradis/plugins/upload/importer.rb, line 23
def initialize(args={})
  @options = args

  @default_user_id = args[:default_user_id] || -1
  @logger = args.fetch(:logger, Rails.logger)
  @plugin = args[:plugin] || default_plugin
  @project = args.key?(:project_id) ? Project.find(args[:project_id]) : nil
  @state = args.fetch(:state, :published)

  @content_service   = args.fetch(:content_service, default_content_service)
  @mapping_service   = default_mapping_service

  post_initialize(args)
end

Public Instance Methods

import(args={}) click to toggle source
# File lib/dradis/plugins/upload/importer.rb, line 38
def import(args={})
  raise "The import() method is not implemented in this plugin [#{self.class.name}]."
end
post_initialize(args={}) click to toggle source

This method can be overwriten by plugins to do initialization tasks.

# File lib/dradis/plugins/upload/importer.rb, line 43
def post_initialize(args={})
end

Private Instance Methods

default_content_service() click to toggle source
# File lib/dradis/plugins/upload/importer.rb, line 47
def default_content_service
  @content ||= Dradis::Plugins::ContentService::Base.new(
    logger: logger,
    plugin: plugin,
    project: project,
    state: state
  )
end
default_mapping_service() click to toggle source
# File lib/dradis/plugins/upload/importer.rb, line 74
def default_mapping_service
  rtp = project.report_template_properties if project
  destination = rtp ? rtp.as_mapping_destination : nil

  Dradis::Plugins::MappingService.new(
    destination: destination,
    integration: plugin
  )
end
default_plugin() click to toggle source

This assumes the plugin’s Importer class is directly nexted into the plugin’s namespace (e.g. Dradis::Plugins::Nessus::Importer)

# File lib/dradis/plugins/upload/importer.rb, line 58
def default_plugin
  plugin_module   = self.class.name.deconstantize
  plugin_constant = plugin_module.constantize

  if defined?(plugin_constant::Engine)
    plugin_engine   = plugin_constant::Engine
    if Dradis::Plugins.registered?(plugin_engine)
      plugin_constant
    else
      raise "Your plugin isn't registered with the framework."
    end
  else
    raise "You need to pass a :plugin value to your Importer or define it under your plugin's root namespace."
  end
end