chef-sugar 1.0.1 → 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: 75de0550f84f3b8ef3b94926f60c2b3a7a757c02
4
- data.tar.gz: 081a7e696179a33958fe4a38cf7022da9c8c0d0b
3
+ metadata.gz: 222ec2b0f50c5d0a482190cc2b4baec1423f124d
4
+ data.tar.gz: 09af24376426ba383f8b85c4e08c8ab6ad4ceef9
5
5
  SHA512:
6
- metadata.gz: f506eb432d8a39cfdea1b709fe760c9994887655503cb2e539bc1ffe5e299d49513a4a0f3928b1ac02e8c42e453726979df4f76d4c2f3c2f69a9d5b663fc337d
7
- data.tar.gz: d6e52403bf24e0a37b61432373b455806d563004773a757fc2d61eff4103e4dbe89796ede0c3d67eea01ab332cdf63d64f25f9c429ea367f6367ec9bb8294983
6
+ metadata.gz: 3341414fb14b31ca32baf45395e084f1d095cb830569669b7048429c66d92bbfa6a10103da4273cd554496289c27958fa09f03db2c3da1e7a1cb37892f2f94d7
7
+ data.tar.gz: 0eb0b352c56911e7c55d26f85259baf418e32c8731401ba37b6ce134b5561549ccdd2e3824a80b14018ad37b17a12bd6f322b4d89f232590cc01a9923625b1d8
data/.gitignore CHANGED
@@ -20,3 +20,4 @@ bin/
20
20
  pkg/
21
21
  tmp/
22
22
  vendor/
23
+ .rspec
@@ -3,4 +3,3 @@ rvm:
3
3
  - 2.0.0
4
4
  script:
5
5
  - bundle exec rspec --color --format progress
6
- - bundle exec foodcritic . -f any
@@ -3,6 +3,14 @@ Chef Sugar Changelog
3
3
  This file is used to list changes made in each version of the chef-sugar cookbook and gem.
4
4
 
5
5
 
6
+ v1.1.0 (2013-12-10)
7
+ -------------------
8
+ - Add `cloudstack?` helper
9
+ - Add data bag helpers
10
+ - Remove foodcritic checks
11
+ - Upgrade development gem versions
12
+ - Randomize spec order
13
+
6
14
  v1.0.1 (2013-10-15)
7
15
  -------------------
8
16
  - Add development recipe
data/README.md CHANGED
@@ -93,6 +93,7 @@ end
93
93
  - `gce?`
94
94
  - `linode?`
95
95
  - `openstack?`
96
+ - `cloudstack?`
96
97
  - `rackspace?`
97
98
 
98
99
  #### Examples
@@ -105,6 +106,19 @@ template '/tmp/config' do
105
106
  end
106
107
  ```
107
108
 
109
+ ### Data Bag
110
+ - `encrypted_data_bag_item` - a handy DSL method for loading encrypted data bag items the same way you load a regular data bag item; this requires `Chef::Config[:encrypted_data_bag_secret]` is set!
111
+ - `encrypted_data_bag_item_for_environment` - find the data bag entry for the current node's Chef environment.
112
+
113
+ #### Examples
114
+ ```ruby
115
+ encrypted_data_bag_item('accounts', 'hipchat')
116
+ ```
117
+
118
+ ```ruby
119
+ encrypted_data_bag_item_for_environment('accounts', 'github')
120
+ ```
121
+
108
122
  ### IP
109
123
  - `best_ip_for` - determine the best IP address for the given "other" node, preferring local IP addresses over public ones.
110
124
 
@@ -251,7 +265,7 @@ end
251
265
 
252
266
  # This is equivalent to
253
267
  package 'apache2' do
254
- 'apache2'
268
+ action :nothing
255
269
  end.run_action(:install)
256
270
  ```
257
271
 
@@ -30,8 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency 'chef', '~> 11.0'
31
31
  spec.add_development_dependency 'rspec', '~> 2.11'
32
32
 
33
- spec.add_development_dependency 'chefspec', '~> 3.0.0.beta'
34
- spec.add_development_dependency 'foodcritic', '~> 3.0'
35
- spec.add_development_dependency 'test-kitchen', '~> 1.0.0.beta'
36
- spec.add_development_dependency 'kitchen-vagrant', '~> 0.11'
33
+ spec.add_development_dependency 'chefspec', '~> 3.0'
34
+ spec.add_development_dependency 'test-kitchen', '~> 1.0'
35
+ spec.add_development_dependency 'kitchen-vagrant', '~> 0.14'
37
36
  end
@@ -22,6 +22,7 @@ class Chef
22
22
  module Sugar
23
23
  require_relative 'sugar/architecture'
24
24
  require_relative 'sugar/cloud'
25
+ require_relative 'sugar/data_bag'
25
26
  require_relative 'sugar/filters'
26
27
  require_relative 'sugar/ip'
27
28
  require_relative 'sugar/node'
@@ -104,6 +104,18 @@ class Chef
104
104
  node.key?('openstack')
105
105
  end
106
106
 
107
+ #
108
+ # Return true if the current current node is in Cloudstack
109
+ #
110
+ # @param [Chef::Node] node
111
+ # the node to check
112
+ #
113
+ # @return [Boolean]
114
+ #
115
+ def cloudstack?(node)
116
+ node.key?('cloudstack')
117
+ end
118
+
107
119
  #
108
120
  # Return true if the current current node is in Azure
109
121
  #
@@ -140,6 +152,9 @@ class Chef
140
152
  # @see Chef::Sugar::Cloud#openstack?
141
153
  def openstack?; Chef::Sugar::Cloud.openstack?(node); end
142
154
 
155
+ # @see Chef::Sugar::Cloud#cloudstack?
156
+ def cloudstack?; Chef::Sugar::Cloud.cloudstack?(node); end
157
+
143
158
  # @see Chef::Sugar::Cloud#azure?
144
159
  def azure?; Chef::Sugar::Cloud.azure?(node); end
145
160
  end
@@ -0,0 +1,84 @@
1
+ #
2
+ # Copyright 2013, Seth Vargo <sethvargo@gmail.com>
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
+ class Chef
18
+ module Sugar
19
+ module DataBag
20
+ extend self
21
+
22
+ #
23
+ # Helper method for loading an encrypted data bag item in a similar
24
+ # syntax/recipe DSL method.
25
+ #
26
+ # @param [String] bag
27
+ # the name of the encrypted data bag
28
+ # @param [String] id
29
+ # the id of the encrypted data bag
30
+ #
31
+ # @return [Hash]
32
+ #
33
+ def encrypted_data_bag_item(bag, id)
34
+ Chef::Log.debug "Loading encrypted data bag item #{bag}/#{id}"
35
+ Chef::EncryptedDataBagItem.load(bag, id)
36
+ end
37
+
38
+ #
39
+ # This algorithm attempts to find the data bag entry for the current
40
+ # node's Chef environment. If there are no environment-specific
41
+ # values, the "default" bucket is used. The data bag must follow the
42
+ # schema:
43
+ #
44
+ # {
45
+ # "default": {...},
46
+ # "environment_name": {...},
47
+ # "other_environment": {...},
48
+ # }
49
+ #
50
+ # @param [Node] node
51
+ # the current Chef node
52
+ # @param [String] bag
53
+ # the name of the encrypted data bag
54
+ # @param [String] id
55
+ # the id of the encrypted data bag
56
+ #
57
+ # @return [Hash]
58
+ #
59
+ def encrypted_data_bag_item_for_environment(node, bag, id)
60
+ data = encrypted_data_bag_item(bag, id)
61
+
62
+ if data[node.chef_environment]
63
+ Chef::Log.debug "Using #{node.chef_environment} as the key"
64
+ data[node.chef_environment]
65
+ else
66
+ Chef::Log.debug "#{node.chef_environment} key does not exist, using `default`"
67
+ data['default']
68
+ end
69
+ end
70
+ end
71
+
72
+ module DSL
73
+ # @see Chef::Sugar::DataBag#encrypted_data_bag_item?
74
+ def encrypted_data_bag_item(bag, id)
75
+ Chef::Sugar::DataBag.encrypted_data_bag_item(bag, id)
76
+ end
77
+
78
+ # @see Chef::Sugar::DataBag#encrypted_data_bag_item_for_environment?
79
+ def encrypted_data_bag_item_for_environment(bag, id)
80
+ Chef::Sugar::DataBag.encrypted_data_bag_item_for_environment(node, bag, id)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -16,6 +16,6 @@
16
16
 
17
17
  class Chef
18
18
  module Sugar
19
- VERSION = '1.0.1'
19
+ VERSION = '1.1.0'
20
20
  end
21
21
  end
@@ -3,3 +3,19 @@ require 'chefspec'
3
3
  require 'chef/sugar'
4
4
 
5
5
  require_relative 'support/shared_examples'
6
+
7
+ RSpec.configure do |config|
8
+ # Prohibit using the should syntax
9
+ config.expect_with :rspec do |spec|
10
+ spec.syntax = :expect
11
+ end
12
+
13
+ # Run specs in random order to surface order dependencies. If you find an
14
+ # order dependency and want to debug it, you can fix the order by providing
15
+ # the seed, which is printed after each run.
16
+ # --seed 1234
17
+ config.order = 'random'
18
+
19
+ # ChefSpec configuration
20
+ config.log_level = :fatal
21
+ end
@@ -99,6 +99,18 @@ describe Chef::Sugar::Cloud do
99
99
  end
100
100
  end
101
101
 
102
+ describe '#cloudstack?' do
103
+ it 'is true when the node is on cloudstack' do
104
+ node = { 'cloudstack' => nil }
105
+ expect(described_class.cloudstack?(node)).to be_true
106
+ end
107
+
108
+ it 'is false when the node is not on cloudstack' do
109
+ node = {}
110
+ expect(described_class.cloudstack?(node)).to be_false
111
+ end
112
+ end
113
+
102
114
  describe '#azure?' do
103
115
  it 'is true when the node is on azure' do
104
116
  node = { 'azure' => nil }
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Sugar::DataBag do
4
+ describe '#encrypted_data_bag_item' do
5
+ before { Chef::EncryptedDataBagItem.stub(:load) }
6
+
7
+ it 'loads the encrypted data bag item' do
8
+ expect(Chef::EncryptedDataBagItem).to receive(:load)
9
+ .with('accounts', 'github')
10
+
11
+ described_class.encrypted_data_bag_item('accounts', 'github')
12
+ end
13
+ end
14
+
15
+ describe '#encrypted_data_bag_item_for_environment' do
16
+ let(:node) { double(:node, chef_environment: 'production') }
17
+
18
+ context 'when the environment exists' do
19
+ it 'loads the data from the environment' do
20
+ Chef::EncryptedDataBagItem.stub(:load).and_return(
21
+ 'production' => {
22
+ 'username' => 'sethvargo',
23
+ 'password' => 'bacon',
24
+ }
25
+ )
26
+
27
+ expect(described_class.encrypted_data_bag_item_for_environment(node, 'accounts', 'github')).to eq(
28
+ 'password' => 'bacon',
29
+ 'username' => 'sethvargo',
30
+ )
31
+ end
32
+ end
33
+
34
+ context 'when the environment does not exist' do
35
+ it 'loads the data from the default bucket' do
36
+ Chef::EncryptedDataBagItem.stub(:load).and_return(
37
+ 'staging' => {
38
+ 'username' => 'sethvargo',
39
+ 'password' => 'bacon',
40
+ },
41
+ 'default' => {
42
+ 'username' => 'schisamo',
43
+ 'password' => 'ham',
44
+ }
45
+ )
46
+
47
+ expect(described_class.encrypted_data_bag_item_for_environment(node, 'accounts', 'github')).to eq(
48
+ 'password' => 'ham',
49
+ 'username' => 'schisamo',
50
+ )
51
+ end
52
+ end
53
+ end
54
+ end
@@ -4,6 +4,6 @@ describe 'chef-sugar::default' do
4
4
  let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
5
5
 
6
6
  it 'installs the chef gem' do
7
- expect(chef_run).to install_chef_gem('chef-sugar').with(version: '1.0.0')
7
+ expect(chef_run).to install_chef_gem('chef-sugar')
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-sugar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Vargo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-15 00:00:00.000000000 Z
11
+ date: 2013-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -68,20 +68,6 @@ dependencies:
68
68
  version: '2.11'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: chefspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ~>
74
- - !ruby/object:Gem::Version
75
- version: 3.0.0.beta
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ~>
81
- - !ruby/object:Gem::Version
82
- version: 3.0.0.beta
83
- - !ruby/object:Gem::Dependency
84
- name: foodcritic
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
73
  - - ~>
@@ -100,28 +86,28 @@ dependencies:
100
86
  requirements:
101
87
  - - ~>
102
88
  - !ruby/object:Gem::Version
103
- version: 1.0.0.beta
89
+ version: '1.0'
104
90
  type: :development
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
94
  - - ~>
109
95
  - !ruby/object:Gem::Version
110
- version: 1.0.0.beta
96
+ version: '1.0'
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: kitchen-vagrant
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
101
  - - ~>
116
102
  - !ruby/object:Gem::Version
117
- version: '0.11'
103
+ version: '0.14'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
108
  - - ~>
123
109
  - !ruby/object:Gem::Version
124
- version: '0.11'
110
+ version: '0.14'
125
111
  description: A series of helpful sugar of the Chef core and other resources to make
126
112
  a cleaner, more lean recipe DSL, enforce DRY principles, and make writing Chef recipes
127
113
  an awesome experience!
@@ -144,6 +130,7 @@ files:
144
130
  - lib/chef/sugar.rb
145
131
  - lib/chef/sugar/architecture.rb
146
132
  - lib/chef/sugar/cloud.rb
133
+ - lib/chef/sugar/data_bag.rb
147
134
  - lib/chef/sugar/filters.rb
148
135
  - lib/chef/sugar/ip.rb
149
136
  - lib/chef/sugar/node.rb
@@ -160,6 +147,7 @@ files:
160
147
  - spec/support/shared_examples.rb
161
148
  - spec/unit/chef/extensions/architecture_spec.rb
162
149
  - spec/unit/chef/extensions/cloud_spec.rb
150
+ - spec/unit/chef/extensions/data_bag_spec.rb
163
151
  - spec/unit/chef/extensions/ip_spec.rb
164
152
  - spec/unit/chef/extensions/node_spec.rb
165
153
  - spec/unit/chef/extensions/platform_family_spec.rb
@@ -188,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
176
  version: '0'
189
177
  requirements: []
190
178
  rubyforge_project:
191
- rubygems_version: 2.0.3
179
+ rubygems_version: 2.0.14
192
180
  signing_key:
193
181
  specification_version: 4
194
182
  summary: A collection of helper methods and modules that make working with Chef recipes
@@ -198,6 +186,7 @@ test_files:
198
186
  - spec/support/shared_examples.rb
199
187
  - spec/unit/chef/extensions/architecture_spec.rb
200
188
  - spec/unit/chef/extensions/cloud_spec.rb
189
+ - spec/unit/chef/extensions/data_bag_spec.rb
201
190
  - spec/unit/chef/extensions/ip_spec.rb
202
191
  - spec/unit/chef/extensions/node_spec.rb
203
192
  - spec/unit/chef/extensions/platform_family_spec.rb
@@ -206,4 +195,3 @@ test_files:
206
195
  - spec/unit/chef/extensions/shell_spec.rb
207
196
  - spec/unit/chef/extensions/vagrant_spec.rb
208
197
  - spec/unit/recipes/default_spec.rb
209
- has_rdoc: