jerakia 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 733f3ff0ffece8cc45246f1e4e4657c6e7729618
4
- data.tar.gz: 4a493d69a56e2cff5eea275fd38201ccfaab6261
3
+ metadata.gz: 343d8ffe41f66435cee08e8db34bb2ff5ae8b005
4
+ data.tar.gz: 127a03abde135fd9b33368b68d04cd81d8d78864
5
5
  SHA512:
6
- metadata.gz: b5d658a3e2ef290b4fd29ca1a0bb2571c1b604793234464b699562e4972f02d6b226006b1ec725c6b513983f96dc6017ec39792d9b1e0df382ae0fbd1d1e4792
7
- data.tar.gz: 8415c0e24ef76f3250f430b7e3085395226ce4f2014a6cfa2e3ea1dac29926d223872ac9025fda3566aee6562716f5ec6a0e42ddf07c18b4cb68c109aeeb51e2
6
+ metadata.gz: 174b063357edeec29a0cd6ca6549c9f6ccd07d73aa5989f2ed6650f0605ddf5c856e0a8728f9fe4eb4c43374684a3e97d27cd50a64e5e7be3e0748797e72d24e
7
+ data.tar.gz: b2f5c63df21955ce11550cc7176eb439ae9ad73e26677dc852837bf10a3eda625ac9422f563adc728fc2b94a522f2e49ed4e6a51501018a296c364db75909630
File without changes
@@ -6,9 +6,9 @@
6
6
  # but maintain an existing hiera filesystem layout and naming convention
7
7
  # within the source data.
8
8
  #
9
- class Jerakia::Lookup
10
- module Plugin
11
- def hiera_compat
9
+ class Jerakia::Lookup::Plugin
10
+ module Hiera
11
+ def rewrite_lookup
12
12
  request.key.prepend("#{request.namespace.join('::')}::")
13
13
  request.namespace=[]
14
14
  end
@@ -0,0 +1,23 @@
1
+ class Jerakia::Lookup::Plugin
2
+
3
+
4
+ attr_reader :lookup
5
+
6
+ def initialize(lookup)
7
+ @lookup = lookup
8
+ end
9
+
10
+ def activate(name)
11
+ instance_eval "extend Jerakia::Lookup::Plugin::#{name.to_s.capitalize}"
12
+ end
13
+
14
+ def scope
15
+ lookup.scope
16
+ end
17
+
18
+ def request
19
+ lookup.request
20
+ end
21
+
22
+ end
23
+
@@ -0,0 +1,22 @@
1
+ class Jerakia::Lookup::PluginFactory
2
+
3
+ def initialize
4
+ Jerakia.log.debug("Loaded plugin handler")
5
+ end
6
+
7
+
8
+ def create_plugin_method(name, &block)
9
+ self.class.send(:define_method, name, &block)
10
+ end
11
+
12
+ def register(name,plugin)
13
+ require "jerakia/lookup/plugin/#{name}"
14
+ plugin.activate(name)
15
+ create_plugin_method(name) do
16
+ plugin
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+
@@ -1,8 +1,8 @@
1
1
  class Jerakia::Lookup
2
2
  require 'jerakia/datasource'
3
3
  require 'jerakia/scope'
4
- require 'jerakia/plugins/lookup/hiera_compat'
5
- require 'jerakia/plugins/lookup/confine'
4
+ require 'jerakia/lookup/plugin'
5
+ require 'jerakia/lookup/pluginfactory'
6
6
 
7
7
  attr_accessor :request
8
8
  attr_reader :datasource
@@ -12,8 +12,9 @@ class Jerakia::Lookup
12
12
  attr_reader :output_filters
13
13
  attr_reader :name
14
14
  attr_reader :proceed
15
+ attr_reader :pluginfactory
15
16
 
16
- def initialize(name,req,scope,&block)
17
+ def initialize(name,opts,req,scope,&block)
17
18
 
18
19
  @name=name
19
20
  @request=req
@@ -21,10 +22,26 @@ class Jerakia::Lookup
21
22
  @scope_object=scope
22
23
  @output_filters=[]
23
24
  @proceed=true
24
- extend Jerakia::Lookup::Plugin
25
+ @pluginfactory = Jerakia::Lookup::PluginFactory.new
26
+
27
+ if opts[:use]
28
+ Array(opts[:use]).flatten.each do |plugin|
29
+ plugin_load(plugin)
30
+ end
31
+ end
32
+
25
33
  instance_eval &block
26
34
 
27
35
  end
36
+
37
+ def plugin_load(plugin)
38
+ Jerakia.log.debug("Loading plugin #{plugin}")
39
+ @pluginfactory.register(plugin, Jerakia::Lookup::Plugin.new(self))
40
+ end
41
+
42
+ def plugin
43
+ @pluginfactory
44
+ end
28
45
 
29
46
  def datasource(source, opts={})
30
47
  @datasource = Jerakia::Datasource.new(source, self, opts)
@@ -78,6 +95,22 @@ class Jerakia::Lookup
78
95
  return @valid
79
96
  end
80
97
 
98
+
99
+ def confine(key=nil,match)
100
+ if key
101
+ invalidate unless key[Regexp.new(match)] == key
102
+ else
103
+ invalidate
104
+ end
105
+ end
106
+
107
+ def exclude(key=nil,match)
108
+ if key
109
+ invalidate if key[Regexp.new(match)] == key
110
+ end
111
+ end
112
+
113
+
81
114
  def run
82
115
  @datasource.run
83
116
  response=@datasource.response
@@ -31,7 +31,7 @@ class Jerakia::Policy < Jerakia::Launcher
31
31
  # We specifically clone the request object to allow plugins to modify the
32
32
  # request payload for the scope of this lookup only.
33
33
  #
34
- lookup = Jerakia::Lookup.new(name,clone_request,scope,&block)
34
+ lookup = Jerakia::Lookup.new(name,opts,clone_request,scope,&block)
35
35
  Jerakia.log.debug("Proceed to next lookup #{lookup.proceed?}")
36
36
 
37
37
  @lookups << lookup if lookup.valid? and @lookup_proceed
data/lib/jerakia.rb CHANGED
@@ -16,6 +16,11 @@ class Jerakia
16
16
  def initialize(options={})
17
17
  configfile = options[:config] || '/etc/jerakia/jerakia.yml'
18
18
  @@config = Jerakia::Config.new(configfile)
19
+
20
+ if @@config[:plugindir]
21
+ $LOAD_PATH << @@config[:plugindir] unless $LOAD_PATH.include?(@@config[:plugindir])
22
+ end
23
+
19
24
  @@filecache = {}
20
25
  loglevel = options[:loglevel] || @@config["loglevel"] || "info"
21
26
  @@log = Jerakia::Log.new(loglevel.to_sym)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jerakia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Dunn
@@ -30,11 +30,14 @@ files:
30
30
  - lib/jerakia/datasource/dummy.rb
31
31
  - lib/jerakia/datasource/file.rb
32
32
  - lib/jerakia/datasource/file/yaml.rb
33
+ - lib/jerakia/foobar
33
34
  - lib/jerakia/launcher.rb
34
35
  - lib/jerakia/log.rb
35
36
  - lib/jerakia/lookup.rb
37
+ - lib/jerakia/lookup/plugin.rb
38
+ - lib/jerakia/lookup/plugin/hiera.rb
39
+ - lib/jerakia/lookup/pluginfactory.rb
36
40
  - lib/jerakia/plugins/lookup/confine.rb
37
- - lib/jerakia/plugins/lookup/hiera_compat.rb
38
41
  - lib/jerakia/policy.rb
39
42
  - lib/jerakia/request.rb
40
43
  - lib/jerakia/response.rb