From d7bcf6dfea4507cdf7ef31ce362f375c3973fd7f Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Fri, 28 Aug 2015 11:49:21 -0700 Subject: [PATCH] move resource plugin to vulcano/plugins Signed-off-by: Dominik Richter --- lib/vulcano/plugins.rb | 7 +++++++ lib/vulcano/plugins/resource.rb | 34 +++++++++++++++++++++++++++++++++ lib/vulcano/profile_context.rb | 13 +------------ lib/vulcano/resource.rb | 22 +++++---------------- lib/vulcano/resources.rb | 1 - 5 files changed, 47 insertions(+), 30 deletions(-) create mode 100644 lib/vulcano/plugins.rb create mode 100644 lib/vulcano/plugins/resource.rb diff --git a/lib/vulcano/plugins.rb b/lib/vulcano/plugins.rb new file mode 100644 index 000000000..65195a15d --- /dev/null +++ b/lib/vulcano/plugins.rb @@ -0,0 +1,7 @@ +# encoding: utf-8 + +module Vulcano + module Plugins + autoload :Resource, 'vulcano/plugins/resource' + end +end diff --git a/lib/vulcano/plugins/resource.rb b/lib/vulcano/plugins/resource.rb new file mode 100644 index 000000000..a0756f566 --- /dev/null +++ b/lib/vulcano/plugins/resource.rb @@ -0,0 +1,34 @@ +# encoding: utf-8 + +module Vulcano + module Plugins + + class Resource + def self.name( name ) + Vulcano::Plugins::Resource.__register(name, self) + end + + def self.__register(name, obj) + cl = Class.new(obj) do + include Vulcano::Plugins::ResourceCommon + def initialize(backend, *args) + @vulcano = backend + super(*args) + end + end + Vulcano::Resource.registry[name] = cl + end + end + + module ResourceCommon + def resource_skipped + @resource_skipped + end + + def skip_resource message + @resource_skipped = message + end + end + + end +end diff --git a/lib/vulcano/profile_context.rb b/lib/vulcano/profile_context.rb index 82cc87571..cc5e4a19f 100644 --- a/lib/vulcano/profile_context.rb +++ b/lib/vulcano/profile_context.rb @@ -12,17 +12,6 @@ module Vulcano __CTX = self backend = Vulcano::Backend::Mock::Runner.new - resource_classes = {} - Vulcano::Resource.registry.each do |name, cl| - resource_classes[name] = Class.new(cl) do - include Vulcano::ResourceCommon - def initialize(backend, *args) - @vulcano = backend - super(*args) - end - end - end - # This is the heart of the profile context # An instantiated object which has all resources registered to it # and exposes them to the a test file. @@ -38,7 +27,7 @@ module Vulcano __CTX.unregister_rule(*args) end - resource_classes.each do |id,r| + Vulcano::Resource.registry.each do |id,r| define_method id.to_sym do |*args| r.new(backend, *args) end diff --git a/lib/vulcano/resource.rb b/lib/vulcano/resource.rb index 76227d9ec..73102764b 100644 --- a/lib/vulcano/resource.rb +++ b/lib/vulcano/resource.rb @@ -1,31 +1,19 @@ # encoding: utf-8 # copyright: 2015, Vulcano Security GmbH # license: All rights reserved +require 'vulcano/plugins' module Vulcano class Resource def self.registry @registry ||= {} end - - def self.name( name ) - Vulcano::Resource.registry[name] = self - end - end - - module ResourceCommon - - def resource_skipped - @resource_skipped - end - - def skip_resource message - @resource_skipped = message - end - end def self.resource(version) - Vulcano::Resource + if version != 1 + raise "Only resource version 1 is supported!" + end + Vulcano::Plugins::Resource end end diff --git a/lib/vulcano/resources.rb b/lib/vulcano/resources.rb index e56c5df56..4713d5de4 100644 --- a/lib/vulcano/resources.rb +++ b/lib/vulcano/resources.rb @@ -1,5 +1,4 @@ # encoding: utf-8 -require 'utils/modulator' require 'vulcano/resource' # require 'resources/apache_conf'