hiera 3.1.1-x86-mingw32 → 3.1.2-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hiera.rb +0 -1
- data/lib/hiera/backend.rb +15 -5
- data/lib/hiera/interpolate.rb +2 -2
- data/lib/hiera/version.rb +1 -1
- data/spec/unit/backend_spec.rb +28 -0
- data/spec/unit/fixtures/interpolate/data/dotted_keys.yaml +3 -0
- data/spec/unit/interpolate_spec.rb +8 -0
- metadata +50 -50
data/lib/hiera.rb
CHANGED
@@ -100,7 +100,6 @@ class Hiera
|
|
100
100
|
#
|
101
101
|
# - 'knockout_prefix' Set to string value to signify prefix which deletes elements from existing element. Defaults is _undef_
|
102
102
|
# - 'sort_merged_arrays' Set to _true_ to sort all arrays that are merged together. Default is _false_
|
103
|
-
# - 'unpack_arrays' Set to string value used as a deliminator to join all array values and then split them again. Default is _undef_
|
104
103
|
# - 'merge_hash_arrays' Set to _true_ to merge hashes within arrays. Default is _false_
|
105
104
|
#
|
106
105
|
# @param key [String] The key to lookup
|
data/lib/hiera/backend.rb
CHANGED
@@ -253,7 +253,9 @@ class Hiera
|
|
253
253
|
segments = Util.split_key(key) { |problem| ArgumentError.new("#{problem} in key: #{key}") }
|
254
254
|
subsegments = nil
|
255
255
|
if segments.size > 1
|
256
|
-
|
256
|
+
unless strategy.nil? || strategy == :priority
|
257
|
+
raise ArgumentError, "Resolution type :#{strategy} is illegal when accessing values using dotted keys. Offending key was '#{key}'"
|
258
|
+
end
|
257
259
|
subsegments = segments.drop(1)
|
258
260
|
end
|
259
261
|
|
@@ -270,7 +272,7 @@ class Hiera
|
|
270
272
|
value = backend.lookup_with_segments(segments, scope, order_override, resolution_type, context)
|
271
273
|
else
|
272
274
|
value = backend.lookup(segments[0], scope, order_override, resolution_type, context)
|
273
|
-
value = qualified_lookup(subsegments, value) unless subsegments.nil?
|
275
|
+
value = qualified_lookup(subsegments, value, key) unless subsegments.nil?
|
274
276
|
end
|
275
277
|
found_in_backend = true
|
276
278
|
value
|
@@ -305,16 +307,24 @@ class Hiera
|
|
305
307
|
@backends = {}
|
306
308
|
end
|
307
309
|
|
308
|
-
def qualified_lookup(segments, hash)
|
310
|
+
def qualified_lookup(segments, hash, full_key = nil)
|
309
311
|
value = hash
|
310
312
|
segments.each do |segment|
|
311
313
|
throw :no_such_key if value.nil?
|
312
314
|
if segment =~ /^[0-9]+$/
|
313
315
|
segment = segment.to_i
|
314
|
-
|
316
|
+
unless value.instance_of?(Array)
|
317
|
+
suffix = full_key.nil? ? '' : " from key '#{full_key}'"
|
318
|
+
raise Exception,
|
319
|
+
"Hiera type mismatch: Got #{value.class.name} when Array was expected to access value using '#{segment}'#{suffix}"
|
320
|
+
end
|
315
321
|
throw :no_such_key unless segment < value.size
|
316
322
|
else
|
317
|
-
|
323
|
+
unless value.respond_to?(:'[]') && !(value.instance_of?(Array) || value.instance_of?(String))
|
324
|
+
suffix = full_key.nil? ? '' : " from key '#{full_key}'"
|
325
|
+
raise Exception,
|
326
|
+
"Hiera type mismatch: Got #{value.class.name} when a hash-like object was expected to access value using '#{segment}'#{suffix}"
|
327
|
+
end
|
318
328
|
throw :no_such_key unless value.include?(segment)
|
319
329
|
end
|
320
330
|
value = value[segment]
|
data/lib/hiera/interpolate.rb
CHANGED
@@ -98,8 +98,8 @@ class Hiera::Interpolate
|
|
98
98
|
|
99
99
|
def scope_interpolate(data, key, scope, extra_data, context)
|
100
100
|
segments = Hiera::Util.split_key(key) { |problem| Hiera::InterpolationInvalidValue.new("#{problem} in interpolation expression: #{data}") }
|
101
|
-
catch(:no_such_key) { return Hiera::Backend.qualified_lookup(segments, scope) }
|
102
|
-
catch(:no_such_key) { Hiera::Backend.qualified_lookup(segments, extra_data) }
|
101
|
+
catch(:no_such_key) { return Hiera::Backend.qualified_lookup(segments, scope, key) }
|
102
|
+
catch(:no_such_key) { Hiera::Backend.qualified_lookup(segments, extra_data, key) }
|
103
103
|
end
|
104
104
|
private :scope_interpolate
|
105
105
|
|
data/lib/hiera/version.rb
CHANGED
data/spec/unit/backend_spec.rb
CHANGED
@@ -682,6 +682,34 @@ class Hiera
|
|
682
682
|
expect(Backend.lookup('key.33', 'dflt', {}, nil, nil)).to eq('dflt')
|
683
683
|
end
|
684
684
|
|
685
|
+
it 'will fail when dotted key access is made using a numeric index and value is not array' do
|
686
|
+
Config.load({:yaml => {:datadir => '/tmp'}})
|
687
|
+
Config.load_backends
|
688
|
+
Backend::Yaml_backend.any_instance.expects(:lookup).with('key', {}, nil, nil, instance_of(Hash)).returns(
|
689
|
+
{'one' => 'value 1', 'two' => 'value 2'})
|
690
|
+
expect {Backend.lookup('key.33', 'dflt', {}, nil, nil)}.to raise_error(Exception,
|
691
|
+
/Got Hash when Array was expected to access value using '33' from key 'key.33'/)
|
692
|
+
end
|
693
|
+
|
694
|
+
it 'will fail when dotted key access is made using a string and value is not hash' do
|
695
|
+
Config.load({:yaml => {:datadir => '/tmp'}})
|
696
|
+
Config.load_backends
|
697
|
+
Backend::Yaml_backend.any_instance.expects(:lookup).with('key', {}, nil, nil, instance_of(Hash)).returns(
|
698
|
+
['value 1', 'value 2'])
|
699
|
+
expect {Backend.lookup('key.one', 'dflt', {}, nil, nil)}.to raise_error(Exception,
|
700
|
+
/Got Array when a hash-like object was expected to access value using 'one' from key 'key.one'/)
|
701
|
+
end
|
702
|
+
|
703
|
+
it 'will fail when dotted key access is made using resolution type :hash' do
|
704
|
+
expect {Backend.lookup('key.one', 'dflt', {}, nil, :hash)}.to raise_error(Exception,
|
705
|
+
/Resolution type :hash is illegal when accessing values using dotted keys. Offending key was 'key.one'/)
|
706
|
+
end
|
707
|
+
|
708
|
+
it 'will fail when dotted key access is made using resolution type :array' do
|
709
|
+
expect {Backend.lookup('key.one', 'dflt', {}, nil, :array)}.to raise_error(Exception,
|
710
|
+
/Resolution type :array is illegal when accessing values using dotted keys. Offending key was 'key.one'/)
|
711
|
+
end
|
712
|
+
|
685
713
|
it 'can use qualified key in interpolation to lookup value in hash' do
|
686
714
|
Config.load({:yaml => {:datadir => '/tmp'}})
|
687
715
|
Config.load_backends
|
@@ -163,6 +163,14 @@ describe "Hiera" do
|
|
163
163
|
it 'should not find a subkey when the dotted key is quoted with method hiera' do
|
164
164
|
expect(hiera.lookup('"a.f.hiera"', nil, {'a' => { 'f' => '(scope) a dot f is a hash entry'}})).to eq('a dot f: ')
|
165
165
|
end
|
166
|
+
|
167
|
+
it 'should not find a subkey that is matched within a string' do
|
168
|
+
expect{ hiera.lookup('ipl_key', nil, {}) }.to raise_error(/Got String when a hash-like object was expected to access value using 'subkey' from key 'key.subkey'/)
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'should not find a subkey that is matched within a string' do
|
172
|
+
expect{ hiera.lookup('key.subkey', nil, {}) }.to raise_error(/Got String when a hash-like object was expected to access value using 'subkey' from key 'key.subkey'/)
|
173
|
+
end
|
166
174
|
end
|
167
175
|
|
168
176
|
context 'when bad interpolation expressions are encountered' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiera
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: x86-mingw32
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-04-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json_pure
|
@@ -67,52 +67,52 @@ extensions: []
|
|
67
67
|
extra_rdoc_files: []
|
68
68
|
files:
|
69
69
|
- bin/hiera
|
70
|
-
- lib/hiera/
|
71
|
-
- lib/hiera/
|
72
|
-
- lib/hiera/backend/yaml_backend.rb
|
73
|
-
- lib/hiera/config.rb
|
74
|
-
- lib/hiera/console_logger.rb
|
70
|
+
- lib/hiera/version.rb
|
71
|
+
- lib/hiera/noop_logger.rb
|
75
72
|
- lib/hiera/error.rb
|
76
73
|
- lib/hiera/fallback_logger.rb
|
74
|
+
- lib/hiera/recursive_guard.rb
|
75
|
+
- lib/hiera/backend/yaml_backend.rb
|
76
|
+
- lib/hiera/backend/json_backend.rb
|
77
|
+
- lib/hiera/config.rb
|
77
78
|
- lib/hiera/filecache.rb
|
78
79
|
- lib/hiera/interpolate.rb
|
79
|
-
- lib/hiera/
|
80
|
+
- lib/hiera/console_logger.rb
|
80
81
|
- lib/hiera/puppet_logger.rb
|
81
|
-
- lib/hiera/recursive_guard.rb
|
82
82
|
- lib/hiera/util.rb
|
83
|
-
- lib/hiera/
|
83
|
+
- lib/hiera/backend.rb
|
84
84
|
- lib/hiera.rb
|
85
85
|
- COPYING
|
86
86
|
- README.md
|
87
87
|
- LICENSE
|
88
|
-
- spec/
|
89
|
-
- spec/unit/
|
90
|
-
- spec/unit/
|
91
|
-
- spec/unit/
|
92
|
-
- spec/unit/config_spec.rb
|
93
|
-
- spec/unit/console_logger_spec.rb
|
94
|
-
- spec/unit/fallback_logger_spec.rb
|
95
|
-
- spec/unit/filecache_spec.rb
|
96
|
-
- spec/unit/fixtures/interpolate/config/hiera.yaml
|
88
|
+
- spec/unit/interpolate_spec.rb
|
89
|
+
- spec/unit/fixtures/override/config/hiera.yaml
|
90
|
+
- spec/unit/fixtures/override/data/alternate.yaml
|
91
|
+
- spec/unit/fixtures/override/data/common.yaml
|
97
92
|
- spec/unit/fixtures/interpolate/config/hiera_iplm_hiera.yaml
|
98
93
|
- spec/unit/fixtures/interpolate/config/hiera_iplm_hiera_bad.yaml
|
99
|
-
- spec/unit/fixtures/interpolate/
|
94
|
+
- spec/unit/fixtures/interpolate/config/hiera.yaml
|
95
|
+
- spec/unit/fixtures/interpolate/data/niltest.yaml
|
100
96
|
- spec/unit/fixtures/interpolate/data/complex.yaml
|
101
|
-
- spec/unit/fixtures/interpolate/data/dotted_keys.yaml
|
102
|
-
- spec/unit/fixtures/interpolate/data/empty_interpolation.yaml
|
103
97
|
- spec/unit/fixtures/interpolate/data/frontend.json
|
104
|
-
- spec/unit/fixtures/interpolate/data/niltest.yaml
|
105
|
-
- spec/unit/fixtures/interpolate/data/recursive.yaml
|
106
98
|
- spec/unit/fixtures/interpolate/data/role.json
|
99
|
+
- spec/unit/fixtures/interpolate/data/bad_interpolation.yaml
|
100
|
+
- spec/unit/fixtures/interpolate/data/dotted_keys.yaml
|
107
101
|
- spec/unit/fixtures/interpolate/data/weird_keys.yaml
|
108
|
-
- spec/unit/fixtures/
|
109
|
-
- spec/unit/fixtures/
|
110
|
-
- spec/unit/
|
111
|
-
- spec/unit/
|
112
|
-
- spec/unit/
|
102
|
+
- spec/unit/fixtures/interpolate/data/empty_interpolation.yaml
|
103
|
+
- spec/unit/fixtures/interpolate/data/recursive.yaml
|
104
|
+
- spec/unit/backend_spec.rb
|
105
|
+
- spec/unit/filecache_spec.rb
|
106
|
+
- spec/unit/config_spec.rb
|
107
|
+
- spec/unit/backend/yaml_backend_spec.rb
|
108
|
+
- spec/unit/backend/json_backend_spec.rb
|
113
109
|
- spec/unit/puppet_logger_spec.rb
|
114
|
-
- spec/unit/
|
110
|
+
- spec/unit/console_logger_spec.rb
|
115
111
|
- spec/unit/version_spec.rb
|
112
|
+
- spec/unit/fallback_logger_spec.rb
|
113
|
+
- spec/unit/util_spec.rb
|
114
|
+
- spec/unit/hiera_spec.rb
|
115
|
+
- spec/spec_helper.rb
|
116
116
|
homepage: https://github.com/puppetlabs/hiera
|
117
117
|
licenses: []
|
118
118
|
post_install_message:
|
@@ -138,31 +138,31 @@ signing_key:
|
|
138
138
|
specification_version: 3
|
139
139
|
summary: Light weight hierarchical data store
|
140
140
|
test_files:
|
141
|
-
- spec/
|
142
|
-
- spec/unit/
|
143
|
-
- spec/unit/
|
144
|
-
- spec/unit/
|
145
|
-
- spec/unit/config_spec.rb
|
146
|
-
- spec/unit/console_logger_spec.rb
|
147
|
-
- spec/unit/fallback_logger_spec.rb
|
148
|
-
- spec/unit/filecache_spec.rb
|
149
|
-
- spec/unit/fixtures/interpolate/config/hiera.yaml
|
141
|
+
- spec/unit/interpolate_spec.rb
|
142
|
+
- spec/unit/fixtures/override/config/hiera.yaml
|
143
|
+
- spec/unit/fixtures/override/data/alternate.yaml
|
144
|
+
- spec/unit/fixtures/override/data/common.yaml
|
150
145
|
- spec/unit/fixtures/interpolate/config/hiera_iplm_hiera.yaml
|
151
146
|
- spec/unit/fixtures/interpolate/config/hiera_iplm_hiera_bad.yaml
|
152
|
-
- spec/unit/fixtures/interpolate/
|
147
|
+
- spec/unit/fixtures/interpolate/config/hiera.yaml
|
148
|
+
- spec/unit/fixtures/interpolate/data/niltest.yaml
|
153
149
|
- spec/unit/fixtures/interpolate/data/complex.yaml
|
154
|
-
- spec/unit/fixtures/interpolate/data/dotted_keys.yaml
|
155
|
-
- spec/unit/fixtures/interpolate/data/empty_interpolation.yaml
|
156
150
|
- spec/unit/fixtures/interpolate/data/frontend.json
|
157
|
-
- spec/unit/fixtures/interpolate/data/niltest.yaml
|
158
|
-
- spec/unit/fixtures/interpolate/data/recursive.yaml
|
159
151
|
- spec/unit/fixtures/interpolate/data/role.json
|
152
|
+
- spec/unit/fixtures/interpolate/data/bad_interpolation.yaml
|
153
|
+
- spec/unit/fixtures/interpolate/data/dotted_keys.yaml
|
160
154
|
- spec/unit/fixtures/interpolate/data/weird_keys.yaml
|
161
|
-
- spec/unit/fixtures/
|
162
|
-
- spec/unit/fixtures/
|
163
|
-
- spec/unit/
|
164
|
-
- spec/unit/
|
165
|
-
- spec/unit/
|
155
|
+
- spec/unit/fixtures/interpolate/data/empty_interpolation.yaml
|
156
|
+
- spec/unit/fixtures/interpolate/data/recursive.yaml
|
157
|
+
- spec/unit/backend_spec.rb
|
158
|
+
- spec/unit/filecache_spec.rb
|
159
|
+
- spec/unit/config_spec.rb
|
160
|
+
- spec/unit/backend/yaml_backend_spec.rb
|
161
|
+
- spec/unit/backend/json_backend_spec.rb
|
166
162
|
- spec/unit/puppet_logger_spec.rb
|
167
|
-
- spec/unit/
|
163
|
+
- spec/unit/console_logger_spec.rb
|
168
164
|
- spec/unit/version_spec.rb
|
165
|
+
- spec/unit/fallback_logger_spec.rb
|
166
|
+
- spec/unit/util_spec.rb
|
167
|
+
- spec/unit/hiera_spec.rb
|
168
|
+
- spec/spec_helper.rb
|