lib/dradis/plugins/upload/base.rb in dradis-plugins-3.0.0 vs lib/dradis/plugins/upload/base.rb in dradis-plugins-3.5.0

- old
+ new

@@ -1,42 +1,57 @@ -# This module contains basic Upload plugin functions to control template -# sample and field management for the Plugin Manager. + +# When you call provides :upload in your Engine, this module gets included. It +# provides two features: # -module Dradis - module Plugins - module Upload - class Base - attr_accessor :content_service, :logger, :template_service +# a) an .uploaders() class method that by default responds with a single array +# item pointing to the engine's parent. This will be used by the framework to +# locate the ::Importer object that does the upload heavy lifting. +# +# If your plugin implements more than one uploader, each one would be contained +# in its own namespace, and you should overwrite the .uploaders() method to +# return an array of all these namespaces. See method definition for an +# example. +# +# b) it adds a .meta() method to the engine's parent module, containing the +# name, description and version of the add-on. +# +# Again, if you implement more than one uploader, make sure you create a +# .meta() class-level method in each of your namespaces. +# - def initialize(args={}) - @logger = args.fetch(:logger, Rails.logger) +module Dradis::Plugins::Upload::Base + extend ActiveSupport::Concern - @content_service = args[:content_service] || default_content_service - @template_service = args[:template_service] || default_template_service + included do + parent.extend NamespaceClassMethods + end - content_service.logger = logger - template_service.logger = logger + module ClassMethods + # Return the list of modules that provide upload functionality. This is + # useful if one plugin provides uploading functionality for more than one + # file type (e.g. the Projects plugin allows you to upload a Package or a + # Template). + # + # The default implementation just returns this plugin's namespace (e.g. + # Dradis::Plugins::Nessus). If a plugin provides multiple uploaders, they + # can override this method: + # def self.uploders + # [ + # Dradis::Plugins::Projects::Package, + # Dradis::Plugins::Projects::Template + # ] + # end + def uploaders() + [parent] + end + end - post_initialize(args) - end - - def import(args={}) - raise "The import() method is not implemented in this plugin [#{self.class.name}]." - end - - # This method can be overwriten by plugins to do initialization tasks. - def post_initialize(args={}) - end - - private - def default_content_service - @content ||= Dradis::Plugins::ContentService.new - end - - def default_template_service - @template ||= Dradis::Plugins::TemplateService.new - end - end # Base - - end # Upload - end # Plugins -end # Core \ No newline at end of file + module NamespaceClassMethods + def meta + { + name: self::Engine::plugin_name, + description: self::Engine::plugin_description, + version: self::VERSION::STRING + } + end + end +end