move resource plugin to vulcano/plugins

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-08-28 11:49:21 -07:00
parent 2c2d2d8d27
commit d7bcf6dfea
5 changed files with 47 additions and 30 deletions

7
lib/vulcano/plugins.rb Normal file
View file

@ -0,0 +1,7 @@
# encoding: utf-8
module Vulcano
module Plugins
autoload :Resource, 'vulcano/plugins/resource'
end
end

View file

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

View file

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

View file

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

View file

@ -1,5 +1,4 @@
# encoding: utf-8
require 'utils/modulator'
require 'vulcano/resource'
# require 'resources/apache_conf'