mirror of
https://github.com/inspec/inspec
synced 2025-02-16 22:18:38 +00:00
establish plugin loading dock
This commit is contained in:
parent
9bda5def40
commit
ecb78e3a19
2 changed files with 35 additions and 0 deletions
|
@ -11,6 +11,7 @@ libdir = File.dirname(__FILE__)
|
||||||
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
||||||
|
|
||||||
require 'inspec/version'
|
require 'inspec/version'
|
||||||
|
require 'inspec/plugins'
|
||||||
require 'inspec/profile'
|
require 'inspec/profile'
|
||||||
require 'inspec/resource'
|
require 'inspec/resource'
|
||||||
require 'inspec/rspec_json_formatter'
|
require 'inspec/rspec_json_formatter'
|
||||||
|
|
|
@ -2,8 +2,42 @@
|
||||||
# author: Dominik Richter
|
# author: Dominik Richter
|
||||||
# author: Christoph Hartmann
|
# author: Christoph Hartmann
|
||||||
|
|
||||||
|
require 'forwardable'
|
||||||
|
|
||||||
module Inspec
|
module Inspec
|
||||||
module Plugins
|
module Plugins
|
||||||
autoload :Resource, 'inspec/plugins/resource'
|
autoload :Resource, 'inspec/plugins/resource'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class PluginCtl
|
||||||
|
extend Forwardable
|
||||||
|
|
||||||
|
attr_reader :registry
|
||||||
|
def_delegator :registry, :keys, :list
|
||||||
|
|
||||||
|
def initialize(home = nil)
|
||||||
|
@home = home || File.join(Dir.home, '.inspec', 'plugins')
|
||||||
|
@paths = Dir[File.join(@home, '**{,/*/**}', '*.gemspec')]
|
||||||
|
.map { |x| File.dirname(x) }
|
||||||
|
.map { |x| Dir[File.join(x, 'lib', 'inspec-*.rb')] }
|
||||||
|
.flatten
|
||||||
|
# map paths to names
|
||||||
|
@registry = Hash[@paths.map { |x|
|
||||||
|
[File.basename(x, '.rb'), x]
|
||||||
|
}]
|
||||||
|
end
|
||||||
|
|
||||||
|
def load(name)
|
||||||
|
path = @registry[name]
|
||||||
|
if path.nil?
|
||||||
|
fail "Couldn't find plugin #{name}. Searching in #{@home}"
|
||||||
|
end
|
||||||
|
puts "Loading plugin #{name} from #{path}"
|
||||||
|
require path
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Load all plugins on startup
|
||||||
|
ctl = Inspec::PluginCtl.new
|
||||||
|
ctl.list.each { |x| ctl.load(x) }
|
||||||
|
|
Loading…
Add table
Reference in a new issue