ridley 0.8.6 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -4,7 +4,3 @@ rvm:
4
4
  - 1.9.2
5
5
  - 1.9.3
6
6
  - jruby-19mode
7
- matrix:
8
- allow_failures:
9
- - rvm: jruby-19mode
10
-
@@ -12,9 +12,9 @@ module Ridley::Chef
12
12
  # Licensed under the Apache License, Version 2.0 (the "License");
13
13
  # you may not use this file except in compliance with the License.
14
14
  # You may obtain a copy of the License at
15
- #
15
+ #
16
16
  # http://www.apache.org/licenses/LICENSE-2.0
17
- #
17
+ #
18
18
  # Unless required by applicable law or agreed to in writing, software
19
19
  # distributed under the License is distributed on an "AS IS" BASIS,
20
20
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -91,13 +91,7 @@ module Ridley::Chef
91
91
  end
92
92
 
93
93
  def untested_ruby_files
94
- ruby_files.reject do |file|
95
- if validated?(file)
96
- true
97
- else
98
- false
99
- end
100
- end
94
+ ruby_files.reject { |file| validated?(file) }
101
95
  end
102
96
 
103
97
  def template_files
@@ -105,13 +99,7 @@ module Ridley::Chef
105
99
  end
106
100
 
107
101
  def untested_template_files
108
- template_files.reject do |file|
109
- if validated?(file)
110
- true
111
- else
112
- false
113
- end
114
- end
102
+ template_files.reject { |file| validated?(file) }
115
103
  end
116
104
 
117
105
  def validated?(file)
@@ -137,18 +125,18 @@ module Ridley::Chef
137
125
  end
138
126
 
139
127
  def validate_template(erb_file)
140
- result = shell_out("erubis -x #{erb_file} | ruby -c")
128
+ result = quietly { shell_out("erubis -x #{erb_file} | ruby -c") }
141
129
  result.error!
142
130
  true
143
131
  rescue Mixlib::ShellOut::ShellCommandFailed
144
132
  file_relative_path = erb_file[/^#{Regexp.escape(cookbook_path+File::Separator)}(.*)/, 1]
145
133
  log.error { "Erb template #{file_relative_path} has a syntax error:" }
146
- result.stderr.each_line { |l| Ridley.log..fatal(l.chomp) }
134
+ result.stderr.each_line { |l| Ridley.log.fatal(l.chomp) }
147
135
  false
148
136
  end
149
137
 
150
138
  def validate_ruby_file(ruby_file)
151
- result = shell_out("ruby -c #{ruby_file}")
139
+ result = quietly { shell_out("ruby -c #{ruby_file}") }
152
140
  result.error!
153
141
  true
154
142
  rescue Mixlib::ShellOut::ShellCommandFailed
@@ -74,6 +74,9 @@ module Ridley::Chef
74
74
  # }
75
75
  attr_reader :manifest
76
76
 
77
+ # @return [Boolean]
78
+ attr_accessor :frozen
79
+
77
80
  def_delegator :@metadata, :version
78
81
 
79
82
  def initialize(name, path, metadata)
@@ -92,6 +95,7 @@ module Ridley::Chef
92
95
  providers: Array.new,
93
96
  root_files: Array.new
94
97
  )
98
+ @frozen = false
95
99
 
96
100
  load_files
97
101
  end
@@ -166,11 +170,11 @@ module Ridley::Chef
166
170
  def validate
167
171
  raise IOError, "No Cookbook found at: #{path}" unless path.exist?
168
172
 
169
- unless quietly { syntax_checker.validate_ruby_files }
170
- raise Ridley::Errors::CookbookSyntaxError, "Invalid ruby files in cookbook: #{name} (#{version})."
173
+ unless syntax_checker.validate_ruby_files
174
+ raise Ridley::Errors::CookbookSyntaxError, "Invalid ruby files in cookbook: #{cookbook_name} (#{version})."
171
175
  end
172
- unless quietly { syntax_checker.validate_templates }
173
- raise Ridley::Errors::CookbookSyntaxError, "Invalid template files in cookbook: #{name} (#{version})."
176
+ unless syntax_checker.validate_templates
177
+ raise Ridley::Errors::CookbookSyntaxError, "Invalid template files in cookbook: #{cookbook_name} (#{version})."
174
178
  end
175
179
 
176
180
  true
@@ -183,13 +187,13 @@ module Ridley::Chef
183
187
  result[:cookbook_name] = cookbook_name
184
188
  result[:version] = version
185
189
  result[:metadata] = metadata
190
+ result[:frozen?] = frozen
186
191
  result.to_hash
187
192
  end
188
193
 
189
194
  def to_json(*args)
190
195
  result = self.to_hash
191
196
  result['json_class'] = CHEF_JSON_CLASS
192
- result['frozen?'] = false
193
197
  result.to_json(*args)
194
198
  end
195
199
 
data/lib/ridley/errors.rb CHANGED
@@ -49,6 +49,8 @@ module Ridley
49
49
  end
50
50
  end
51
51
 
52
+ class FrozenCookbook < RidleyError; end
53
+
52
54
  class HTTPError < RidleyError
53
55
  class << self
54
56
  def fabricate(env)
@@ -29,10 +29,6 @@ module Ridley
29
29
  end
30
30
  end
31
31
 
32
- def create(*args)
33
- raise NotImplementedError
34
- end
35
-
36
32
  # Delete a cookbook of the given name and version on the remote Chef server
37
33
  #
38
34
  # @param [Ridley::Client] client
@@ -140,15 +136,12 @@ module Ridley
140
136
  nil
141
137
  end
142
138
 
143
- # Save a new Cookbook Version of the given name, version with the
139
+ # Update or create a new Cookbook Version of the given name, version with the
144
140
  # given manifest of files and checksums.
145
141
  #
146
142
  # @param [Ridley::Client] client
147
- # @param [String] name
148
- # @param [String] version
149
- # @param [String] manifest
150
- # a JSON blob containing file names, file paths, and checksums for each
151
- # that describe the cookbook version being uploaded.
143
+ # @param [Ridley::Chef::Cookbook] cookbook
144
+ # the cookbook to save
152
145
  #
153
146
  # @option options [Boolean] :force
154
147
  # Upload the Cookbook even if the version already exists and is frozen on
@@ -157,19 +150,25 @@ module Ridley
157
150
  # Freeze the uploaded Cookbook on the Chef Server so that it cannot be
158
151
  # overwritten
159
152
  #
153
+ # @raise [Ridley::Errors::FrozenCookbook]
154
+ # if a cookbook of the same name and version already exists on the remote Chef server
155
+ # and is frozen. If the :force option is provided the given cookbook will be saved
156
+ # regardless.
157
+ #
160
158
  # @return [Hash]
161
- def save(client, name, version, manifest, options = {})
159
+ def update(client, cookbook, options = {})
162
160
  options.reverse_merge(force: false, freeze: false)
163
161
 
164
- url = "cookbooks/#{name}/#{version}"
165
- url << "?force=true" if options[:force]
162
+ cookbook.frozen = options[:freeze]
166
163
 
167
- client.connection.put(url, manifest)
168
- end
164
+ url = "cookbooks/#{cookbook.cookbook_name}/#{cookbook.version}"
165
+ url << "?force=true" if options[:force]
169
166
 
170
- def update(*args)
171
- raise NotImplementedError
167
+ client.connection.put(url, cookbook.to_json)
168
+ rescue Ridley::Errors::HTTPConflict => ex
169
+ raise Ridley::Errors::FrozenCookbook, ex
172
170
  end
171
+ alias_method :create, :update
173
172
 
174
173
  # Uploads a cookbook to the remote Chef server from the contents of a filepath
175
174
  #
@@ -195,17 +194,24 @@ module Ridley
195
194
  options = options.reverse_merge(validate: true, force: false, freeze: false)
196
195
  cookbook = Ridley::Chef::Cookbook.from_path(path, options.slice(:name))
197
196
 
197
+ unless (existing = find(client, cookbook.cookbook_name, cookbook.version)).nil?
198
+ if existing.frozen? && options[:force] == false
199
+ msg = "The cookbook #{cookbook.cookbook_name} (#{cookbook.version}) already exists and is"
200
+ msg << " frozen on the Chef server. Use the 'force' option to override."
201
+ raise Ridley::Errors::FrozenCookbook, msg
202
+ end
203
+ end
204
+
198
205
  if options[:validate]
199
206
  cookbook.validate
200
207
  end
201
208
 
202
- name = options[:name] || cookbook.name
203
209
  checksums = cookbook.checksums.dup
204
210
  sandbox = client.sandbox.create(checksums.keys)
205
211
 
206
212
  sandbox.upload(checksums)
207
213
  sandbox.commit
208
- save(client, name, cookbook.version, cookbook.to_json, options.slice(:force, :freeze))
214
+ update(client, cookbook, options.slice(:force, :freeze))
209
215
  end
210
216
 
211
217
  # Return a list of versions for the given cookbook present on the remote Chef server
@@ -293,6 +299,9 @@ module Ridley
293
299
  attribute :version,
294
300
  type: String
295
301
 
302
+ attribute :frozen?,
303
+ type: Boolean
304
+
296
305
  # Download the entire cookbook
297
306
  #
298
307
  # @param [String] destination (Dir.mktmpdir)
@@ -1,3 +1,3 @@
1
1
  module Ridley
2
- VERSION = "0.8.6"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -150,6 +150,10 @@ describe Ridley::Chef::Cookbook do
150
150
  describe "#to_hash" do
151
151
  subject { cookbook.to_hash }
152
152
 
153
+ it "has a :frozen? flag" do
154
+ subject.should have_key(:frozen?)
155
+ end
156
+
153
157
  it "has a :recipes key with a value of an Array Hashes" do
154
158
  subject.should have_key(:recipes)
155
159
  subject[:recipes].should be_a(Array)
@@ -408,5 +412,9 @@ describe Ridley::Chef::Cookbook do
408
412
  @json.should have_json_path('json_class')
409
413
  parse_json(@json)['json_class'].should eql(Ridley::Chef::Cookbook::CHEF_JSON_CLASS)
410
414
  end
415
+
416
+ it "has a 'frozen?' flag" do
417
+ @json.should have_json_path('frozen?')
418
+ end
411
419
  end
412
420
  end
@@ -6,6 +6,7 @@ describe Ridley::CookbookResource do
6
6
  subject { described_class.new(client) }
7
7
 
8
8
  describe "ClassMethods" do
9
+ subject { described_class }
9
10
  let(:server_url) { "https://api.opscode.com/organizations/vialstudios" }
10
11
  let(:client_name) { "reset" }
11
12
  let(:client_key) { fixtures_path.join("reset.pem") }
@@ -132,7 +133,7 @@ describe Ridley::CookbookResource do
132
133
  end
133
134
 
134
135
  describe "::versions" do
135
- let(:cookbook) { "artifact" }
136
+ let(:cookbook) { "artifact" }
136
137
  subject { described_class.versions(client, cookbook) }
137
138
 
138
139
  before(:each) do
@@ -169,6 +170,14 @@ describe Ridley::CookbookResource do
169
170
  subject.should include("1.2.0")
170
171
  end
171
172
  end
173
+
174
+ describe "::upload" do
175
+ pending
176
+ end
177
+
178
+ describe "::update" do
179
+ pending
180
+ end
172
181
  end
173
182
 
174
183
  describe "#download" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridley
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.6
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-20 00:00:00.000000000 Z
12
+ date: 2013-03-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -401,7 +401,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
401
401
  version: '0'
402
402
  segments:
403
403
  - 0
404
- hash: 3721242510601733249
404
+ hash: 141649622166830890
405
405
  requirements: []
406
406
  rubyforge_project:
407
407
  rubygems_version: 1.8.24