hiera-dyml 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hiera/backend/dyml_backend.rb +43 -34
- metadata +6 -6
@@ -1,43 +1,52 @@
|
|
1
1
|
class Hiera
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
module Backend
|
3
|
+
class Dyml_backend
|
4
|
+
#based on the original Hiera Yaml backend, modified to use the deep_merge hash function to merge the hiera yaml files.
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
def initialize
|
7
|
+
require 'yaml'
|
8
|
+
require 'deep_merge'
|
9
|
+
Hiera.debug("Hiera Dyml backend starting")
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
files << yamlfile
|
21
|
-
end
|
12
|
+
def deep_merge_options
|
13
|
+
@options ||= {}.tap do |options|
|
14
|
+
backend_options = Hiera::Config[:dyml]
|
15
|
+
[:knockout_prefix, :preserve_unmergeables, :sort_merged_arrays, :unpack_arrays].each do |key|
|
16
|
+
options[key] = backend_options[key] if backend_options.include?(key)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
22
20
|
|
23
|
-
|
21
|
+
def lookup(key, scope, order_override, resolution_type)
|
22
|
+
answer = nil
|
23
|
+
Hiera.debug("Looking up #{key} in DYML backend")
|
24
|
+
files = []
|
25
|
+
data = {}
|
26
|
+
Backend.datasources(scope, order_override) do |source|
|
27
|
+
Hiera.debug("Looking for data source #{source}")
|
28
|
+
yamlfile = Backend.datafile(:dyml, scope, source, "yaml") || next
|
29
|
+
files << yamlfile
|
30
|
+
end
|
24
31
|
|
25
|
-
|
26
|
-
new_answer = Backend.parse_answer(data[key], scope)
|
27
|
-
case resolution_type
|
28
|
-
when :array
|
29
|
-
raise Exception, "Hiera type mismatch: expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array or new_answer.kind_of? String
|
30
|
-
answer << new_answer
|
31
|
-
when :hash
|
32
|
-
raise Exception, "Hiera type mismatch: expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash
|
33
|
-
answer = new_answer.merge answer
|
34
|
-
else
|
35
|
-
answer = new_answer
|
36
|
-
end
|
37
|
-
end
|
32
|
+
files.reverse.each { |f| data.deep_merge!(YAML.load_file(f), deep_merge_options) } unless files.empty?
|
38
33
|
|
39
|
-
|
40
|
-
|
34
|
+
if data.include?(key)
|
35
|
+
new_answer = Backend.parse_answer(data[key], scope)
|
36
|
+
case resolution_type
|
37
|
+
when :array
|
38
|
+
raise Exception, "Hiera type mismatch: expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array or new_answer.kind_of? String
|
39
|
+
answer << new_answer
|
40
|
+
when :hash
|
41
|
+
raise Exception, "Hiera type mismatch: expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash
|
42
|
+
answer = new_answer.merge answer
|
43
|
+
else
|
44
|
+
answer = new_answer
|
45
|
+
end
|
41
46
|
end
|
47
|
+
|
48
|
+
return answer
|
49
|
+
end
|
42
50
|
end
|
51
|
+
end
|
43
52
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiera-dyml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hiera
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- - '
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
21
|
+
version: 1.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- - '
|
27
|
+
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.
|
29
|
+
version: 1.0.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: deep_merge
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|