poise-hoist 1.0.0 → 1.1.0

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: 17c2ff1e81f2fe651f4c3a048482985b8f57431c
4
- data.tar.gz: df81c9f07b4009c074d02db0783140e286cbad44
3
+ metadata.gz: fa17c579cae5930699ac620980f878e0a8512889
4
+ data.tar.gz: a0f4dddbe610cfe9f9dca8993d73a16b21b3fa25
5
5
  SHA512:
6
- metadata.gz: 5bc25b30445c863e1b3205b537bc49985c0a4216943df3930b9721527c2ca5659964aef54b6a2430baa07129a5bc55da111f5a6216a5d7eba81ec47e26e5ac15
7
- data.tar.gz: f6d9e8490017afa7b2077e260e8a8bf46bba4509ad0394dcfd313a0cab9c51d17674d8f7017583289974ee7b0f477cf55570497f2461a025bca5297debcc79e1
6
+ metadata.gz: c066fd3561a0f3885316fabcdf4f3a246dfcfdcd2e769f794f30a8706e36f200c4ed5d0852b7e4e54f28308cb5fe7fb1f3dc80131fbc2f453d6300caac59717b
7
+ data.tar.gz: 088b1d2b6cc2b7c53c43e56fe79c666a3c9fc34d28991e1946f9a3f686b863d30850e833deeeb0158f3d0e3e93ef9b61f449e040ed13ee234f2f089b5d28ae96
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Poise-Hoist Changelog
2
2
 
3
+ ## v1.1.0
4
+
5
+ * Add `node.chef_environment` shim for older cookbooks.
6
+
3
7
  ## v1.0.0
4
8
 
5
9
  * Initial release!
data/README.md CHANGED
@@ -41,6 +41,12 @@ group will always be `local`.
41
41
  default['local']['myapp']['debug_mode'] = true
42
42
  ```
43
43
 
44
+ ## Environment Shim
45
+
46
+ For older cookbooks still expecting to use `node.chef_environment`, by default
47
+ that method will be patched to return the policy group label instead. This can
48
+ be disabled by setting `node['poise-hoist']['hoist_chef_environment'] = false`.
49
+
44
50
  ## Sponsors
45
51
 
46
52
  Development sponsored by [Bloomberg](http://www.bloomberg.com/company/technology/).
@@ -14,5 +14,8 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
+ # Enable node.chef_environment by default.
18
+ default['poise-hoist']['hoist_chef_environment'] = true
19
+
17
20
  # If we weren't able to run it during library load, do it now.
18
21
  PoiseHoist.hoist!(node) unless defined?(Chef.node)
data/lib/poise_hoist.rb CHANGED
@@ -23,15 +23,42 @@ require 'chef/mixin/deep_merge'
23
23
  module PoiseHoist
24
24
  autoload :VERSION, 'poise_hoist/version'
25
25
 
26
+ # Run the attribute hoist process.
27
+ #
28
+ # @param node [Chef::Node] Node object to modify.
29
+ # @return [void]
26
30
  def self.hoist!(node)
27
- # Do nothing if we aren't using policies.
28
31
  policy_group = (defined?(node.policy_group) && node.policy_group) || \
29
32
  Chef::Config[:policy_group] || \
30
33
  (Chef::Config[:deployment_group] && Chef::Config[:deployment_group].split(/-/).last)
34
+ # Don't continue if we aren't using policies.
31
35
  return unless policy_group
32
36
  Chef::Log.debug("Running attribute Hoist for group #{policy_group}")
33
37
  # Hoist away, mateys!
34
38
  Chef::Mixin::DeepMerge.hash_only_merge!(node.role_default, node.role_default[policy_group]) if node.role_default.include?(policy_group)
35
39
  Chef::Mixin::DeepMerge.hash_only_merge!(node.role_override, node.role_override[policy_group]) if node.role_override.include?(policy_group)
40
+ # Install the patch for chef_environment.
41
+ patch_chef_environment!(node, policy_group)
36
42
  end
43
+
44
+ # Patch `node.chef_environment` to return the policy group name if enabled
45
+ # via `node['poise-hoist']['hoist_chef_environment']`.
46
+ #
47
+ # @api private
48
+ # @since 1.1.0
49
+ # @param node [Chef::Node] Node object to modify.
50
+ # @param policy_group [String] Policy group name.
51
+ # @return [void]
52
+ def self.patch_chef_environment!(node, policy_group)
53
+ old_accessor = node.method(:chef_environment)
54
+ # Not using Poise::NOT_PASSED because this doesn't depend on Poise.
55
+ node.define_singleton_method(:chef_environment) do |*args|
56
+ if args.empty? && node['poise-hoist']['hoist_chef_environment']
57
+ policy_group
58
+ else
59
+ old_accessor.call(*args)
60
+ end
61
+ end
62
+ end
63
+
37
64
  end
@@ -17,5 +17,5 @@
17
17
 
18
18
  module PoiseHoist
19
19
  # Version for the poise-hoist gem.
20
- VERSION = '1.0.0'
20
+ VERSION = '1.1.0'
21
21
  end
@@ -17,3 +17,7 @@
17
17
  file '/hoist_test' do
18
18
  content node['hoist_test'].to_hash.to_json
19
19
  end
20
+
21
+ file '/hoist_environment' do
22
+ content node.chef_environment
23
+ end
@@ -17,3 +17,7 @@
17
17
  describe file('/hoist_test') do
18
18
  its(:content) { is_expected.to eq '{"one":11,"two":222,"three":3}' }
19
19
  end
20
+
21
+ describe file('/hoist_environment') do
22
+ its(:content) { is_expected.to eq 'local' }
23
+ end
@@ -126,4 +126,15 @@ describe PoiseHoist do
126
126
  its(%w{baseline deep four}) { is_expected.to eq [4] }
127
127
  its(%w{top}) { is_expected.to eq 'dog' }
128
128
  end # /context with a top-level override policy attribute
129
+
130
+ describe 'patch_chef_environment!' do
131
+ context 'with patching enabled (default)' do
132
+ it { subject; expect(chef_run.node.chef_environment).to eq 'mygroup' }
133
+ end # /context with patching enabled (default)
134
+
135
+ context 'with patching disabled' do
136
+ before { override_attributes['poise-hoist'] = {'hoist_chef_environment' => false} }
137
+ it { subject; expect(chef_run.node.chef_environment).to eq '_default' }
138
+ end # /context with patching disabled
139
+ end # /describe patch_chef_environment!
129
140
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poise-hoist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Kantrowitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-22 00:00:00.000000000 Z
11
+ date: 2016-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: halite