poise-hoist 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/.travis.yml +56 -20
  4. data/.yardopts +2 -0
  5. data/.yo-rc.json +7 -0
  6. data/CHANGELOG.md +4 -0
  7. data/Gemfile +2 -2
  8. data/LICENSE +201 -202
  9. data/README.md +26 -2
  10. data/Rakefile +1 -1
  11. data/chef/attributes/default.rb +4 -1
  12. data/chef/recipes/default.rb +1 -1
  13. data/lib/poise_hoist.rb +52 -1
  14. data/lib/poise_hoist/cheftie.rb +1 -1
  15. data/lib/poise_hoist/version.rb +2 -2
  16. data/poise-hoist.gemspec +5 -3
  17. data/test/cookbook/attributes/default.rb +2 -1
  18. data/test/cookbook/metadata.rb +1 -1
  19. data/test/cookbook/recipes/default.rb +1 -1
  20. data/test/gemfiles/chef-12.10.gemfile +26 -0
  21. data/test/gemfiles/chef-12.11.gemfile +26 -0
  22. data/test/gemfiles/chef-12.12.gemfile +25 -0
  23. data/test/gemfiles/chef-12.13.gemfile +25 -0
  24. data/test/gemfiles/chef-12.14.gemfile +21 -0
  25. data/test/gemfiles/chef-12.15.gemfile +21 -0
  26. data/test/gemfiles/chef-12.16.gemfile +21 -0
  27. data/test/gemfiles/chef-12.17.gemfile +21 -0
  28. data/test/gemfiles/chef-12.18.gemfile +20 -0
  29. data/test/gemfiles/chef-12.19.gemfile +20 -0
  30. data/test/gemfiles/chef-12.2.gemfile +7 -1
  31. data/test/gemfiles/chef-12.3.gemfile +7 -1
  32. data/test/gemfiles/chef-12.4.gemfile +8 -1
  33. data/test/gemfiles/chef-12.5.gemfile +7 -1
  34. data/test/gemfiles/chef-12.6.gemfile +7 -1
  35. data/test/gemfiles/chef-12.7.gemfile +7 -1
  36. data/test/gemfiles/chef-12.8.gemfile +8 -2
  37. data/test/gemfiles/chef-12.9.gemfile +26 -0
  38. data/test/gemfiles/chef-12.gemfile +3 -3
  39. data/test/gemfiles/chef-13.0.gemfile +19 -0
  40. data/test/gemfiles/chef-13.gemfile +19 -0
  41. data/test/gemfiles/master.gemfile +10 -6
  42. data/test/integration/data_bags/hoist/local.json +6 -0
  43. data/test/integration/default/default_spec.rb +2 -2
  44. data/test/integration/default_policy.rb +3 -1
  45. data/test/spec/fixtures/encrypted-node.json +10 -0
  46. data/test/spec/fixtures/key +1 -0
  47. data/test/spec/fixtures/mygroup.json +7 -0
  48. data/test/spec/fixtures/test-node.json +10 -0
  49. data/test/spec/poise_hoist_spec.rb +65 -6
  50. data/test/spec/spec_helper.rb +1 -1
  51. metadata +73 -10
@@ -0,0 +1,20 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.18.31'
20
+ gem 'cheffish', '< 13'
@@ -0,0 +1,20 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.19.36'
20
+ gem 'cheffish', '< 13'
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright 2016, Noah Kantrowitz
2
+ # Copyright 2016-2017, Noah Kantrowitz
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -17,4 +17,10 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.2.1'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
20
22
  gem 'chef-dk', '~> 0.10.0'
23
+ gem 'mixlib-install', '>= 2'
24
+ gem 'fauxhai', '<= 3.9.0'
25
+ gem 'cheffish', '< 13'
26
+ gem 'chefspec', '< 6'
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright 2016, Noah Kantrowitz
2
+ # Copyright 2016-2017, Noah Kantrowitz
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -17,4 +17,10 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.3.0'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
20
22
  gem 'chef-dk', '~> 0.10.0'
23
+ gem 'mixlib-install', '>= 2'
24
+ gem 'fauxhai', '<= 3.9.0'
25
+ gem 'cheffish', '< 13'
26
+ gem 'chefspec', '< 6'
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright 2016, Noah Kantrowitz
2
+ # Copyright 2016-2017, Noah Kantrowitz
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -17,4 +17,11 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.4.3'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
20
22
  gem 'chef-dk', '~> 0.10.0'
23
+ gem 'mixlib-install', '>= 2'
24
+ gem 'fauxhai', '<= 3.9.0'
25
+ gem 'gh', '0.14.0'
26
+ gem 'cheffish', '< 13'
27
+ gem 'chefspec', '< 6'
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright 2016, Noah Kantrowitz
2
+ # Copyright 2016-2017, Noah Kantrowitz
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -17,4 +17,10 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.5.1'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
20
22
  gem 'chef-dk', '~> 0.10.0'
23
+ gem 'mixlib-install', '>= 2'
24
+ gem 'fauxhai', '<= 3.9.0'
25
+ gem 'cheffish', '< 13'
26
+ gem 'chefspec', '< 6'
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright 2016, Noah Kantrowitz
2
+ # Copyright 2016-2017, Noah Kantrowitz
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -17,4 +17,10 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.6.0'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
20
22
  gem 'chef-dk', '~> 0.10.0'
23
+ gem 'mixlib-install', '>= 2'
24
+ gem 'fauxhai', '<= 3.9.0'
25
+ gem 'cheffish', '< 13'
26
+ gem 'chefspec', '< 6'
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright 2016, Noah Kantrowitz
2
+ # Copyright 2016-2017, Noah Kantrowitz
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -17,4 +17,10 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.7.2'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
20
22
  gem 'chef-dk', '~> 0.11.0'
23
+ gem 'mixlib-install', '>= 2'
24
+ gem 'fauxhai', '<= 3.9.0'
25
+ gem 'cheffish', '< 13'
26
+ gem 'chefspec', '< 6'
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright 2016, Noah Kantrowitz
2
+ # Copyright 2016-2017, Noah Kantrowitz
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -17,4 +17,10 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.8.1'
20
- gem 'chef-dk', '~> 0.12'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
22
+ gem 'chef-dk', '~> 0.12.0'
23
+ gem 'mixlib-install', '>= 2'
24
+ gem 'fauxhai', '<= 3.9.0'
25
+ gem 'cheffish', '< 13'
26
+ gem 'chefspec', '< 6'
@@ -0,0 +1,26 @@
1
+ #
2
+ # Copyright 2016-2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.9.41'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
22
+ gem 'chef-dk', '~> 0.13.0'
23
+ gem 'mixlib-install', '>= 2'
24
+ gem 'fauxhai', '<= 3.9.0'
25
+ gem 'cheffish', '< 13'
26
+ gem 'chefspec', '< 6'
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright 2016, Noah Kantrowitz
2
+ # Copyright 2016-2017, Noah Kantrowitz
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -16,5 +16,5 @@
16
16
 
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
- gem 'chef', '~> 12.9'
20
- gem 'chef-dk', '~> 0.12'
19
+ gem 'chef', '~> 12.19'
20
+ gem 'cheffish', '< 13'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 13.0.118'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 13.0'
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright 2016, Noah Kantrowitz
2
+ # Copyright 2016-2017, Noah Kantrowitz
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -16,8 +16,12 @@
16
16
 
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
- gem 'chef', github: 'chef/chef'
20
- gem 'chef-dk', github: 'chef/chef-dk'
21
- gem 'halite', github: 'poise/halite'
22
- # gem 'poise-boiler', github: 'poise/poise-boiler'
23
- gem 'poise-profiler', github: 'poise/poise-profiler'
19
+ gem 'chef', git: 'https://github.com/chef/chef.git'
20
+ gem 'chef-dk', git: 'https://github.com/chef/chef-dk.git'
21
+ gem 'chefspec', git: 'https://github.com/sethvargo/chefspec.git'
22
+ gem 'fauxhai', git: 'https://github.com/customink/fauxhai.git'
23
+ gem 'foodcritic', git: 'https://github.com/foodcritic/foodcritic.git'
24
+ gem 'halite', git: 'https://github.com/poise/halite.git'
25
+ gem 'ohai', git: 'https://github.com/chef/ohai.git'
26
+ gem 'poise-boiler', git: 'https://github.com/poise/poise-boiler.git'
27
+ gem 'poise-profiler', git: 'https://github.com/poise/poise-profiler.git'
@@ -0,0 +1,6 @@
1
+ {
2
+ "id": "local",
3
+ "hoist_test": {
4
+ "four": 44
5
+ }
6
+ }
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright 2016, Noah Kantrowitz
2
+ # Copyright 2016-2017, Noah Kantrowitz
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
15
15
  #
16
16
 
17
17
  describe file('/hoist_test') do
18
- its(:content) { is_expected.to eq '{"one":11,"two":222,"three":3}' }
18
+ its(:content) { is_expected.to eq '{"one":11,"two":222,"three":3,"four":44}' }
19
19
  end
20
20
 
21
21
  describe file('/hoist_environment') do
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright 2016, Noah Kantrowitz
2
+ # Copyright 2016-2017, Noah Kantrowitz
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -22,3 +22,5 @@ default['local']['hoist_test']['one'] = 11
22
22
  override['hoist_test']['two'] = 22
23
23
  override['other']['hoist_test']['two'] = 220
24
24
  override['local']['hoist_test']['two'] = 222
25
+
26
+ default['poise-hoist']['data_bag'] = 'hoist'
@@ -0,0 +1,10 @@
1
+ {
2
+ "id": "encrypted-node",
3
+ "baseline": {
4
+ "encrypted_data": "V+YNyaskOPd0c0q5GJv9ogtfQahQQz5GJssGoFfjDObbGtgHDYvnNv46AsMn\nlXPVIYfGiZdBDp9aOJUsPY/WRce2\n",
5
+ "iv": "s1q5jNccDFIj8AI0\n",
6
+ "auth_tag": "IgKp1wRq9sCQXb8konivDA==\n",
7
+ "version": 3,
8
+ "cipher": "aes-256-gcm"
9
+ }
10
+ }
@@ -0,0 +1 @@
1
+ bdd5551cd57f85250989dabd53d922acc48aa4ab1675e5190cf493276cb1
@@ -0,0 +1,7 @@
1
+ {
2
+ "id": "mygroup",
3
+ "baseline": {
4
+ "one": 1111
5
+ },
6
+ "top": "flight"
7
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "id": "test-node",
3
+ "baseline": {
4
+ "one": 11111,
5
+ "two": 22222,
6
+ "deep": {
7
+ "four": [44444]
8
+ }
9
+ }
10
+ }
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright 2016, Noah Kantrowitz
2
+ # Copyright 2016-2017, Noah Kantrowitz
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -21,18 +21,19 @@ describe PoiseHoist do
21
21
  let(:role_default_attributes) { {} }
22
22
  let(:role_override_attributes) { {} }
23
23
  let(:node) { chef_run.node }
24
+ let(:policy_group) { 'mygroup' }
24
25
  subject do
25
- # Apply our attributes
26
- node.role_default.update(role_default_attributes)
27
- node.role_override.update(role_override_attributes)
28
26
  # Set a policy_group. Run this late so our node doesn't get created before
29
27
  # all before blocks get a chance to run.
30
28
  if defined?(node.policy_group)
31
- node.policy_group = 'mygroup'
29
+ node.policy_group = policy_group
32
30
  else
33
31
  # Global side effect. ¯\_(ツ)_/¯
34
- Chef::Config[:policy_group] = 'mygroup'
32
+ Chef::Config[:policy_group] = policy_group
35
33
  end
34
+ # Apply our attributes
35
+ node.role_default.update(role_default_attributes)
36
+ node.role_override.update(role_override_attributes)
36
37
  # Run the hoist.
37
38
  PoiseHoist.hoist!(node)
38
39
  # Use the attributes as the subject.
@@ -49,6 +50,19 @@ describe PoiseHoist do
49
50
  role_override_attributes['baseline'] ||= {}
50
51
  role_override_attributes['baseline']['one'] = 11
51
52
  role_override_attributes['top'] = 'hat'
53
+ # Patch data bag item loading to use the fixtures.
54
+ allow(Chef::DataBagItem).to receive(:load) do |bag, item|
55
+ if bag != 'hoist'
56
+ raise Chef::Exceptions::InvalidDataBagItemID.new("No bag found for #{bag}/#{item}")
57
+ end
58
+ path = File.expand_path("../fixtures/#{item}.json", __FILE__)
59
+ unless File.exist?(path)
60
+ raise Chef::Exceptions::InvalidDataBagItemID.new("No item found for #{bag}/#{item} at #{path}")
61
+ end
62
+ obj = Chef::DataBagItem.from_hash(JSON.parse(IO.read(path)))
63
+ obj.data_bag(bag)
64
+ obj
65
+ end
52
66
  end
53
67
 
54
68
  context 'with no policy attributes' do
@@ -127,6 +141,51 @@ describe PoiseHoist do
127
141
  its(%w{top}) { is_expected.to eq 'dog' }
128
142
  end # /context with a top-level override policy attribute
129
143
 
144
+ context 'with a data bag' do
145
+ before { override_attributes['poise-hoist'] = {'data_bag' => 'hoist'} }
146
+ its(%w{baseline one}) { is_expected.to eq 1111 }
147
+ its(%w{baseline two}) { is_expected.to eq 2 }
148
+ its(%w{baseline deep three}) { is_expected.to eq 3 }
149
+ its(%w{baseline deep four}) { is_expected.to eq [4] }
150
+ its(%w{top}) { is_expected.to eq 'flight' }
151
+ end # /context with a data bag
152
+
153
+ context 'with a data bag for the node name' do
154
+ before do
155
+ override_attributes['poise-hoist'] = {'data_bag' => 'hoist'}
156
+ node.name('test-node')
157
+ end
158
+ its(%w{baseline one}) { is_expected.to eq 11111 }
159
+ its(%w{baseline two}) { is_expected.to eq 22222 }
160
+ its(%w{baseline deep three}) { is_expected.to eq 3 }
161
+ its(%w{baseline deep four}) { is_expected.to eq [44444] }
162
+ its(%w{top}) { is_expected.to eq 'hat' }
163
+ end # /context with a data bag for the node name
164
+
165
+ context 'with a data bag that does not exist' do
166
+ before { override_attributes['poise-hoist'] = {'data_bag' => 'notfound'} }
167
+ it { expect { subject }.to raise_error Chef::Exceptions::InvalidDataBagItemID }
168
+ end # /context with a data bag that does not exist
169
+
170
+ context 'with a data bag that does not match the policy group' do
171
+ let(:policy_group) { 'othergroup' }
172
+ before { override_attributes['poise-hoist'] = {'data_bag' => 'hoist'} }
173
+ it { expect { subject }.to raise_error Chef::Exceptions::InvalidDataBagItemID }
174
+ end # /context with a data bag that does not match the policy group
175
+
176
+ context 'with an encrypted data bag' do
177
+ before do
178
+ Chef::Config[:encrypted_data_bag_secret] = File.expand_path('../fixtures/key', __FILE__)
179
+ override_attributes['poise-hoist'] = {'data_bag' => 'hoist'}
180
+ node.name('encrypted-node')
181
+ end
182
+ its(%w{baseline one}) { is_expected.to eq 11111 }
183
+ its(%w{baseline two}) { is_expected.to eq 22222 }
184
+ its(%w{baseline deep three}) { is_expected.to eq 3 }
185
+ its(%w{baseline deep four}) { is_expected.to eq [44444] }
186
+ its(%w{top}) { is_expected.to eq 'hat' }
187
+ end # /context with an encrypted data bag
188
+
130
189
  describe 'patch_chef_environment!' do
131
190
  context 'with patching enabled (default)' do
132
191
  it { subject; expect(chef_run.node.chef_environment).to eq 'mygroup' }