Class: Jerakia::Lookup
- Inherits:
-
Object
- Object
- Jerakia::Lookup
- Defined in:
- lib/jerakia/lookup.rb,
lib/jerakia/lookup/plugin_config.rb
Defined Under Namespace
Classes: Plugin, PluginConfig, PluginFactory
Instance Attribute Summary collapse
-
#datasource ⇒ Object
Returns the value of attribute datasource.
-
#lookuptype ⇒ Object
readonly
Returns the value of attribute lookuptype.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#output_filters ⇒ Object
readonly
Returns the value of attribute output_filters.
-
#pluginfactory ⇒ Object
readonly
Returns the value of attribute pluginfactory.
-
#proceed ⇒ Object
Returns the value of attribute proceed.
-
#request ⇒ Object
Returns the value of attribute request.
-
#scope_object ⇒ Object
readonly
Returns the value of attribute scope_object.
-
#valid ⇒ Object
Returns the value of attribute valid.
Instance Method Summary collapse
- #confine(key = nil, match) ⇒ Object
-
#continue ⇒ Object
lookup function: continue Will cause Jerakia to continue to the next lookup in the policy which is the default behaviour.
- #exclude(key = nil, match) ⇒ Object
- #get_matches(key, match) ⇒ Object
-
#initialize(name, opts, req, scope) ⇒ Lookup
constructor
A new instance of Lookup.
-
#invalidate ⇒ Object
lookup function: invalidate Setting invalidate will mean this lookup will be skipped in the policy.
- #output_filter(name, opts = {}) ⇒ Object
- #plugin ⇒ Object
-
#plugin_config(plugin) ⇒ Object
Retrieve plugin specific configuration from the global configuration file gets passed to the plugin instance upon initilization.
- #plugin_load(plugin) ⇒ Object
- #proceed? ⇒ Boolean
- #scope ⇒ Object
-
#stop ⇒ Object
lookup function: stop Enabling stop sets @proceed to false, which will cause Jerakia not to load any more lookups in the policy if this lookup is deemed as valid.
- #valid? ⇒ Boolean
Constructor Details
#initialize(name, opts, req, scope) ⇒ Lookup
Returns a new instance of Lookup.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/jerakia/lookup.rb', line 18 def initialize(name, opts, req, scope) @name = name @request = req @valid = true @scope_object = scope @output_filters = [] @proceed = true @pluginfactory = Jerakia::Lookup::PluginFactory.new # Validate options passed to the lookup # valid_opts = [:use] opts.keys.each do |opt_key| unless valid_opts.include?(opt_key) raise Jerakia::PolicyError, "Unknown option #{opt_key} for lookup #{name}" end end if opts[:use] Array(opts[:use]).flatten.each do |plugin| plugin_load(plugin) end end end |
Instance Attribute Details
#datasource ⇒ Object
Returns the value of attribute datasource.
9 10 11 |
# File 'lib/jerakia/lookup.rb', line 9 def datasource @datasource end |
#lookuptype ⇒ Object (readonly)
Returns the value of attribute lookuptype.
12 13 14 |
# File 'lib/jerakia/lookup.rb', line 12 def lookuptype @lookuptype end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/jerakia/lookup.rb', line 15 def name @name end |
#output_filters ⇒ Object (readonly)
Returns the value of attribute output_filters.
14 15 16 |
# File 'lib/jerakia/lookup.rb', line 14 def output_filters @output_filters end |
#pluginfactory ⇒ Object (readonly)
Returns the value of attribute pluginfactory.
16 17 18 |
# File 'lib/jerakia/lookup.rb', line 16 def pluginfactory @pluginfactory end |
#proceed ⇒ Object
Returns the value of attribute proceed.
11 12 13 |
# File 'lib/jerakia/lookup.rb', line 11 def proceed @proceed end |
#request ⇒ Object
Returns the value of attribute request.
8 9 10 |
# File 'lib/jerakia/lookup.rb', line 8 def request @request end |
#scope_object ⇒ Object (readonly)
Returns the value of attribute scope_object.
13 14 15 |
# File 'lib/jerakia/lookup.rb', line 13 def scope_object @scope_object end |
#valid ⇒ Object
Returns the value of attribute valid.
10 11 12 |
# File 'lib/jerakia/lookup.rb', line 10 def valid @valid end |
Instance Method Details
#confine(key = nil, match) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/jerakia/lookup.rb', line 107 def confine(key = nil, match) if key invalidate if get_matches(key, match).empty? else invalidate end end |
#continue ⇒ Object
lookup function: continue Will cause Jerakia to continue to the next lookup in the policy which is the default behaviour
88 89 90 |
# File 'lib/jerakia/lookup.rb', line 88 def continue @proceed = true end |
#exclude(key = nil, match) ⇒ Object
115 116 117 118 119 |
# File 'lib/jerakia/lookup.rb', line 115 def exclude(key = nil, match) if key invalidate unless get_matches(key, match).empty? end end |
#get_matches(key, match) ⇒ Object
103 104 105 |
# File 'lib/jerakia/lookup.rb', line 103 def get_matches(key, match) matches = Array(match).select { |m| key[Regexp.new(m)] == key } end |
#invalidate ⇒ Object
lookup function: invalidate Setting invalidate will mean this lookup will be skipped in the policy
95 96 97 |
# File 'lib/jerakia/lookup.rb', line 95 def invalidate @valid = false end |
#output_filter(name, opts = {}) ⇒ Object
64 65 66 |
# File 'lib/jerakia/lookup.rb', line 64 def output_filter(name, opts = {}) @output_filters << { :name => name, :opts => opts } end |
#plugin ⇒ Object
56 57 58 |
# File 'lib/jerakia/lookup.rb', line 56 def plugin pluginfactory end |
#plugin_config(plugin) ⇒ Object
Retrieve plugin specific configuration from the global configuration file gets passed to the plugin instance upon initilization.
47 48 49 |
# File 'lib/jerakia/lookup.rb', line 47 def plugin_config(plugin) Jerakia::Lookup::PluginConfig.new(plugin) end |
#plugin_load(plugin) ⇒ Object
51 52 53 54 |
# File 'lib/jerakia/lookup.rb', line 51 def plugin_load(plugin) Jerakia.log.debug("Loading plugin #{plugin}") pluginfactory.register(plugin, Jerakia::Lookup::Plugin.new(self, plugin_config(plugin))) end |
#proceed? ⇒ Boolean
68 69 70 |
# File 'lib/jerakia/lookup.rb', line 68 def proceed? proceed end |
#scope ⇒ Object
60 61 62 |
# File 'lib/jerakia/lookup.rb', line 60 def scope scope_object.value end |
#stop ⇒ Object
lookup function: stop Enabling stop sets @proceed to false, which will cause Jerakia not to load any more lookups in the policy if this lookup is deemed as valid. If the lookup is invalidated than Jerakia will progress to the next lookup. This is useful in conjuction with the confine plugin where we want to segregate some lookups but not worry about excluding from later lookups
80 81 82 |
# File 'lib/jerakia/lookup.rb', line 80 def stop @proceed = false end |
#valid? ⇒ Boolean
99 100 101 |
# File 'lib/jerakia/lookup.rb', line 99 def valid? valid end |