module Dradis::Plugins::ContentService::Core

Attributes

logger[RW]
plugin[RW]
project[RW]
scope[RW]

Public Class Methods

new(args={}) click to toggle source

@option plugin [Class] the ‘wrapper’ module of a plugin, e.g.

Dradis::Plugins::Nessus
# File lib/dradis/plugins/content_service/core.rb, line 14
def initialize(args={})
  @logger = args.fetch(:logger, Rails.logger)
  @plugin = args.fetch(:plugin)
  @project = args[:project]
  @scope = validate_scope(args[:scope]).to_sym
  @state = args[:state]
end

Private Instance Methods

default_author() click to toggle source
# File lib/dradis/plugins/content_service/core.rb, line 24
def default_author
  @default_author ||= "#{plugin::Engine.plugin_name.to_s.humanize} upload plugin"
end
try_rescue_from_length_validation(args={}) click to toggle source
# File lib/dradis/plugins/content_service/core.rb, line 28
def try_rescue_from_length_validation(args={})
  model = args[:model]
  field = args[:field]
  text  = args[:text]
  msg   = args[:msg]
  tail  = "..." + args[:tail].to_s

  logger.error{ "Trying to rescue from a :length error" }

  if model.errors[field]
    # the plugin tried to store too much information
    msg = "#[Title]#\nTruncation warning!\n\n"
    msg << "#[Error]#\np(alert alert-error). The plugin tried to store content that was too big for the DB. Review the source to ensure no important data was lost.\n\n"
    msg << text
    model.send("#{field}=", msg.truncate(65300, omission: tail))
  else
    # bail
    msg = "#[Title]#\n#{msg}\n\n"
    msg << "#[Description]#\nbc. #{model.errors.inspect}\n\n"
    model.send("#{field}=", msg)
  end
  if model.valid?
    model.save
  end
end
validate_scope(scope) click to toggle source
# File lib/dradis/plugins/content_service/core.rb, line 54
def validate_scope(scope)
  valid_scopes = Dradis::Plugins::ContentService::Base::VALID_SCOPES
  if scope && valid_scopes.include?(scope.to_s)
    scope
  else
    :published
  end
end