hiera 3.1.1-x64-mingw32 → 3.1.2-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
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
- raise ArgumentError, "Resolution type :#{strategy} is illegal when doing segmented key lookups" unless strategy.nil? || strategy == :priority
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
- raise Exception, "Hiera type mismatch: Got #{value.class.name} when Array was expected enable lookup using key '#{segment}'" unless value.instance_of?(Array)
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
- raise Exception, "Hiera type mismatch: Got #{value.class.name} when a non Array object that responds to '[]' was expected to enable lookup using key '#{segment}'" unless value.respond_to?(:'[]') && !value.instance_of?(Array);
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]
@@ -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
@@ -7,7 +7,7 @@
7
7
 
8
8
 
9
9
  class Hiera
10
- VERSION = "3.1.1"
10
+ VERSION = "3.1.2"
11
11
 
12
12
  ##
13
13
  # version is a public API method intended to always provide a fast and
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
@@ -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
@@ -38,3 +38,6 @@ a.f.hiera: 'a dot f: %{hiera("''a.d''")}'
38
38
  x.1: '(hiera) x dot 1'
39
39
  x.2.scope: "x dot 2: %{'x.1'}"
40
40
  x.2.hiera: 'x dot 2: %{hiera("''x.1''")}'
41
+
42
+ key: subkey
43
+ ipl_key: '- %{hiera("key.subkey")} -'
@@ -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.1
4
+ version: 3.1.2
5
5
  prerelease:
6
6
  platform: x64-mingw32
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-23 00:00:00.000000000 Z
12
+ date: 2016-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json_pure
@@ -51,52 +51,52 @@ extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
53
  - bin/hiera
54
- - lib/hiera/backend.rb
55
- - lib/hiera/backend/json_backend.rb
56
- - lib/hiera/backend/yaml_backend.rb
57
- - lib/hiera/config.rb
58
- - lib/hiera/console_logger.rb
54
+ - lib/hiera/version.rb
55
+ - lib/hiera/noop_logger.rb
59
56
  - lib/hiera/error.rb
60
57
  - lib/hiera/fallback_logger.rb
58
+ - lib/hiera/recursive_guard.rb
59
+ - lib/hiera/backend/yaml_backend.rb
60
+ - lib/hiera/backend/json_backend.rb
61
+ - lib/hiera/config.rb
61
62
  - lib/hiera/filecache.rb
62
63
  - lib/hiera/interpolate.rb
63
- - lib/hiera/noop_logger.rb
64
+ - lib/hiera/console_logger.rb
64
65
  - lib/hiera/puppet_logger.rb
65
- - lib/hiera/recursive_guard.rb
66
66
  - lib/hiera/util.rb
67
- - lib/hiera/version.rb
67
+ - lib/hiera/backend.rb
68
68
  - lib/hiera.rb
69
69
  - COPYING
70
70
  - README.md
71
71
  - LICENSE
72
- - spec/spec_helper.rb
73
- - spec/unit/backend/json_backend_spec.rb
74
- - spec/unit/backend/yaml_backend_spec.rb
75
- - spec/unit/backend_spec.rb
76
- - spec/unit/config_spec.rb
77
- - spec/unit/console_logger_spec.rb
78
- - spec/unit/fallback_logger_spec.rb
79
- - spec/unit/filecache_spec.rb
80
- - spec/unit/fixtures/interpolate/config/hiera.yaml
72
+ - spec/unit/interpolate_spec.rb
73
+ - spec/unit/fixtures/override/config/hiera.yaml
74
+ - spec/unit/fixtures/override/data/alternate.yaml
75
+ - spec/unit/fixtures/override/data/common.yaml
81
76
  - spec/unit/fixtures/interpolate/config/hiera_iplm_hiera.yaml
82
77
  - spec/unit/fixtures/interpolate/config/hiera_iplm_hiera_bad.yaml
83
- - spec/unit/fixtures/interpolate/data/bad_interpolation.yaml
78
+ - spec/unit/fixtures/interpolate/config/hiera.yaml
79
+ - spec/unit/fixtures/interpolate/data/niltest.yaml
84
80
  - spec/unit/fixtures/interpolate/data/complex.yaml
85
- - spec/unit/fixtures/interpolate/data/dotted_keys.yaml
86
- - spec/unit/fixtures/interpolate/data/empty_interpolation.yaml
87
81
  - spec/unit/fixtures/interpolate/data/frontend.json
88
- - spec/unit/fixtures/interpolate/data/niltest.yaml
89
- - spec/unit/fixtures/interpolate/data/recursive.yaml
90
82
  - spec/unit/fixtures/interpolate/data/role.json
83
+ - spec/unit/fixtures/interpolate/data/bad_interpolation.yaml
84
+ - spec/unit/fixtures/interpolate/data/dotted_keys.yaml
91
85
  - spec/unit/fixtures/interpolate/data/weird_keys.yaml
92
- - spec/unit/fixtures/override/config/hiera.yaml
93
- - spec/unit/fixtures/override/data/alternate.yaml
94
- - spec/unit/fixtures/override/data/common.yaml
95
- - spec/unit/hiera_spec.rb
96
- - spec/unit/interpolate_spec.rb
86
+ - spec/unit/fixtures/interpolate/data/empty_interpolation.yaml
87
+ - spec/unit/fixtures/interpolate/data/recursive.yaml
88
+ - spec/unit/backend_spec.rb
89
+ - spec/unit/filecache_spec.rb
90
+ - spec/unit/config_spec.rb
91
+ - spec/unit/backend/yaml_backend_spec.rb
92
+ - spec/unit/backend/json_backend_spec.rb
97
93
  - spec/unit/puppet_logger_spec.rb
98
- - spec/unit/util_spec.rb
94
+ - spec/unit/console_logger_spec.rb
99
95
  - spec/unit/version_spec.rb
96
+ - spec/unit/fallback_logger_spec.rb
97
+ - spec/unit/util_spec.rb
98
+ - spec/unit/hiera_spec.rb
99
+ - spec/spec_helper.rb
100
100
  homepage: https://github.com/puppetlabs/hiera
101
101
  licenses: []
102
102
  post_install_message:
@@ -122,31 +122,31 @@ signing_key:
122
122
  specification_version: 3
123
123
  summary: Light weight hierarchical data store
124
124
  test_files:
125
- - spec/spec_helper.rb
126
- - spec/unit/backend/json_backend_spec.rb
127
- - spec/unit/backend/yaml_backend_spec.rb
128
- - spec/unit/backend_spec.rb
129
- - spec/unit/config_spec.rb
130
- - spec/unit/console_logger_spec.rb
131
- - spec/unit/fallback_logger_spec.rb
132
- - spec/unit/filecache_spec.rb
133
- - spec/unit/fixtures/interpolate/config/hiera.yaml
125
+ - spec/unit/interpolate_spec.rb
126
+ - spec/unit/fixtures/override/config/hiera.yaml
127
+ - spec/unit/fixtures/override/data/alternate.yaml
128
+ - spec/unit/fixtures/override/data/common.yaml
134
129
  - spec/unit/fixtures/interpolate/config/hiera_iplm_hiera.yaml
135
130
  - spec/unit/fixtures/interpolate/config/hiera_iplm_hiera_bad.yaml
136
- - spec/unit/fixtures/interpolate/data/bad_interpolation.yaml
131
+ - spec/unit/fixtures/interpolate/config/hiera.yaml
132
+ - spec/unit/fixtures/interpolate/data/niltest.yaml
137
133
  - spec/unit/fixtures/interpolate/data/complex.yaml
138
- - spec/unit/fixtures/interpolate/data/dotted_keys.yaml
139
- - spec/unit/fixtures/interpolate/data/empty_interpolation.yaml
140
134
  - spec/unit/fixtures/interpolate/data/frontend.json
141
- - spec/unit/fixtures/interpolate/data/niltest.yaml
142
- - spec/unit/fixtures/interpolate/data/recursive.yaml
143
135
  - spec/unit/fixtures/interpolate/data/role.json
136
+ - spec/unit/fixtures/interpolate/data/bad_interpolation.yaml
137
+ - spec/unit/fixtures/interpolate/data/dotted_keys.yaml
144
138
  - spec/unit/fixtures/interpolate/data/weird_keys.yaml
145
- - spec/unit/fixtures/override/config/hiera.yaml
146
- - spec/unit/fixtures/override/data/alternate.yaml
147
- - spec/unit/fixtures/override/data/common.yaml
148
- - spec/unit/hiera_spec.rb
149
- - spec/unit/interpolate_spec.rb
139
+ - spec/unit/fixtures/interpolate/data/empty_interpolation.yaml
140
+ - spec/unit/fixtures/interpolate/data/recursive.yaml
141
+ - spec/unit/backend_spec.rb
142
+ - spec/unit/filecache_spec.rb
143
+ - spec/unit/config_spec.rb
144
+ - spec/unit/backend/yaml_backend_spec.rb
145
+ - spec/unit/backend/json_backend_spec.rb
150
146
  - spec/unit/puppet_logger_spec.rb
151
- - spec/unit/util_spec.rb
147
+ - spec/unit/console_logger_spec.rb
152
148
  - spec/unit/version_spec.rb
149
+ - spec/unit/fallback_logger_spec.rb
150
+ - spec/unit/util_spec.rb
151
+ - spec/unit/hiera_spec.rb
152
+ - spec/spec_helper.rb