mirror of
https://github.com/inspec/inspec
synced 2024-11-10 23:24:18 +00:00
Add input plugin type API
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
parent
962dfc8d90
commit
9e2e569d85
2 changed files with 39 additions and 6 deletions
|
@ -1,5 +1,37 @@
|
|||
module Inspec::Plugin::V2::PluginType
|
||||
class Input < Inspec::Plugin::V2::PluginBase
|
||||
register_plugin_type(:input)
|
||||
|
||||
#====================================================================#
|
||||
# Input plugin type API
|
||||
#====================================================================#
|
||||
# Implementation classes must implement these methods.
|
||||
|
||||
# When an input is obtained from the plugin, this number determines what
|
||||
# precedence to assign to the input.
|
||||
# @return Integer range 0-100. Higher priority means higher precedence
|
||||
def default_priority
|
||||
60
|
||||
end
|
||||
|
||||
# Indicates an attempt is being made to read the value for an input.
|
||||
# Return nil or an Event if the plugin is choosing to respond with a value.
|
||||
# Note that the Input system will still log the attempt in the event log,
|
||||
# even if nil is returned.
|
||||
# If you wish to indicate nil as a value for the input, return an
|
||||
# Event explicitly setting value to nil.
|
||||
# @return Inspec::Input::Event
|
||||
def fetch(_profile_name, _input_name)
|
||||
raise NotImplementedError, "Plugin #{plugin_name} must implement the #fetch method"
|
||||
end
|
||||
|
||||
# Given a profile name, list all input names for which the plugin
|
||||
# would offer a response.
|
||||
# @param String profile_name Name of the profile
|
||||
# @return Array[String] List of input names for which the plugin
|
||||
# would offer a response.
|
||||
def list_inputs(_profile)
|
||||
raise NotImplementedError, "Plugin #{plugin_name} must implement the #list_inputs method"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -22,13 +22,14 @@ describe 'Input plugin type' do
|
|||
|
||||
describe 'when examining the specific plugin type API' do
|
||||
[
|
||||
# TODO - API instance methods
|
||||
# fetch?
|
||||
# default_priority?
|
||||
# API instance methods
|
||||
:fetch,
|
||||
:default_priority,
|
||||
:list_inputs,
|
||||
].each do |api_method|
|
||||
it "should define an #{api_method} in the superclass" do
|
||||
klass = Inspec::Plugin::V2::PluginType::CliCommand
|
||||
klass.method_defined?(api_method).must_eq true
|
||||
it "should define a '#{api_method}' method in the superclass" do
|
||||
klass = Inspec::Plugin::V2::PluginType::Input
|
||||
klass.method_defined?(api_method).must_equal true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue