berkshelf 4.1.1 → 4.2.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: fb91a34f310e2a87c08b695287aef0b37d2f8571
4
- data.tar.gz: dc98b00aa2af23be7e9083870834a8fb0b73d2d1
3
+ metadata.gz: 9edf31296dfa910235ff1d4f00fc9a56e9bed2db
4
+ data.tar.gz: aa922a7527312fb21d32f0d80bb600837f4178c0
5
5
  SHA512:
6
- metadata.gz: 3c5abb9d31d18ff11d18f994b1bfee07e596a2be29da3f5ae0608f41898bf62c350899cd1fea50a57099fbae1dd4bd1a2581eb5764e57dffc7fc6be9b65c0fd0
7
- data.tar.gz: ddd2e9b0dfd7a6a602c3f69c73a7a78ef8a492db9f0d2ed5eea65eb7f5e5b7ac41d5e8d22b095867cd9681e30e3a85ca294c1169bc43edc790ef188c88507172
6
+ metadata.gz: 0bcb121c3d06aa8869b6956ff6e0eac85e2c2910cca013a0542d7c39bb17062171bd2de49eecf8622d7b696b63ef0aed3fe2a16f49482ea1613a7e27da52b955
7
+ data.tar.gz: 7a158f6ba5045ef1ea2d4810bfba7bb0a0eaae3475a573f75184bd9293fb9ea2b99552ae1011de52a9c1d871b04f8bb825b57d3aaf7fc829a8c8a7cc1059c2ab
@@ -1,7 +1,19 @@
1
1
  # Change Log
2
2
 
3
- ## [4.1.1](https://github.com/berkshelf/berkshelf/tree/4.1.1) (2016-02-11)
4
- [Full Changelog](https://github.com/berkshelf/berkshelf/compare/v4.1.0...4.1.1)
3
+ ## [4.2.0](https://github.com/berkshelf/berkshelf/tree/4.2.0) (2016-02-18)
4
+ [Full Changelog](https://github.com/berkshelf/berkshelf/compare/v4.1.1...4.2.0)
5
+
6
+ **Closed issues:**
7
+
8
+ - Allow one to "berks apply" to a json environment file [\#875](https://github.com/berkshelf/berkshelf/issues/875)
9
+
10
+ **Merged pull requests:**
11
+
12
+ - Update the chef-config pin to 12.7.2 [\#1516](https://github.com/berkshelf/berkshelf/pull/1516) ([jaym](https://github.com/jaym))
13
+ - Apply locks to local json environment file [\#1512](https://github.com/berkshelf/berkshelf/pull/1512) ([louis-gounot](https://github.com/louis-gounot))
14
+
15
+ ## [v4.1.1](https://github.com/berkshelf/berkshelf/tree/v4.1.1) (2016-02-11)
16
+ [Full Changelog](https://github.com/berkshelf/berkshelf/compare/v4.1.0...v4.1.1)
5
17
 
6
18
  **Merged pull requests:**
7
19
 
@@ -2313,4 +2325,4 @@
2313
2325
 
2314
2326
 
2315
2327
 
2316
- \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
2328
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
@@ -19,7 +19,7 @@ GIT
19
19
  PATH
20
20
  remote: .
21
21
  specs:
22
- berkshelf (4.1.1)
22
+ berkshelf (4.2.0)
23
23
  addressable (~> 2.3.4)
24
24
  berkshelf-api-client (~> 2.0)
25
25
  buff-config (~> 1.0)
@@ -77,7 +77,7 @@ GEM
77
77
  celluloid-io (0.16.2)
78
78
  celluloid (>= 0.16.0)
79
79
  nio4r (>= 1.1.0)
80
- chef-config (12.6.0)
80
+ chef-config (12.7.2)
81
81
  mixlib-config (~> 2.0)
82
82
  mixlib-shellout (~> 2.0)
83
83
  chef-zero (4.5.0)
@@ -208,6 +208,10 @@ module Berkshelf
208
208
  berksfile.upload(names, options.symbolize_keys)
209
209
  end
210
210
 
211
+ method_option :envfile,
212
+ type: :string,
213
+ desc: 'Path to a JSON environment file to update.',
214
+ aliases: '-f'
211
215
  method_option :lockfile,
212
216
  type: :string,
213
217
  default: Berkshelf::Lockfile::DEFAULT_FILENAME,
@@ -537,6 +537,18 @@ module Berkshelf
537
537
  end
538
538
  end
539
539
 
540
+ # Raised when envFile provided to apply -f is not found
541
+ class EnvironmentFileNotFound < EnvironmentNotFound
542
+ set_status_code(150)
543
+
544
+ def intialize(environment_file)
545
+ @environment_file = environment_file
546
+ end
547
+
548
+ def to_s
549
+ "Could not find environment file #{@environment_file}"
550
+ end
551
+ end
540
552
 
541
553
  # Git errors
542
554
  # ------------------------------
@@ -194,6 +194,8 @@ module Berkshelf
194
194
  #
195
195
  # @option options [Hash] :ssl_verify (true)
196
196
  # Disable/Enable SSL verification during uploads
197
+ # @option options [String] :envfile
198
+ # Environment file to update
197
199
  #
198
200
  # @raise [EnvironmentNotFound]
199
201
  # if the target environment was not found on the remote Chef Server
@@ -201,18 +203,22 @@ module Berkshelf
201
203
  # if you are locking cookbooks with an invalid or not-specified client
202
204
  # configuration
203
205
  def apply(name, options = {})
204
- Berkshelf.ridley_connection(options) do |connection|
205
- environment = connection.environment.find(name)
206
+ locks = graph.locks.inject({}) do |hash, (name, dependency)|
207
+ hash[name] = "= #{dependency.locked_version.to_s}"
208
+ hash
209
+ end
210
+
211
+ if options[:envfile]
212
+ update_environment_file(options[:envfile], locks) if options[:envfile]
213
+ else
214
+ Berkshelf.ridley_connection(options) do |connection|
215
+ environment = connection.environment.find(name)
206
216
 
207
- raise EnvironmentNotFound.new(name) if environment.nil?
217
+ raise EnvironmentNotFound.new(name) if environment.nil?
208
218
 
209
- locks = graph.locks.inject({}) do |hash, (name, dependency)|
210
- hash[name] = "= #{dependency.locked_version.to_s}"
211
- hash
219
+ environment.cookbook_versions = locks
220
+ environment.save unless options[:envfile]
212
221
  end
213
-
214
- environment.cookbook_versions = locks
215
- environment.save
216
222
  end
217
223
  end
218
224
 
@@ -297,6 +303,32 @@ module Berkshelf
297
303
  locked.cached_cookbook
298
304
  end
299
305
 
306
+ # Update local environment file
307
+ #
308
+ # @param [String] environment_file
309
+ # path to the envfile to update
310
+ #
311
+ # @param [Hash] locks
312
+ # A hash of cookbooks and versions to update the environment with
313
+ #
314
+ # @raise [EnvironmentFileNotFound]
315
+ # If environment file doesn't exist
316
+ def update_environment_file(environment_file, locks)
317
+ unless File.exists?(environment_file)
318
+ raise EnvironmentFileNotFound.new(environment_file)
319
+ end
320
+
321
+ json_environment = JSON.parse(File.read(environment_file))
322
+
323
+ json_environment['cookbook_versions'] = locks
324
+
325
+ json = JSON.pretty_generate(json_environment)
326
+
327
+ File.open(environment_file, 'w'){ |f| f.puts(json) }
328
+
329
+ Berkshelf.log.info "Updated environment file #{environment_file}"
330
+ end
331
+
300
332
  # Replace the list of dependencies.
301
333
  #
302
334
  # @param [Array<Berkshelf::Dependency>] dependencies
@@ -1,3 +1,3 @@
1
1
  module Berkshelf
2
- VERSION = "4.1.1"
2
+ VERSION = "4.2.0"
3
3
  end
@@ -208,35 +208,52 @@ describe Berkshelf::Lockfile do
208
208
  end
209
209
 
210
210
  describe '#apply' do
211
- let(:connection) { double('connection') }
212
-
213
211
  before do
214
- allow(Berkshelf).to receive(:ridley_connection).and_yield(connection)
212
+ apt = double(name: 'apt', locked_version: '1.0.0')
213
+ jenkins = double(name: 'jenkins', locked_version: '1.4.5')
214
+ allow(subject.graph).to receive(:locks).and_return('apt' => apt, 'jenkins' => jenkins)
215
215
  end
216
216
 
217
- context 'when the Chef environment does not exist' do
218
- it 'raises an exception' do
219
- allow(connection).to receive(:environment).and_return(double(find: nil))
220
- expect {
221
- subject.apply('production')
222
- }.to raise_error(Berkshelf::EnvironmentNotFound)
217
+ describe 'when :envfile option is not used' do
218
+ let(:connection) { double('connection') }
219
+
220
+ before do
221
+ allow(Berkshelf).to receive(:ridley_connection).and_yield(connection)
223
222
  end
224
- end
225
223
 
226
- it 'locks the environment cookbook versions' do
227
- apt = double(name: 'apt', locked_version: '1.0.0')
228
- jenkins = double(name: 'jenkins', locked_version: '1.4.5')
229
- allow(subject.graph).to receive(:locks).and_return('apt' => apt, 'jenkins' => jenkins)
224
+ context 'when the Chef environment does not exist' do
225
+ it 'raises an exception' do
226
+ allow(connection).to receive(:environment).and_return(double(find: nil))
227
+ expect {
228
+ subject.apply('production')
229
+ }.to raise_error(Berkshelf::EnvironmentNotFound)
230
+ end
231
+ end
230
232
 
231
- environment = double('environment', :cookbook_versions= => nil, save: true)
232
- allow(connection).to receive(:environment).and_return(double(find: environment))
233
+ it 'locks the environment cookbook versions on chef server' do
234
+ environment = double('environment', :cookbook_versions= => nil, save: true)
235
+ allow(connection).to receive(:environment).and_return(double(find: environment))
233
236
 
234
- expect(environment).to receive(:cookbook_versions=).with(
235
- 'apt' => '= 1.0.0',
236
- 'jenkins' => '= 1.4.5',
237
- )
237
+ expect(environment).to receive(:cookbook_versions=).with(
238
+ 'apt' => '= 1.0.0',
239
+ 'jenkins' => '= 1.4.5',
240
+ )
238
241
 
239
- subject.apply('production')
242
+ subject.apply('production')
243
+ end
244
+ end
245
+
246
+ describe 'when :envfile option is used' do
247
+ it 'locks the environment cookbook version into envfile' do
248
+ locks = {
249
+ 'apt' => '= 1.0.0',
250
+ 'jenkins' => '= 1.4.5'
251
+ }
252
+
253
+ expect(subject).to receive(:update_environment_file).with('/working/path', locks)
254
+
255
+ subject.apply('production', envfile: '/working/path')
256
+ end
240
257
  end
241
258
  end
242
259
 
@@ -273,6 +290,35 @@ describe Berkshelf::Lockfile do
273
290
  end
274
291
  end
275
292
 
293
+ describe '#update_environment_file' do
294
+ it 'raises an exception when environment file does not exist' do
295
+ allow(File).to receive(:exists?).and_return(false)
296
+ expect {
297
+ subject.update_environment_file('/broken/path', nil)
298
+ }.to raise_error(Berkshelf::EnvironmentFileNotFound)
299
+ end
300
+
301
+ it 'updates the environment file with cookbook versions' do
302
+ file = instance_spy('File')
303
+ locks = {
304
+ 'apt' => '1.0.0',
305
+ 'jenkins' => '1.4.5'
306
+ }
307
+
308
+ allow(File).to receive(:exists?).and_return(true)
309
+ allow(File).to receive(:read).and_return("{}")
310
+ allow(File).to receive(:open).and_yield(file)
311
+
312
+ subject.update_environment_file('/working/path.json', locks)
313
+
314
+ expect(file).to have_received(:puts) do |arg|
315
+ expect(JSON.parse(arg)).to eq({
316
+ 'cookbook_versions' => locks
317
+ })
318
+ end
319
+ end
320
+ end
321
+
276
322
  describe '#update' do
277
323
  it 'resets the dependencies' do
278
324
  subject.update([])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berkshelf
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.1
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Winsor
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2016-02-11 00:00:00.000000000 Z
15
+ date: 2016-02-19 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: addressable
@@ -625,7 +625,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
625
625
  version: 1.8.0
626
626
  requirements: []
627
627
  rubyforge_project:
628
- rubygems_version: 2.4.5.1
628
+ rubygems_version: 2.4.7
629
629
  signing_key:
630
630
  specification_version: 4
631
631
  summary: Manages a Cookbook's, or an Application's, Cookbook dependencies