hiera-router 0.3.0 → 0.3.1

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: abfcfa47f33ef9e671eb2ae5c67a926ff54e9ece
4
- data.tar.gz: 08d87376e47464ef8d8950d904049e7b6984f3d9
3
+ metadata.gz: 270b051d6714ab746076bb4fb1cd045e6bac9bb3
4
+ data.tar.gz: bbd6acc88db52a5a3db6cc6617c549b87dba46f1
5
5
  SHA512:
6
- metadata.gz: b590110177566923f3ae58051ebbbd224b3a5a50845425e92bae141510eae919f07c2ae93a00b3d6e72d2d41bf734a0a911f82a963c551b0180016d6c8a22a57
7
- data.tar.gz: b3b9cc76cf375490ce8f3bdc438d0b80ea98c5a73537a8cbe09292ffab93ccbfcc0568a8c93cf9427283f897668b6c9481c3b3cbce7e2157f01493c4f1cf9119
6
+ metadata.gz: 4d1466d75a15d0080abb23c4d6525415ff43dbfd0f44bc89b2410079d787cb1d11037bbc361da01bb13508c65f643cf42be372daa4d4bcbf7c23f50d001a5b24
7
+ data.tar.gz: 5bd9826ece5fc3c2e019902d5f8a901e3a1bb04c2aa7f802dea0407641b6ed62e382ff807a389210fb036885f94bcfe6cc037fba992e80f613554c58f066866b
@@ -1,3 +1,6 @@
1
+ require 'hiera/filecache'
2
+ require 'yaml'
3
+
1
4
  class Hiera
2
5
  class Config
3
6
  class << self
@@ -10,20 +13,20 @@ class Hiera
10
13
  module Backend
11
14
  class Router_backend
12
15
  attr_reader :backends
16
+ attr_accessor :config
13
17
 
14
18
  def initialize(cache = nil)
15
- require 'hiera/filecache'
16
- require 'yaml'
17
19
  @cache = cache || Filecache.new
18
20
  @backends = {}
19
21
  Hiera.debug("[hiera-router] I'm here!")
20
- Hiera.debug("[hiera-router] My configuration: #{Config[:router].inspect}")
22
+ config = Config.config
21
23
 
22
24
  if backend_list = Config[:router][:backends]
23
25
  Hiera.debug("[hiera-router] Initializing backends: #{backend_list.keys.join(',')}")
24
26
  backend_list.each do |backend, backend_config|
25
27
  Hiera.debug("[hiera-router] Initializing backend '#{backend}'")
26
28
  backend_classname = backend_config['backend_class'] || backend_config[:backend_class] || backend
29
+ full_backend_classname = "#{backend_classname.capitalize}_backend"
27
30
  backend_config_override = backend_config['backend_key'] || backend_config[:backend_key] || backend_classname
28
31
  Hiera.debug("[hiera-router] Backend class for '#{backend}' will be '#{backend_classname}'")
29
32
 
@@ -32,15 +35,18 @@ class Hiera
32
35
  :backends => [backend_classname],
33
36
  backend_classname.to_sym => Config[backend_config_override.to_sym] || Config[:router][backend_config_override.to_sym] || {},
34
37
  })
38
+
39
+ Config.load(backend_config)
40
+ require "hiera/backend/#{full_backend_classname.downcase}"
41
+ backend_inst = Hiera::Backend.const_get(full_backend_classname).new
42
+ Config.load(config)
35
43
  @backends[backend.to_sym] = {
36
- :class_name => "#{backend_classname.capitalize}_backend",
44
+ :instance => backend_inst,
37
45
  :config => backend_config,
38
46
  }
39
47
  end
40
48
  end
41
49
 
42
- Hiera.debug("All the backend configs: #{@backends.inspect}")
43
-
44
50
  Hiera.debug("[hiera-router] hiera router initialized")
45
51
  end
46
52
  def lookup(key, scope, order_override, resolution_type)
@@ -143,12 +149,10 @@ class Hiera
143
149
  backend_options = backend_options.merge(backend_parameters) if backend_parameters
144
150
  Hiera.debug("[hiera-router] Calling hiera with '#{backend_name}'...")
145
151
  if backend = backends[backend_name.to_sym]
146
- backend_classname = backend[:class_name]
147
- Hiera.debug("[hiera-router] Backend class: #{backend_classname}")
148
- config = Config.config
152
+ backend_instance = backend[:instance]
153
+ Hiera.debug("[hiera-router] Backend class: #{backend_instance.class.name}")
149
154
  Config.load(backend[:config])
150
- require "hiera/backend/#{backend_classname.downcase}"
151
- result = Hiera::Backend.const_get(backend_classname).new.lookup(backend_options[:key], backend_options[:scope], nil, backend_options[:resolution_type])
155
+ result = backend_instance.lookup(backend_options[:key], backend_options[:scope], nil, backend_options[:resolution_type])
152
156
  Config.load(config)
153
157
  else
154
158
  Hiera.warn "Backend '#{backend_name}' was not configured; returning the data as-is."
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiera-router
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jo Vandeginste