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
data/README.md CHANGED
@@ -24,10 +24,25 @@ name 'myapp'
24
24
 
25
25
  run_list 'poise-hoist', 'myapp'
26
26
 
27
- default['staging']['myapp']['debug_mode'] = true
27
+ # Default value for all groups.
28
+ default['myapp']['debug_mode'] = true
29
+
30
+ # Per-group values, will be hoisted on top of the default above.
31
+ default['staging']['myapp']['debug_mode'] = 'extra_verbose'
28
32
  default['prod']['myapp']['debug_mode'] = false
29
33
  ```
30
34
 
35
+ and then in your recipe code:
36
+
37
+ ```ruby
38
+ some_resource 'name' do
39
+ debug_mode node['myapp']['debug_mode']
40
+ end
41
+ ```
42
+
43
+ This automatically hoists up policy attributes set under a top-level key
44
+ matching the name of the policy group of the current node.
45
+
31
46
  ## Requirements
32
47
 
33
48
  Chef 12.2 or newer is required.
@@ -47,6 +62,15 @@ For older cookbooks still expecting to use `node.chef_environment`, by default
47
62
  that method will be patched to return the policy group label instead. This can
48
63
  be disabled by setting `node['poise-hoist']['hoist_chef_environment'] = false`.
49
64
 
65
+ ## Data Bag Attributes
66
+
67
+ To pull in data from a data bag, set `node['poise-hoist']['data_bag']`, in your
68
+ Policyfile or in a wrapper cookbook. It will look for an item in the specified
69
+ data bag using the name of the node and then the name of policy group.
70
+
71
+ This can be useful in combination with attributes from the Policyfile to provide
72
+ immediate overrides outside of the "compile and push" cycle of the policy system.
73
+
50
74
  ## Sponsors
51
75
 
52
76
  Development sponsored by [Bloomberg](http://www.bloomberg.com/company/technology/).
@@ -55,7 +79,7 @@ The Poise test server infrastructure is generously sponsored by [Rackspace](http
55
79
 
56
80
  ## License
57
81
 
58
- Copyright 2016, Noah Kantrowitz
82
+ Copyright 2016-2017, Noah Kantrowitz
59
83
 
60
84
  Licensed under the Apache License, Version 2.0 (the "License");
61
85
  you may not use this file except in compliance with the License.
data/Rakefile CHANGED
@@ -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.
@@ -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.
@@ -14,6 +14,9 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
+ # Name for attribute data bag. Defaults to nil, meaning the feature is disabled.
18
+ default['poise-hoist']['data_bag'] = nil
19
+
17
20
  # Enable node.chef_environment by default.
18
21
  default['poise-hoist']['hoist_chef_environment'] = true
19
22
 
@@ -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.
data/lib/poise_hoist.rb CHANGED
@@ -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.
@@ -14,6 +14,7 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
+ require 'chef/encrypted_data_bag_item/check_encrypted'
17
18
  require 'chef/mixin/deep_merge'
18
19
 
19
20
 
@@ -21,6 +22,8 @@ require 'chef/mixin/deep_merge'
21
22
  #
22
23
  # @since 1.0.0
23
24
  module PoiseHoist
25
+ extend Chef::EncryptedDataBagItem::CheckEncrypted
26
+
24
27
  autoload :VERSION, 'poise_hoist/version'
25
28
 
26
29
  # Run the attribute hoist process.
@@ -37,10 +40,58 @@ module PoiseHoist
37
40
  # Hoist away, mateys!
38
41
  Chef::Mixin::DeepMerge.hash_only_merge!(node.role_default, node.role_default[policy_group]) if node.role_default.include?(policy_group)
39
42
  Chef::Mixin::DeepMerge.hash_only_merge!(node.role_override, node.role_override[policy_group]) if node.role_override.include?(policy_group)
43
+ # Grab from a data bag if one is configured.
44
+ hoist_from_data_bag!(node, policy_group, node['poise-hoist']['data_bag']) if node['poise-hoist']['data_bag']
40
45
  # Install the patch for chef_environment.
41
46
  patch_chef_environment!(node, policy_group)
42
47
  end
43
48
 
49
+ # Pull attribute data in from a data bag. Checks for an item matching the
50
+ # node node, and then the policy group.
51
+ #
52
+ # @api private
53
+ # @param node [Chef::Node] Node object to modify.
54
+ # @param policy_group [String] Policy group name.
55
+ # @param data_bag [String] Data bag name to load from.
56
+ # @return [void]
57
+ def self.hoist_from_data_bag!(node, policy_group, data_bag)
58
+ item = begin
59
+ data_bag_item(data_bag, node.name)
60
+ rescue Exception
61
+ data_bag_item(data_bag, policy_group)
62
+ end
63
+ Chef::Mixin::DeepMerge.hash_only_merge!(node.role_override, item)
64
+ end
65
+
66
+ # A copy of Chef's data_bag_item method, modified to remove some spurious
67
+ # error logging and returns a plain hash without the `id` field instead of
68
+ # one of the data bag item objects.
69
+ #
70
+ # @api private
71
+ # @param bag [String] Data bag name.
72
+ # @param item [String] Data bag item name.
73
+ # @param secret [String, nil] Data bag secret.
74
+ # @return [Hash]
75
+ def self.data_bag_item(bag, item, secret = nil)
76
+ Chef::DataBag.validate_name!(bag.to_s)
77
+ Chef::DataBagItem.validate_id!(item)
78
+
79
+ item = Chef::DataBagItem.load(bag, item)
80
+ data = if encrypted?(item.raw_data)
81
+ Chef::Log.debug("Data bag item looks encrypted: #{bag.inspect} #{item.inspect}")
82
+
83
+ # Try to load the data bag item secret, if secret is not provided.
84
+ # Chef::EncryptedDataBagItem.load_secret may throw a variety of errors.
85
+ secret ||= Chef::EncryptedDataBagItem.load_secret
86
+ Chef::EncryptedDataBagItem.new(item.raw_data, secret).to_hash
87
+ else
88
+ item.raw_data
89
+ end
90
+ data.delete('id')
91
+
92
+ data
93
+ end
94
+
44
95
  # Patch `node.chef_environment` to return the policy group name if enabled
45
96
  # via `node['poise-hoist']['hoist_chef_environment']`.
46
97
  #
@@ -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.
@@ -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,5 +17,5 @@
17
17
 
18
18
  module PoiseHoist
19
19
  # Version for the poise-hoist gem.
20
- VERSION = '1.1.0'
20
+ VERSION = '1.2.0'
21
21
  end
data/poise-hoist.gemspec CHANGED
@@ -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.
@@ -26,16 +26,18 @@ Gem::Specification.new do |spec|
26
26
  spec.description = 'Automatically hoist environment level-attributes from Policyfiles.'
27
27
  spec.summary = spec.description
28
28
  spec.homepage = 'https://github.com/poise/poise-hoist'
29
- spec.license = 'Apache 2.0'
29
+ spec.license = 'Apache-2.0'
30
+ spec.metadata['platforms'] = 'any'
30
31
 
31
32
  spec.files = `git ls-files`.split($/)
32
33
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
33
34
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
34
35
  spec.require_paths = %w{lib}
35
36
 
37
+ spec.add_dependency 'chef', '>= 12.2', '< 14'
36
38
  spec.add_dependency 'halite', '~> 1.0'
37
39
 
38
- spec.add_development_dependency 'chef-dk', '~> 0.1'
40
+ spec.add_development_dependency 'chef-dk', '>= 0.10', '< 3'
39
41
  spec.add_development_dependency 'kitchen-inspec', '~> 0.12'
40
42
  spec.add_development_dependency 'poise-boiler', '~> 1.8'
41
43
  end
@@ -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,3 +17,4 @@
17
17
  default['hoist_test']['one'] = 1
18
18
  default['hoist_test']['two'] = 2
19
19
  default['hoist_test']['three'] = 3
20
+ default['hoist_test']['four'] = 4
@@ -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.
@@ -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.
@@ -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.10.24'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
22
+ gem 'chef-dk', '~> 0.14.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.11.18'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
22
+ gem 'chef-dk', '~> 0.15.0'
23
+ gem 'mixlib-install', '>= 2'
24
+ gem 'fauxhai', '<= 3.9.0'
25
+ gem 'cheffish', '< 13'
26
+ gem 'chefspec', '< 6'
@@ -0,0 +1,25 @@
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.12.15'
20
+ gem 'foodcritic', '< 8'
21
+ gem 'chef-dk', '~> 0.16.0'
22
+ gem 'mixlib-install', '>= 2'
23
+ gem 'fauxhai', '<= 3.9.0'
24
+ gem 'cheffish', '< 13'
25
+ gem 'chefspec', '< 6'
@@ -0,0 +1,25 @@
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.13.37'
20
+ gem 'foodcritic', '< 8'
21
+ gem 'chef-dk', '~> 0.17.0'
22
+ gem 'mixlib-install', '>= 2'
23
+ gem 'fauxhai', '<= 3.9.0'
24
+ gem 'cheffish', '< 13'
25
+ gem 'chefspec', '< 6'
@@ -0,0 +1,21 @@
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.14.89'
20
+ gem 'chef-dk', '~> 0.18.0'
21
+ gem 'cheffish', '< 13'
@@ -0,0 +1,21 @@
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.15.19'
20
+ gem 'chef-dk', '~> 0.19.0'
21
+ gem 'cheffish', '< 13'
@@ -0,0 +1,21 @@
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.16.42'
20
+ gem 'chef-dk', '~> 1.0.0'
21
+ gem 'cheffish', '< 13'
@@ -0,0 +1,21 @@
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.17.44'
20
+ gem 'chef-dk', '~> 1.1.0'
21
+ gem 'cheffish', '< 13'