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 +4 -4
- data/lib/hiera/backend/router_backend.rb +15 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 270b051d6714ab746076bb4fb1cd045e6bac9bb3
|
4
|
+
data.tar.gz: bbd6acc88db52a5a3db6cc6617c549b87dba46f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
:
|
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
|
-
|
147
|
-
Hiera.debug("[hiera-router] Backend class: #{
|
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
|
-
|
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."
|