Class: Jerakia::Lookup

Inherits:
Object
  • Object
show all
Defined in:
lib/jerakia/lookup.rb

Defined Under Namespace

Classes: Plugin, PluginFactory

Instance Attribute Summary collapse

Instance Method Summary collapse

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
43
44
45
# 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(source, opts = {}) ⇒ Object

Returns the value of attribute datasource.



8
9
10
# File 'lib/jerakia/lookup.rb', line 8

def datasource
  @datasource
end

#lookuptypeObject (readonly)

Returns the value of attribute lookuptype.



11
12
13
# File 'lib/jerakia/lookup.rb', line 11

def lookuptype
  @lookuptype
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/jerakia/lookup.rb', line 14

def name
  @name
end

#output_filtersObject (readonly)

Returns the value of attribute output_filters.



13
14
15
# File 'lib/jerakia/lookup.rb', line 13

def output_filters
  @output_filters
end

#pluginfactoryObject (readonly)

Returns the value of attribute pluginfactory.



15
16
17
# File 'lib/jerakia/lookup.rb', line 15

def pluginfactory
  @pluginfactory
end

#proceedObject

Returns the value of attribute proceed.



10
11
12
# File 'lib/jerakia/lookup.rb', line 10

def proceed
  @proceed
end

#requestObject

Returns the value of attribute request.



7
8
9
# File 'lib/jerakia/lookup.rb', line 7

def request
  @request
end

#scope_objectObject (readonly)

Returns the value of attribute scope_object.



12
13
14
# File 'lib/jerakia/lookup.rb', line 12

def scope_object
  @scope_object
end

#validObject

Returns the value of attribute valid.



9
10
11
# File 'lib/jerakia/lookup.rb', line 9

def valid
  @valid
end

Instance Method Details

#confine(key = nil, match) ⇒ Object



117
118
119
120
121
122
123
# File 'lib/jerakia/lookup.rb', line 117

def confine(key=nil,match)
  if key
    invalidate unless get_matches(key,match).size > 0
  else
    invalidate
  end
end

#continueObject

lookup function: continue Will cause Jerakia to continue to the next lookup in the policy which is the default behaviour



97
98
99
# File 'lib/jerakia/lookup.rb', line 97

def continue
  @proceed = true
end

#exclude(key = nil, match) ⇒ Object



125
126
127
128
129
# File 'lib/jerakia/lookup.rb', line 125

def exclude(key=nil,match)
  if key
    invalidate if get_matches(key,match).size > 0
  end
end

#get_datasourceObject



56
57
58
# File 'lib/jerakia/lookup.rb', line 56

def get_datasource
  @datasource
end

#get_matches(key, match) ⇒ Object



113
114
115
# File 'lib/jerakia/lookup.rb', line 113

def get_matches(key,match)
  matches = Array(match).select { |m| key[Regexp.new(m)] == key}
end

#invalidateObject

lookup function: invalidate Setting invalidate will mean this lookup will be skipped in the policy



104
105
106
# File 'lib/jerakia/lookup.rb', line 104

def invalidate
  @valid = false
end

#output_filter(name, opts = {}) ⇒ Object



73
74
75
# File 'lib/jerakia/lookup.rb', line 73

def output_filter(name,opts={})
  @output_filters << { :name => name, :opts => opts }
end

#pluginObject



52
53
54
# File 'lib/jerakia/lookup.rb', line 52

def plugin
  pluginfactory
end

#plugin_load(plugin) ⇒ Object



47
48
49
50
# File 'lib/jerakia/lookup.rb', line 47

def plugin_load(plugin)
  Jerakia.log.debug("Loading plugin #{plugin}")
  pluginfactory.register(plugin, Jerakia::Lookup::Plugin.new(self))
end

#proceed?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/jerakia/lookup.rb', line 77

def proceed?
  proceed
end

#runObject



132
133
134
135
136
137
138
139
140
# File 'lib/jerakia/lookup.rb', line 132

def run
  Jerakia.log.verbose("lookup: #{@name} key: #{@request.key} namespace: #{@request.namespace.join('/')}")
  @datasource.run
  response=@datasource.response
  @output_filters.each do |filter|
    response.filter! filter[:name], filter[:opts]
  end
  return response
end

#scopeObject

If set, Jerakia will pass each Jerakia::Response object to an output filter plugin



68
69
70
# File 'lib/jerakia/lookup.rb', line 68

def scope
  scope_object.value
end

#stopObject

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



89
90
91
# File 'lib/jerakia/lookup.rb', line 89

def stop
  @proceed = false
end

#valid?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/jerakia/lookup.rb', line 108

def valid?
  valid
end