diff options
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/cookbook_site_streaming_uploader.rb | 46 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_site_share.rb | 54 | ||||
-rw-r--r-- | lib/chef/provider/registry_key.rb | 4 |
3 files changed, 52 insertions, 52 deletions
diff --git a/lib/chef/cookbook_site_streaming_uploader.rb b/lib/chef/cookbook_site_streaming_uploader.rb index 879a578e15..9e7a55c772 100644 --- a/lib/chef/cookbook_site_streaming_uploader.rb +++ b/lib/chef/cookbook_site_streaming_uploader.rb @@ -35,22 +35,22 @@ class Chef class << self - def create_build_dir(cookbook) - tmp_cookbook_path = Tempfile.new("chef-#{cookbook.name}-build") - tmp_cookbook_path.close - tmp_cookbook_dir = tmp_cookbook_path.path - File.unlink(tmp_cookbook_dir) - FileUtils.mkdir_p(tmp_cookbook_dir) - Chef::Log.debug("Staging at #{tmp_cookbook_dir}") - checksums_to_on_disk_paths = cookbook.checksums - Chef::CookbookVersion::COOKBOOK_SEGMENTS.each do |segment| - cookbook.manifest[segment].each do |manifest_record| - path_in_cookbook = manifest_record[:path] - on_disk_path = checksums_to_on_disk_paths[manifest_record[:checksum]] - dest = File.join(tmp_cookbook_dir, cookbook.name.to_s, path_in_cookbook) - FileUtils.mkdir_p(File.dirname(dest)) - Chef::Log.debug("Staging #{on_disk_path} to #{dest}") - FileUtils.cp(on_disk_path, dest) + def create_build_dir(cookbook) + tmp_cookbook_path = Tempfile.new("chef-#{cookbook.name}-build") + tmp_cookbook_path.close + tmp_cookbook_dir = tmp_cookbook_path.path + File.unlink(tmp_cookbook_dir) + FileUtils.mkdir_p(tmp_cookbook_dir) + Chef::Log.debug("Staging at #{tmp_cookbook_dir}") + checksums_to_on_disk_paths = cookbook.checksums + Chef::CookbookVersion::COOKBOOK_SEGMENTS.each do |segment| + cookbook.manifest[segment].each do |manifest_record| + path_in_cookbook = manifest_record[:path] + on_disk_path = checksums_to_on_disk_paths[manifest_record[:checksum]] + dest = File.join(tmp_cookbook_dir, cookbook.name.to_s, path_in_cookbook) + FileUtils.mkdir_p(File.dirname(dest)) + Chef::Log.debug("Staging #{on_disk_path} to #{dest}") + FileUtils.cp(on_disk_path, dest) end end @@ -87,13 +87,13 @@ class Chef filepath = value.path filename = File.basename(filepath) parts << StringPart.new( "--" + boundary + "\r\n" + - "Content-Disposition: form-data; name=\"" + key.to_s + "\"; filename=\"" + filename + "\"\r\n" + - "Content-Type: application/octet-stream\r\n\r\n") + "Content-Disposition: form-data; name=\"" + key.to_s + "\"; filename=\"" + filename + "\"\r\n" + + "Content-Type: application/octet-stream\r\n\r\n") parts << StreamPart.new(value, File.size(filepath)) parts << StringPart.new("\r\n") else parts << StringPart.new( "--" + boundary + "\r\n" + - "Content-Disposition: form-data; name=\"" + key.to_s + "\"\r\n\r\n") + "Content-Disposition: form-data; name=\"" + key.to_s + "\"\r\n\r\n") parts << StringPart.new(value.to_s + "\r\n") end end @@ -244,10 +244,10 @@ class Chef @part_offset = 0 next_part = read(how_much_next_part) result = current_part + if next_part - next_part - else - '' - end + next_part + else + '' + end else @part_offset += how_much_current_part result = current_part diff --git a/lib/chef/knife/cookbook_site_share.rb b/lib/chef/knife/cookbook_site_share.rb index ee73bfc26a..560e0669c1 100644 --- a/lib/chef/knife/cookbook_site_share.rb +++ b/lib/chef/knife/cookbook_site_share.rb @@ -131,33 +131,33 @@ class Chef end def do_upload(cookbook_filename, cookbook_category, user_id, user_secret_filename) - uri = "https://supermarket.chef.io/api/v1/cookbooks" - - category_string = Chef::JSONCompat.to_json({ 'category'=>cookbook_category }) - - http_resp = Chef::CookbookSiteStreamingUploader.post(uri, user_id, user_secret_filename, { - :tarball => File.open(cookbook_filename), - :cookbook => category_string - }) - - res = Chef::JSONCompat.from_json(http_resp.body) - if http_resp.code.to_i != 201 - if res['error_messages'] - if res['error_messages'][0] =~ /Version already exists/ - ui.error "The same version of this cookbook already exists on the Opscode Cookbook Site." - exit(1) - else - ui.error "#{res['error_messages'][0]}" - exit(1) - end - else - ui.error "Unknown error while sharing cookbook" - ui.error "Server response: #{http_resp.body}" - exit(1) - end - end - res - end + uri = "https://supermarket.chef.io/api/v1/cookbooks" + + category_string = Chef::JSONCompat.to_json({ 'category'=>cookbook_category }) + + http_resp = Chef::CookbookSiteStreamingUploader.post(uri, user_id, user_secret_filename, { + :tarball => File.open(cookbook_filename), + :cookbook => category_string + }) + + res = Chef::JSONCompat.from_json(http_resp.body) + if http_resp.code.to_i != 201 + if res['error_messages'] + if res['error_messages'][0] =~ /Version already exists/ + ui.error "The same version of this cookbook already exists on the Opscode Cookbook Site." + exit(1) + else + ui.error "#{res['error_messages'][0]}" + exit(1) + end + else + ui.error "Unknown error while sharing cookbook" + ui.error "Server response: #{http_resp.body}" + exit(1) + end + end + res + end end end diff --git a/lib/chef/provider/registry_key.rb b/lib/chef/provider/registry_key.rb index 01ee57895e..94f4e2655b 100644 --- a/lib/chef/provider/registry_key.rb +++ b/lib/chef/provider/registry_key.rb @@ -60,9 +60,9 @@ class Chef @registry ||= Chef::Win32::Registry.new(@run_context, @new_resource.architecture) end - def values_to_hash(values) + def values_to_hash(values) if values - @name_hash = Hash[values.map { |val| [val[:name], val] }] + @name_hash = Hash[values.map { |val| [val[:name], val] }] else @name_hash = {} end |