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 +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +0 -1
- data/CHANGELOG.md +8 -0
- data/README.md +15 -1
- data/chef-extensions.gemspec +3 -4
- data/lib/chef/sugar.rb +1 -0
- data/lib/chef/sugar/cloud.rb +15 -0
- data/lib/chef/sugar/data_bag.rb +84 -0
- data/lib/chef/sugar/version.rb +1 -1
- data/spec/spec_helper.rb +16 -0
- data/spec/unit/chef/extensions/cloud_spec.rb +12 -0
- data/spec/unit/chef/extensions/data_bag_spec.rb +54 -0
- data/spec/unit/recipes/default_spec.rb +1 -1
- metadata +10 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 222ec2b0f50c5d0a482190cc2b4baec1423f124d
|
4
|
+
data.tar.gz: 09af24376426ba383f8b85c4e08c8ab6ad4ceef9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3341414fb14b31ca32baf45395e084f1d095cb830569669b7048429c66d92bbfa6a10103da4273cd554496289c27958fa09f03db2c3da1e7a1cb37892f2f94d7
|
7
|
+
data.tar.gz: 0eb0b352c56911e7c55d26f85259baf418e32c8731401ba37b6ce134b5561549ccdd2e3824a80b14018ad37b17a12bd6f322b4d89f232590cc01a9923625b1d8
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -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
|
-
|
268
|
+
action :nothing
|
255
269
|
end.run_action(:install)
|
256
270
|
```
|
257
271
|
|
data/chef-extensions.gemspec
CHANGED
@@ -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
|
34
|
-
spec.add_development_dependency '
|
35
|
-
spec.add_development_dependency '
|
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
|
data/lib/chef/sugar.rb
CHANGED
data/lib/chef/sugar/cloud.rb
CHANGED
@@ -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
|
data/lib/chef/sugar/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -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')
|
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
|
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
|
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
|
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
|
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.
|
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.
|
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.
|
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:
|