hiera 3.0.6-x64-mingw32 → 3.1.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91c3060292dceb13da5b99fe4189aee0b395a23e
4
- data.tar.gz: 5abce3cf33535c571d35114d50af19942a757dcd
3
+ metadata.gz: d13558560b89acbbd6720376162e7b5e7352c541
4
+ data.tar.gz: 6fd01d4e6590e18449bc6a70a43c46288e55e7ce
5
5
  SHA512:
6
- metadata.gz: 6d07c5edaced3dc0d2d29316aa6009b937194c2fa992702a828eeb6c4e5942b8dd87535c9e73a6556779207d131603f7de243dfcad2a1d379e2858e8bf857597
7
- data.tar.gz: 536c50491c59fa5f87235eaedf0bf73c89311bd890b8015e853d036b1c88f3e46860d8ff3490fe08133695fe38f1a7c06c30e0658ffb3d8b99e8fdcb759b5b27
6
+ metadata.gz: 69785d29b404ab6eca305dfa70167e8efdf7f72dc806938eb852bac48541118e197a857b6c59496583bd48c07816a116721d286738b2692b07863bbf96f62794
7
+ data.tar.gz: 0a5dfdc722e1c800339811f74a6e76354b380681f6d727f33285e383ff2a049bac1acaaface1705afea3e8c4e3f8cf205f7d935157f95419962593646877d39c
data/README.md CHANGED
@@ -210,7 +210,7 @@ require 'hiera'
210
210
  require 'puppet'
211
211
 
212
212
  # load the facts for example.com
213
- scope = YAML.load_file("/opt/puppetlabs/puppet/cache/yaml/facts/example.com.yaml").values
213
+ scope = YAML.load_file("/opt/puppetlabs/puppet/cache/yaml/facts/example.com.yaml")
214
214
 
215
215
  # create a new instance based on config file
216
216
  hiera = Hiera.new(:config => "/etc/puppetlabs/code/hiera.yaml")
data/lib/hiera/backend.rb CHANGED
@@ -2,7 +2,7 @@ require 'hiera/util'
2
2
  require 'hiera/interpolate'
3
3
 
4
4
  begin
5
- require 'deep_merge'
5
+ require 'deep_merge/rails_compat'
6
6
  rescue LoadError
7
7
  end
8
8
 
@@ -42,7 +42,7 @@ class Hiera
42
42
  "datadir for #{backend} cannot be an array")
43
43
  end
44
44
 
45
- parse_string(dir, scope)
45
+ interpolate_config(dir, scope, nil)
46
46
  end
47
47
 
48
48
  # Finds the path to a datafile based on the Backend#datadir
@@ -88,7 +88,7 @@ class Hiera
88
88
  hierarchy.insert(0, override) if override
89
89
 
90
90
  hierarchy.flatten.map do |source|
91
- source = parse_string(source, scope, {}, :order_override => override)
91
+ source = interpolate_config(source, scope, override)
92
92
  yield(source) unless source == "" or source =~ /(^\/|\/\/|\/$)/
93
93
  end
94
94
  end
@@ -186,10 +186,11 @@ class Hiera
186
186
  # :merge_behavior: {:native|:deep|:deeper}
187
187
  #
188
188
  # Deep merge options use the Hash utility function provided by [deep_merge](https://github.com/danielsdeleo/deep_merge)
189
+ # It uses the compatibility mode [deep_merge](https://github.com/danielsdeleo/deep_merge#using-deep_merge-in-rails)
189
190
  #
190
191
  # :native => Native Hash.merge
191
- # :deep => Use Hash.deep_merge
192
- # :deeper => Use Hash.deep_merge!
192
+ # :deep => Use Hash.deeper_merge
193
+ # :deeper => Use Hash.deeper_merge!
193
194
  #
194
195
  # @param left [Hash] left side of the merge
195
196
  # @param right [Hash] right side of the merge
@@ -208,9 +209,9 @@ class Hiera
208
209
 
209
210
  case behavior
210
211
  when :deeper,'deeper'
211
- left.deep_merge!(right, options)
212
+ left.deeper_merge!(right, options)
212
213
  when :deep,'deep'
213
- left.deep_merge(right, options)
214
+ left.deeper_merge(right, options)
214
215
  else # Native and undefined
215
216
  left.merge(right)
216
217
  end
@@ -263,8 +264,14 @@ class Hiera
263
264
  backend = (@backends[backend] ||= find_backend(backend_constant))
264
265
  found_in_backend = false
265
266
  new_answer = catch(:no_such_key) do
266
- value = backend.lookup(segments[0], scope, order_override, resolution_type, context)
267
- value = qualified_lookup(subsegments, value) unless subsegments.nil?
267
+ if subsegments.nil?
268
+ value = backend.lookup(key, scope, order_override, resolution_type, context)
269
+ elsif backend.respond_to?(:lookup_with_segments)
270
+ value = backend.lookup_with_segments(segments, scope, order_override, resolution_type, context)
271
+ else
272
+ value = backend.lookup(segments[0], scope, order_override, resolution_type, context)
273
+ value = qualified_lookup(subsegments, value) unless subsegments.nil?
274
+ end
268
275
  found_in_backend = true
269
276
  value
270
277
  end
@@ -320,6 +327,20 @@ class Hiera
320
327
  return backend.method(:lookup).arity == 4 ? Backend1xWrapper.new(backend) : backend
321
328
  end
322
329
  private :find_backend
330
+
331
+ def interpolate_config(entry, scope, override)
332
+ if @config_lookup_context.nil?
333
+ @config_lookup_context = { :is_interpolate_config => true, :order_override => override, :recurse_guard => Hiera::RecursiveGuard.new }
334
+ begin
335
+ Hiera::Interpolate.interpolate(entry, scope, {}, @config_lookup_context)
336
+ ensure
337
+ @config_lookup_context = nil
338
+ end
339
+ else
340
+ # Nested call (will happen when interpolate method 'hiera' is used)
341
+ Hiera::Interpolate.interpolate(entry, scope, {}, @config_lookup_context.merge(:order_override => override))
342
+ end
343
+ end
323
344
  end
324
345
  end
325
346
  end
data/lib/hiera/config.rb CHANGED
@@ -53,6 +53,7 @@ class Hiera::Config
53
53
  when :deep,'deep',:deeper,'deeper'
54
54
  begin
55
55
  require "deep_merge"
56
+ require "deep_merge/rails_compat"
56
57
  rescue LoadError
57
58
  raise Hiera::Error, "Must have 'deep_merge' gem installed for the configured merge_behavior."
58
59
  end
@@ -74,7 +75,7 @@ class Hiera::Config
74
75
  begin
75
76
  require "hiera/backend/#{backend.downcase}_backend"
76
77
  rescue LoadError => e
77
- Hiera.warn "Cannot load backend #{backend}: #{e}"
78
+ raise "Cannot load backend #{backend}: #{e}"
78
79
  end
79
80
  end
80
81
  end
@@ -21,7 +21,7 @@ class Hiera::Interpolate
21
21
 
22
22
  # Get interp method in case we are aliasing
23
23
  if data.is_a?(String) && (match = data.match(INTERPOLATION))
24
- interpolate_method, key = get_interpolation_method_and_key(data)
24
+ interpolate_method, key = get_interpolation_method_and_key(data, new_context)
25
25
  else
26
26
  interpolate_method = nil
27
27
  end
@@ -44,8 +44,15 @@ class Hiera::Interpolate
44
44
  def do_interpolation(data, scope, extra_data, context)
45
45
  if data.is_a?(String) && (match = data.match(INTERPOLATION))
46
46
  interpolation_variable = match[1]
47
+
48
+ # HI-494
49
+ case interpolation_variable.strip
50
+ when '', '::'
51
+ return ''
52
+ end
53
+
47
54
  context[:recurse_guard].check(interpolation_variable) do
48
- interpolate_method, key = get_interpolation_method_and_key(data)
55
+ interpolate_method, key = get_interpolation_method_and_key(data, context)
49
56
  interpolated_data = send(interpolate_method, data, key, scope, extra_data, context)
50
57
 
51
58
  # Halt recursion if we encounter a literal.
@@ -59,8 +66,9 @@ class Hiera::Interpolate
59
66
  end
60
67
  private :do_interpolation
61
68
 
62
- def get_interpolation_method_and_key(data)
69
+ def get_interpolation_method_and_key(data, context)
63
70
  if (match = data.match(METHOD_INTERPOLATION))
71
+ Hiera.warn('Use of interpolation methods in hiera configuration file is deprecated') if context[:is_interpolate_config]
64
72
  case match[1]
65
73
  when 'hiera' then [:hiera_interpolate, match[2]]
66
74
  when 'scope' then [:scope_interpolate, match[2]]
@@ -10,7 +10,7 @@ class Hiera::RecursiveGuard
10
10
 
11
11
  def check(value, &block)
12
12
  if @seen.include?(value)
13
- raise Hiera::InterpolationLoop, "Detected in [#{@seen.join(', ')}]"
13
+ raise Hiera::InterpolationLoop, "Lookup recursion detected in [#{@seen.join(', ')}]"
14
14
  end
15
15
  @seen.push(value)
16
16
  ret = yield
data/lib/hiera/version.rb CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
 
9
9
  class Hiera
10
- VERSION = "3.0.6"
10
+ VERSION = "3.1.0"
11
11
 
12
12
  ##
13
13
  # version is a public API method intended to always provide a fast and
@@ -11,6 +11,15 @@ class Hiera
11
11
  end
12
12
 
13
13
  describe Backend do
14
+ describe "loading non existing backend" do
15
+ it "fails if a backend cannot be loaded" do
16
+ Config.load({:datadir => "/tmp/%{interpolate}", :backends => ['bogus']})
17
+ expect do
18
+ Config.load_backends
19
+ end.to raise_error(/Cannot load backend bogus/)
20
+ end
21
+ end
22
+
14
23
  describe "#datadir" do
15
24
  it "interpolates any values in the configured value" do
16
25
  Config.load({:rspec => {:datadir => "/tmp/%{interpolate}"}})
@@ -92,8 +101,8 @@ class Hiera
92
101
  end
93
102
 
94
103
  it "parses the names of the hierarchy levels using the given scope" do
95
- Backend.expects(:parse_string).with('nodes/%{::trusted.certname}', {:rspec => :tests}, {}, {:order_override => nil})
96
- Backend.expects(:parse_string).with('common', {:rspec => :tests}, {}, {:order_override => nil})
104
+ Backend.expects(:interpolate_config).with('nodes/%{::trusted.certname}', {:rspec => :tests}, nil)
105
+ Backend.expects(:interpolate_config).with('common', {:rspec => :tests}, nil)
97
106
  Backend.datasources({:rspec => :tests}) { }
98
107
  end
99
108
 
@@ -248,7 +257,7 @@ class Hiera
248
257
  input = "test_%{first}_test"
249
258
  expect do
250
259
  Backend.parse_string(input, scope)
251
- end.to raise_error Hiera::InterpolationLoop, "Detected in [first, second]"
260
+ end.to raise_error Hiera::InterpolationLoop, "Lookup recursion detected in [first, second]"
252
261
  end
253
262
 
254
263
  it "replaces repeated occurances of the same lookup" do
@@ -713,30 +722,30 @@ class Hiera
713
722
 
714
723
  it "uses deep_merge! when configured with :merge_behavior => :deeper" do
715
724
  Config.load({:merge_behavior => :deeper})
716
- Hash.any_instance.expects('deep_merge!').with({"b" => "bnswer"}, {}).returns({"a" => "answer", "b" => "bnswer"})
725
+ Hash.any_instance.expects('deeper_merge!').with({"b" => "bnswer"}, {}).returns({"a" => "answer", "b" => "bnswer"})
717
726
  expect(Backend.merge_answer({"a" => "answer"},{"b" => "bnswer"})).to eq({"a" => "answer", "b" => "bnswer"})
718
727
  end
719
728
 
720
729
  it "uses deep_merge when configured with :merge_behavior => :deep" do
721
730
  Config.load({:merge_behavior => :deep})
722
- Hash.any_instance.expects('deep_merge').with({"b" => "bnswer"}, {}).returns({"a" => "answer", "b" => "bnswer"})
731
+ Hash.any_instance.expects('deeper_merge').with({"b" => "bnswer"}, {}).returns({"a" => "answer", "b" => "bnswer"})
723
732
  expect(Backend.merge_answer({"a" => "answer"},{"b" => "bnswer"})).to eq({"a" => "answer", "b" => "bnswer"})
724
733
  end
725
734
 
726
735
  it "disregards configuration when 'merge' parameter is given as a Hash" do
727
736
  Config.load({:merge_behavior => :deep})
728
- Hash.any_instance.expects('deep_merge!').with({"b" => "bnswer"}, {}).returns({"a" => "answer", "b" => "bnswer"})
737
+ Hash.any_instance.expects('deeper_merge!').with({"b" => "bnswer"}, {}).returns({"a" => "answer", "b" => "bnswer"})
729
738
  expect(Backend.merge_answer({"a" => "answer"},{"b" => "bnswer"}, {:behavior => 'deeper' })).to eq({"a" => "answer", "b" => "bnswer"})
730
739
  end
731
740
 
732
741
  it "propagates deep merge options when given Hash 'merge' parameter" do
733
- Hash.any_instance.expects('deep_merge!').with({"b" => "bnswer"}, { :knockout_prefix => '-' }).returns({"a" => "answer", "b" => "bnswer"})
742
+ Hash.any_instance.expects('deeper_merge!').with({"b" => "bnswer"}, { :knockout_prefix => '-' }).returns({"a" => "answer", "b" => "bnswer"})
734
743
  expect(Backend.merge_answer({"a" => "answer"},{"b" => "bnswer"}, {:behavior => 'deeper', :knockout_prefix => '-'})).to eq({"a" => "answer", "b" => "bnswer"})
735
744
  end
736
745
 
737
746
  it "passes Config[:deep_merge_options] into calls to deep_merge" do
738
747
  Config.load({:merge_behavior => :deep, :deep_merge_options => { :knockout_prefix => '-' } })
739
- Hash.any_instance.expects('deep_merge').with({"b" => "bnswer"}, {:knockout_prefix => '-'}).returns({"a" => "answer", "b" => "bnswer"})
748
+ Hash.any_instance.expects('deeper_merge').with({"b" => "bnswer"}, {:knockout_prefix => '-'}).returns({"a" => "answer", "b" => "bnswer"})
740
749
  expect(Backend.merge_answer({"a" => "answer"},{"b" => "bnswer"})).to eq({"a" => "answer", "b" => "bnswer"})
741
750
  end
742
751
  end
@@ -4,3 +4,4 @@
4
4
  :hierarchy:
5
5
  - recursive
6
6
  - niltest
7
+ - empty_%{}inter%{::}polation
@@ -0,0 +1,6 @@
1
+ :backends:
2
+ - json
3
+
4
+ :hierarchy:
5
+ - role
6
+ - "%{hiera('role')}"
@@ -0,0 +1,5 @@
1
+ :backends:
2
+ - yaml
3
+
4
+ :hierarchy:
5
+ - "%{hiera('role')}"
@@ -0,0 +1,6 @@
1
+ empty_interpolation: 'clown%{}shoe'
2
+ escaped_empty_interpolation: 'clown%%{}{shoe}s'
3
+ only_empty_interpolation: '%{}'
4
+ empty_namespace: '%{::}'
5
+ whitespace1: '%{ :: }'
6
+ whitespace2: '%{ }'
@@ -0,0 +1 @@
1
+ { "foo": "Foo" }
@@ -0,0 +1 @@
1
+ { "role": "frontend" }
@@ -10,7 +10,7 @@ describe "Hiera" do
10
10
  hiera = Hiera.new(:config => File.join(fixtures, 'config', 'hiera.yaml'))
11
11
  expect do
12
12
  hiera.lookup('foo', nil, {})
13
- end.to raise_error Hiera::InterpolationLoop, 'Detected in [hiera("bar"), hiera("foo")]'
13
+ end.to raise_error Hiera::InterpolationLoop, 'Lookup recursion detected in [hiera("bar"), hiera("foo")]'
14
14
  end
15
15
  end
16
16
 
@@ -24,6 +24,46 @@ describe "Hiera" do
24
24
  end
25
25
  end
26
26
 
27
+ context "when there are empty interpolations %{} in data" do
28
+ let(:fixtures) { File.join(HieraSpec::FIXTURE_DIR, 'interpolate') }
29
+
30
+ it 'should should produce an empty string for the interpolation' do
31
+ Hiera::Util.expects(:var_dir).at_least_once.returns(File.join(fixtures, 'data'))
32
+ hiera = Hiera.new(:config => File.join(fixtures, 'config', 'hiera.yaml'))
33
+ expect(hiera.lookup('empty_interpolation', nil, {})).to eq('clownshoe')
34
+ end
35
+
36
+ it 'the empty interpolation can be escaped' do
37
+ Hiera::Util.expects(:var_dir).at_least_once.returns(File.join(fixtures, 'data'))
38
+ hiera = Hiera.new(:config => File.join(fixtures, 'config', 'hiera.yaml'))
39
+ expect(hiera.lookup('escaped_empty_interpolation', nil, {})).to eq('clown%{shoe}s')
40
+ end
41
+
42
+ it 'the value can consist of only an empty escape' do
43
+ Hiera::Util.expects(:var_dir).at_least_once.returns(File.join(fixtures, 'data'))
44
+ hiera = Hiera.new(:config => File.join(fixtures, 'config', 'hiera.yaml'))
45
+ expect(hiera.lookup('only_empty_interpolation', nil, {})).to eq('')
46
+ end
47
+
48
+ it 'the value can consist of an empty namespace %{::}' do
49
+ Hiera::Util.expects(:var_dir).at_least_once.returns(File.join(fixtures, 'data'))
50
+ hiera = Hiera.new(:config => File.join(fixtures, 'config', 'hiera.yaml'))
51
+ expect(hiera.lookup('empty_namespace', nil, {})).to eq('')
52
+ end
53
+
54
+ it 'the value can consist of whitespace %{ :: }' do
55
+ Hiera::Util.expects(:var_dir).at_least_once.returns(File.join(fixtures, 'data'))
56
+ hiera = Hiera.new(:config => File.join(fixtures, 'config', 'hiera.yaml'))
57
+ expect(hiera.lookup('whitespace1', nil, {})).to eq('')
58
+ end
59
+
60
+ it 'the value can consist of whitespace %{ }' do
61
+ Hiera::Util.expects(:var_dir).at_least_once.returns(File.join(fixtures, 'data'))
62
+ hiera = Hiera.new(:config => File.join(fixtures, 'config', 'hiera.yaml'))
63
+ expect(hiera.lookup('whitespace2', nil, {})).to eq('')
64
+ end
65
+ end
66
+
27
67
  context "when doing interpolation with override" do
28
68
  let(:fixtures) { File.join(HieraSpec::FIXTURE_DIR, 'override') }
29
69
 
@@ -33,4 +73,27 @@ describe "Hiera" do
33
73
  expect(hiera.lookup('foo', nil, {}, 'alternate')).to eq('alternate')
34
74
  end
35
75
  end
76
+
77
+ context 'when doing interpolation in config file' do
78
+ let(:fixtures) { File.join(HieraSpec::FIXTURE_DIR, 'interpolate') }
79
+
80
+ it 'should allow and resolve a correctly configured interpolation using "hiera" method' do
81
+ Hiera::Util.expects(:var_dir).at_least_once.returns(File.join(fixtures, 'data'))
82
+ hiera = Hiera.new(:config => File.join(fixtures, 'config', 'hiera_iplm_hiera.yaml'))
83
+ expect(hiera.lookup('foo', nil, {})).to eq('Foo')
84
+ end
85
+
86
+ it 'should detect interpolation recursion when using "hiera" method' do
87
+ Hiera::Util.expects(:var_dir).at_least_once.returns(File.join(fixtures, 'data'))
88
+ hiera = Hiera.new(:config => File.join(fixtures, 'config', 'hiera_iplm_hiera_bad.yaml'))
89
+ expect{ hiera.lookup('foo', nil, {}) }.to raise_error(Hiera::InterpolationLoop, "Lookup recursion detected in [hiera('role')]")
90
+ end
91
+
92
+ it 'should issue warning when interpolation methods are used' do
93
+ Hiera.expects(:warn).with('Use of interpolation methods in hiera configuration file is deprecated').at_least_once
94
+ Hiera::Util.expects(:var_dir).at_least_once.returns(File.join(fixtures, 'data'))
95
+ hiera = Hiera.new(:config => File.join(fixtures, 'config', 'hiera_iplm_hiera.yaml'))
96
+ expect(hiera.lookup('foo', nil, {})).to eq('Foo')
97
+ end
98
+ end
36
99
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiera
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.6
4
+ version: 3.1.0
5
5
  platform: x64-mingw32
6
6
  authors:
7
7
  - Puppet Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-21 00:00:00.000000000 Z
11
+ date: 2016-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_pure
@@ -73,8 +73,13 @@ files:
73
73
  - spec/unit/fallback_logger_spec.rb
74
74
  - spec/unit/filecache_spec.rb
75
75
  - spec/unit/fixtures/interpolate/config/hiera.yaml
76
+ - spec/unit/fixtures/interpolate/config/hiera_iplm_hiera.yaml
77
+ - spec/unit/fixtures/interpolate/config/hiera_iplm_hiera_bad.yaml
78
+ - spec/unit/fixtures/interpolate/data/empty_interpolation.yaml
79
+ - spec/unit/fixtures/interpolate/data/frontend.json
76
80
  - spec/unit/fixtures/interpolate/data/niltest.yaml
77
81
  - spec/unit/fixtures/interpolate/data/recursive.yaml
82
+ - spec/unit/fixtures/interpolate/data/role.json
78
83
  - spec/unit/fixtures/override/config/hiera.yaml
79
84
  - spec/unit/fixtures/override/data/alternate.yaml
80
85
  - spec/unit/fixtures/override/data/common.yaml
@@ -116,8 +121,13 @@ test_files:
116
121
  - spec/unit/fallback_logger_spec.rb
117
122
  - spec/unit/filecache_spec.rb
118
123
  - spec/unit/fixtures/interpolate/config/hiera.yaml
124
+ - spec/unit/fixtures/interpolate/config/hiera_iplm_hiera.yaml
125
+ - spec/unit/fixtures/interpolate/config/hiera_iplm_hiera_bad.yaml
126
+ - spec/unit/fixtures/interpolate/data/empty_interpolation.yaml
127
+ - spec/unit/fixtures/interpolate/data/frontend.json
119
128
  - spec/unit/fixtures/interpolate/data/niltest.yaml
120
129
  - spec/unit/fixtures/interpolate/data/recursive.yaml
130
+ - spec/unit/fixtures/interpolate/data/role.json
121
131
  - spec/unit/fixtures/override/config/hiera.yaml
122
132
  - spec/unit/fixtures/override/data/alternate.yaml
123
133
  - spec/unit/fixtures/override/data/common.yaml