Sha256: 7190f421183213749bc073fbd4fcf4c3aac2b5570867b7b52bd799f1d6abcfd7

Contents?: true

Size: 1.8 KB

Versions: 2

Compression:

Stored size: 1.8 KB

Contents

module Dradis::Plugins::ContentService
  module Core
    extend ActiveSupport::Concern

    included do
      attr_accessor :logger, :plugin, :project, :scope
    end

    # ----------------------------------------------------------- Initializer
    #

    # @option plugin [Class] the 'wrapper' module of a plugin, e.g.
    #     Dradis::Plugins::Nessus
    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

    def default_author
      @default_author ||= "#{plugin::Engine.plugin_name.to_s.humanize} upload plugin"
    end

    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

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dradis-plugins-4.14.0 lib/dradis/plugins/content_service/core.rb
dradis-plugins-4.13.0 lib/dradis/plugins/content_service/core.rb