hiera 1.3.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of hiera might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/lib/hiera/backend.rb +39 -6
- data/lib/hiera/backend/yaml_backend.rb +1 -6
- data/lib/hiera/version.rb +1 -1
- data/spec/unit/backend/yaml_backend_spec.rb +9 -56
- metadata +32 -36
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bead4c683facdc5241dc8d042f1cd3bf13876bcf
|
4
|
+
data.tar.gz: a6065696732cb214f52b973f1bcfd711dbbf7efb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7f8bba4254043dd85e15d289b80e18fa0f7bdf176492633d28240e6157e647dd8008b123503db9b6fb594f47aaa59a57e9e48dce544dc18f4f7f279c606e2f2c
|
7
|
+
data.tar.gz: a570c3344e74d6c522a12b476b242e5f6b221e027e7151cc56a9701ea4eb163434656094b8dfc3f2deca893a84645b8196f79a28557485fea46242a284b070a2
|
data/lib/hiera/backend.rb
CHANGED
@@ -34,15 +34,19 @@ class Hiera
|
|
34
34
|
#
|
35
35
|
# If the file is not found nil is returned
|
36
36
|
def datafile(backend, scope, source, extension)
|
37
|
-
|
37
|
+
datafile_in(datadir(backend, scope), source, extension)
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
40
|
+
# @api private
|
41
|
+
def datafile_in(datadir, source, extension)
|
42
|
+
file = File.join(datadir, "#{source}.#{extension}")
|
41
43
|
|
42
|
-
|
44
|
+
if File.exist?(file)
|
45
|
+
file
|
46
|
+
else
|
47
|
+
Hiera.debug("Cannot find datafile #{file}, skipping")
|
48
|
+
nil
|
43
49
|
end
|
44
|
-
|
45
|
-
return file
|
46
50
|
end
|
47
51
|
|
48
52
|
# Constructs a list of data sources to search
|
@@ -73,6 +77,35 @@ class Hiera
|
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
80
|
+
# Constructs a list of data files to search
|
81
|
+
#
|
82
|
+
# If you give it a specific hierarchy it will just use that
|
83
|
+
# else it will use the global configured one, failing that
|
84
|
+
# it will just look in the 'common' data source.
|
85
|
+
#
|
86
|
+
# An override can be supplied that will be pre-pended to the
|
87
|
+
# hierarchy.
|
88
|
+
#
|
89
|
+
# The source names will be subject to variable expansion based
|
90
|
+
# on scope
|
91
|
+
#
|
92
|
+
# Only files that exist will be returned. If the file is missing, then
|
93
|
+
# the block will not receive the file.
|
94
|
+
#
|
95
|
+
# @yield [String, String] the source string and the name of the resulting file
|
96
|
+
# @api public
|
97
|
+
def datasourcefiles(backend, scope, extension, override=nil, hierarchy=nil)
|
98
|
+
datadir = Backend.datadir(backend, scope)
|
99
|
+
Backend.datasources(scope, override, hierarchy) do |source|
|
100
|
+
Hiera.debug("Looking for data source #{source}")
|
101
|
+
file = datafile_in(datadir, source, extension)
|
102
|
+
|
103
|
+
if file
|
104
|
+
yield source, file
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
76
109
|
# Parse a string like <code>'%{foo}'</code> against a supplied
|
77
110
|
# scope and additional scope. If either scope or
|
78
111
|
# extra_scope includes the variable 'foo', then it will
|
@@ -13,12 +13,7 @@ class Hiera
|
|
13
13
|
|
14
14
|
Hiera.debug("Looking up #{key} in YAML backend")
|
15
15
|
|
16
|
-
Backend.
|
17
|
-
Hiera.debug("Looking for data source #{source}")
|
18
|
-
yamlfile = Backend.datafile(:yaml, scope, source, "yaml") || next
|
19
|
-
|
20
|
-
next unless file_exists?(yamlfile)
|
21
|
-
|
16
|
+
Backend.datasourcefiles(:yaml, scope, "yaml", order_override) do |source, yamlfile|
|
22
17
|
data = @cache.read_file(yamlfile, Hash) do |data|
|
23
18
|
YAML.load(data) || {}
|
24
19
|
end
|
data/lib/hiera/version.rb
CHANGED
@@ -37,38 +37,16 @@ class Hiera
|
|
37
37
|
end
|
38
38
|
|
39
39
|
describe "#lookup" do
|
40
|
-
it "should look for data in all sources" do
|
41
|
-
Backend.expects(:datasources).multiple_yields(["one"], ["two"])
|
42
|
-
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns(nil)
|
43
|
-
Backend.expects(:datafile).with(:yaml, {}, "two", "yaml").returns(nil)
|
44
|
-
|
45
|
-
@backend.lookup("key", {}, nil, :priority)
|
46
|
-
end
|
47
|
-
|
48
40
|
it "should pick data earliest source that has it for priority searches" do
|
49
|
-
Backend.expects(:
|
50
|
-
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml")
|
51
|
-
Backend.expects(:datafile).with(:yaml, {}, "two", "yaml").returns(nil).never
|
52
|
-
|
53
|
-
@backend.stubs(:file_exists?).with("/nonexisting/one.yaml").returns(true)
|
41
|
+
Backend.expects(:datasourcefiles).with(:yaml, {}, "yaml", nil).yields(["one", "/nonexisting/one.yaml"])
|
54
42
|
@cache.value = "---\nkey: answer"
|
55
43
|
|
56
44
|
@backend.lookup("key", {}, nil, :priority).should == "answer"
|
57
45
|
end
|
58
46
|
|
59
|
-
it "should not look up missing data files" do
|
60
|
-
Backend.expects(:datasources).multiple_yields(["one"])
|
61
|
-
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns(nil)
|
62
|
-
YAML.expects(:load_file).never
|
63
|
-
|
64
|
-
@backend.lookup("key", {}, nil, :priority)
|
65
|
-
end
|
66
|
-
|
67
47
|
describe "handling unexpected YAML values" do
|
68
48
|
before do
|
69
|
-
Backend.expects(:
|
70
|
-
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml")
|
71
|
-
@backend.stubs(:file_exists?).with("/nonexisting/one.yaml").returns(true)
|
49
|
+
Backend.expects(:datasourcefiles).with(:yaml, {}, "yaml", nil).yields(["one", "/nonexisting/one.yaml"])
|
72
50
|
end
|
73
51
|
|
74
52
|
it "returns nil when the YAML value is nil" do
|
@@ -88,12 +66,7 @@ class Hiera
|
|
88
66
|
end
|
89
67
|
|
90
68
|
it "should build an array of all data sources for array searches" do
|
91
|
-
Backend.expects(:
|
92
|
-
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml")
|
93
|
-
Backend.expects(:datafile).with(:yaml, {}, "two", "yaml").returns("/nonexisting/two.yaml")
|
94
|
-
File.stubs(:exist?).with("/nonexisting/one.yaml").returns(true)
|
95
|
-
File.stubs(:exist?).with("/nonexisting/two.yaml").returns(true)
|
96
|
-
|
69
|
+
Backend.expects(:datasourcefiles).with(:yaml, {}, "yaml", nil).multiple_yields(["one", "/nonexisting/one.yaml"], ["two", "/nonexisting/two.yaml"])
|
97
70
|
@cache.expects(:read_file).with("/nonexisting/one.yaml", Hash).returns({"key"=>"answer"})
|
98
71
|
@cache.expects(:read_file).with("/nonexisting/two.yaml", Hash).returns({"key"=>"answer"})
|
99
72
|
|
@@ -101,11 +74,7 @@ class Hiera
|
|
101
74
|
end
|
102
75
|
|
103
76
|
it "should ignore empty hash of data sources for hash searches" do
|
104
|
-
Backend.expects(:
|
105
|
-
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml")
|
106
|
-
Backend.expects(:datafile).with(:yaml, {}, "two", "yaml").returns("/nonexisting/two.yaml")
|
107
|
-
File.stubs(:exist?).with("/nonexisting/one.yaml").returns(true)
|
108
|
-
File.stubs(:exist?).with("/nonexisting/two.yaml").returns(true)
|
77
|
+
Backend.expects(:datasourcefiles).with(:yaml, {}, "yaml", nil).multiple_yields(["one", "/nonexisting/one.yaml"], ["two", "/nonexisting/two.yaml"])
|
109
78
|
|
110
79
|
@cache.expects(:read_file).with("/nonexisting/one.yaml", Hash).returns({})
|
111
80
|
@cache.expects(:read_file).with("/nonexisting/two.yaml", Hash).returns({"key"=>{"a"=>"answer"}})
|
@@ -114,11 +83,7 @@ class Hiera
|
|
114
83
|
end
|
115
84
|
|
116
85
|
it "should build a merged hash of data sources for hash searches" do
|
117
|
-
Backend.expects(:
|
118
|
-
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml")
|
119
|
-
Backend.expects(:datafile).with(:yaml, {}, "two", "yaml").returns("/nonexisting/two.yaml")
|
120
|
-
File.stubs(:exist?).with("/nonexisting/one.yaml").returns(true)
|
121
|
-
File.stubs(:exist?).with("/nonexisting/two.yaml").returns(true)
|
86
|
+
Backend.expects(:datasourcefiles).with(:yaml, {}, "yaml", nil).multiple_yields(["one", "/nonexisting/one.yaml"], ["two", "/nonexisting/two.yaml"])
|
122
87
|
|
123
88
|
@cache.expects(:read_file).with("/nonexisting/one.yaml", Hash).returns({"key"=>{"a"=>"answer"}})
|
124
89
|
@cache.expects(:read_file).with("/nonexisting/two.yaml", Hash).returns({"key"=>{"b"=>"answer", "a"=>"wrong"}})
|
@@ -127,11 +92,7 @@ class Hiera
|
|
127
92
|
end
|
128
93
|
|
129
94
|
it "should fail when trying to << a Hash" do
|
130
|
-
Backend.expects(:
|
131
|
-
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml")
|
132
|
-
Backend.expects(:datafile).with(:yaml, {}, "two", "yaml").returns("/nonexisting/two.yaml")
|
133
|
-
File.stubs(:exist?).with("/nonexisting/one.yaml").returns(true)
|
134
|
-
File.stubs(:exist?).with("/nonexisting/two.yaml").returns(true)
|
95
|
+
Backend.expects(:datasourcefiles).with(:yaml, {}, "yaml", nil).multiple_yields(["one", "/nonexisting/one.yaml"], ["two", "/nonexisting/two.yaml"])
|
135
96
|
|
136
97
|
@cache.expects(:read_file).with("/nonexisting/one.yaml", Hash).returns({"key"=>["a", "answer"]})
|
137
98
|
@cache.expects(:read_file).with("/nonexisting/two.yaml", Hash).returns({"key"=>{"a"=>"answer"}})
|
@@ -140,11 +101,7 @@ class Hiera
|
|
140
101
|
end
|
141
102
|
|
142
103
|
it "should fail when trying to merge an Array" do
|
143
|
-
Backend.expects(:
|
144
|
-
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml")
|
145
|
-
Backend.expects(:datafile).with(:yaml, {}, "two", "yaml").returns("/nonexisting/two.yaml")
|
146
|
-
File.stubs(:exist?).with("/nonexisting/one.yaml").returns(true)
|
147
|
-
File.stubs(:exist?).with("/nonexisting/two.yaml").returns(true)
|
104
|
+
Backend.expects(:datasourcefiles).with(:yaml, {}, "yaml", nil).multiple_yields(["one", "/nonexisting/one.yaml"], ["two", "/nonexisting/two.yaml"])
|
148
105
|
|
149
106
|
@cache.expects(:read_file).with("/nonexisting/one.yaml", Hash).returns({"key"=>{"a"=>"answer"}})
|
150
107
|
@cache.expects(:read_file).with("/nonexisting/two.yaml", Hash).returns({"key"=>["a", "wrong"]})
|
@@ -153,9 +110,7 @@ class Hiera
|
|
153
110
|
end
|
154
111
|
|
155
112
|
it "should parse the answer for scope variables" do
|
156
|
-
Backend.expects(:
|
157
|
-
Backend.expects(:datafile).with(:yaml, {"rspec" => "test"}, "one", "yaml").returns("/nonexisting/one.yaml")
|
158
|
-
File.stubs(:exist?).with("/nonexisting/one.yaml").returns(true)
|
113
|
+
Backend.expects(:datasourcefiles).with(:yaml, {"rspec" => "test"}, "yaml", nil).multiple_yields(["one", "/nonexisting/one.yaml"])
|
159
114
|
|
160
115
|
@cache.expects(:read_file).with("/nonexisting/one.yaml", Hash).returns({"key"=>"test_%{rspec}"})
|
161
116
|
|
@@ -163,9 +118,7 @@ class Hiera
|
|
163
118
|
end
|
164
119
|
|
165
120
|
it "should retain datatypes found in yaml files" do
|
166
|
-
Backend.expects(:
|
167
|
-
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml").times(3)
|
168
|
-
File.stubs(:exist?).with("/nonexisting/one.yaml").returns(true)
|
121
|
+
Backend.expects(:datasourcefiles).with(:yaml, {}, "yaml", nil).multiple_yields(["one", "/nonexisting/one.yaml"]).times(3)
|
169
122
|
|
170
123
|
|
171
124
|
@cache.value = "---\nstringval: 'string'\nboolval: true\nnumericval: 1"
|
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiera
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
5
|
-
prerelease:
|
4
|
+
version: 1.3.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Puppet Labs
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-05-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: json_pure
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
description: A pluggable data store for hierarcical data
|
@@ -35,70 +32,69 @@ extensions: []
|
|
35
32
|
extra_rdoc_files: []
|
36
33
|
files:
|
37
34
|
- bin/hiera
|
38
|
-
- lib/hiera.rb
|
39
|
-
- lib/hiera/console_logger.rb
|
40
|
-
- lib/hiera/noop_logger.rb
|
41
|
-
- lib/hiera/backend/yaml_backend.rb
|
35
|
+
- lib/hiera/backend.rb
|
42
36
|
- lib/hiera/backend/json_backend.rb
|
37
|
+
- lib/hiera/backend/yaml_backend.rb
|
38
|
+
- lib/hiera/config.rb
|
39
|
+
- lib/hiera/console_logger.rb
|
40
|
+
- lib/hiera/error.rb
|
43
41
|
- lib/hiera/fallback_logger.rb
|
44
42
|
- lib/hiera/filecache.rb
|
45
|
-
- lib/hiera/version.rb
|
46
|
-
- lib/hiera/config.rb
|
47
43
|
- lib/hiera/interpolate.rb
|
44
|
+
- lib/hiera/noop_logger.rb
|
45
|
+
- lib/hiera/puppet_logger.rb
|
48
46
|
- lib/hiera/recursive_guard.rb
|
49
47
|
- lib/hiera/util.rb
|
50
|
-
- lib/hiera/
|
51
|
-
- lib/hiera
|
52
|
-
- lib/hiera/error.rb
|
48
|
+
- lib/hiera/version.rb
|
49
|
+
- lib/hiera.rb
|
53
50
|
- COPYING
|
54
51
|
- README.md
|
55
52
|
- LICENSE
|
56
|
-
- spec/
|
57
|
-
- spec/unit/filecache_spec.rb
|
58
|
-
- spec/unit/backend/yaml_backend_spec.rb
|
53
|
+
- spec/spec_helper.rb
|
59
54
|
- spec/unit/backend/json_backend_spec.rb
|
60
|
-
- spec/unit/
|
55
|
+
- spec/unit/backend/yaml_backend_spec.rb
|
61
56
|
- spec/unit/backend_spec.rb
|
62
|
-
- spec/unit/version_spec.rb
|
63
|
-
- spec/unit/puppet_logger_spec.rb
|
64
57
|
- spec/unit/config_spec.rb
|
58
|
+
- spec/unit/console_logger_spec.rb
|
65
59
|
- spec/unit/fallback_logger_spec.rb
|
60
|
+
- spec/unit/filecache_spec.rb
|
61
|
+
- spec/unit/hiera_spec.rb
|
62
|
+
- spec/unit/puppet_logger_spec.rb
|
66
63
|
- spec/unit/util_spec.rb
|
67
|
-
- spec/
|
64
|
+
- spec/unit/version_spec.rb
|
68
65
|
homepage: https://github.com/puppetlabs/hiera
|
69
66
|
licenses: []
|
67
|
+
metadata: {}
|
70
68
|
post_install_message:
|
71
69
|
rdoc_options: []
|
72
70
|
require_paths:
|
73
71
|
- lib
|
74
72
|
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
-
none: false
|
76
73
|
requirements:
|
77
|
-
- -
|
74
|
+
- - '>='
|
78
75
|
- !ruby/object:Gem::Version
|
79
76
|
version: '0'
|
80
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
78
|
requirements:
|
83
|
-
- -
|
79
|
+
- - '>='
|
84
80
|
- !ruby/object:Gem::Version
|
85
81
|
version: '0'
|
86
82
|
requirements: []
|
87
83
|
rubyforge_project:
|
88
|
-
rubygems_version:
|
84
|
+
rubygems_version: 2.0.3
|
89
85
|
signing_key:
|
90
|
-
specification_version:
|
86
|
+
specification_version: 4
|
91
87
|
summary: Light weight hierarchical data store
|
92
88
|
test_files:
|
93
|
-
- spec/
|
94
|
-
- spec/unit/filecache_spec.rb
|
95
|
-
- spec/unit/backend/yaml_backend_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
96
90
|
- spec/unit/backend/json_backend_spec.rb
|
97
|
-
- spec/unit/
|
91
|
+
- spec/unit/backend/yaml_backend_spec.rb
|
98
92
|
- spec/unit/backend_spec.rb
|
99
|
-
- spec/unit/version_spec.rb
|
100
|
-
- spec/unit/puppet_logger_spec.rb
|
101
93
|
- spec/unit/config_spec.rb
|
94
|
+
- spec/unit/console_logger_spec.rb
|
102
95
|
- spec/unit/fallback_logger_spec.rb
|
96
|
+
- spec/unit/filecache_spec.rb
|
97
|
+
- spec/unit/hiera_spec.rb
|
98
|
+
- spec/unit/puppet_logger_spec.rb
|
103
99
|
- spec/unit/util_spec.rb
|
104
|
-
- spec/
|
100
|
+
- spec/unit/version_spec.rb
|