summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2013-10-11 13:14:36 -0700
committerJohn Keiser <jkeiser@opscode.com>2013-10-11 13:14:36 -0700
commitbff6f43e38dfadffe4431065a28f5d581b83b8e3 (patch)
treea20057f6584312225007dd33ca90b6ab043ebfc0 /lib/chef
parent6d58ff931dda2d5bfa0eb8b7feadf5cd0fb37c8e (diff)
downloadchef-bff6f43e38dfadffe4431065a28f5d581b83b8e3.tar.gz
Fix DELETE requests for -z for all endpoints, and PUT/POST for cookbooks
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/chef_fs/chef_fs_data_store.rb2
-rw-r--r--lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb19
-rw-r--r--lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb13
-rw-r--r--lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb26
-rw-r--r--lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb11
-rw-r--r--lib/chef/chef_fs/file_system/multiplexed_dir.rb2
-rw-r--r--lib/chef/cookbook_uploader.rb18
7 files changed, 56 insertions, 35 deletions
diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb
index c1c5a81e04..1fedc98380 100644
--- a/lib/chef/chef_fs/chef_fs_data_store.rb
+++ b/lib/chef/chef_fs/chef_fs_data_store.rb
@@ -135,7 +135,7 @@ class Chef
if path[0] == 'cookbooks' && path.length >= 3
entry.delete(true)
else
- entry.delete
+ entry.delete(false)
end
end
end
diff --git a/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb b/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb
index e3d8e47cf2..48fc4b6860 100644
--- a/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb
+++ b/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb
@@ -18,6 +18,7 @@
require 'chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry'
require 'chef/chef_fs/file_system/cookbook_dir'
+require 'chef/chef_fs/file_system/not_found_error'
require 'chef/cookbook/chefignore'
require 'chef/cookbook/cookbook_version_loader'
@@ -51,13 +52,17 @@ class Chef
end
def children
- Dir.entries(file_path).sort.
- select { |child_name| can_have_child?(child_name, File.directory?(File.join(file_path, child_name))) }.
- map do |child_name|
- segment_info = CookbookDir::COOKBOOK_SEGMENT_INFO[child_name.to_sym] || {}
- ChefRepositoryFileSystemCookbookEntry.new(child_name, self, nil, segment_info[:ruby_only], segment_info[:recursive])
- end.
- select { |entry| !(entry.dir? && entry.children.size == 0) }
+ begin
+ Dir.entries(file_path).sort.
+ select { |child_name| can_have_child?(child_name, File.directory?(File.join(file_path, child_name))) }.
+ map do |child_name|
+ segment_info = CookbookDir::COOKBOOK_SEGMENT_INFO[child_name.to_sym] || {}
+ ChefRepositoryFileSystemCookbookEntry.new(child_name, self, nil, segment_info[:ruby_only], segment_info[:recursive])
+ end.
+ select { |entry| !(entry.dir? && entry.children.size == 0) }
+ rescue Errno::ENOENT
+ raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
+ end
end
def can_have_child?(name, is_dir)
diff --git a/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb b/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb
index d2fe3ed5f6..07de961891 100644
--- a/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb
+++ b/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb
@@ -18,6 +18,7 @@
require 'chef/chef_fs/file_system/chef_repository_file_system_entry'
require 'chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir'
+require 'chef/chef_fs/file_system/not_found_error'
class Chef
module ChefFS
@@ -33,10 +34,14 @@ class Chef
attr_reader :recursive
def children
- Dir.entries(file_path).sort.
- select { |child_name| can_have_child?(child_name, File.directory?(File.join(file_path, child_name))) }.
- map { |child_name| ChefRepositoryFileSystemCookbookEntry.new(child_name, self, nil, ruby_only, recursive) }.
- select { |entry| !(entry.dir? && entry.children.size == 0) }
+ begin
+ Dir.entries(file_path).sort.
+ select { |child_name| can_have_child?(child_name, File.directory?(File.join(file_path, child_name))) }.
+ map { |child_name| ChefRepositoryFileSystemCookbookEntry.new(child_name, self, nil, ruby_only, recursive) }.
+ select { |entry| !(entry.dir? && entry.children.size == 0) }
+ rescue Errno::ENOENT
+ raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
+ end
end
def can_have_child?(name, is_dir)
diff --git a/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb b/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb
index 8a987bf9a2..1f3f9f2b5e 100644
--- a/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb
+++ b/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb
@@ -37,18 +37,22 @@ class Chef
attr_reader :chefignore
def children
- Dir.entries(file_path).sort.
- select { |child_name| can_have_child?(child_name, File.directory?(File.join(file_path, child_name))) }.
- map { |child_name| ChefRepositoryFileSystemCookbookDir.new(child_name, self) }.
- select do |entry|
- # empty cookbooks and cookbook directories are ignored
- if entry.children.size == 0
- Chef::Log.warn("Cookbook '#{entry.name}' is empty or entirely chefignored at #{entry.path_for_printing}")
- false
- else
- true
+ begin
+ Dir.entries(file_path).sort.
+ select { |child_name| can_have_child?(child_name, File.directory?(File.join(file_path, child_name))) }.
+ map { |child_name| ChefRepositoryFileSystemCookbookDir.new(child_name, self) }.
+ select do |entry|
+ # empty cookbooks and cookbook directories are ignored
+ if entry.children.size == 0
+ Chef::Log.warn("Cookbook '#{entry.name}' is empty or entirely chefignored at #{entry.path_for_printing}")
+ false
+ else
+ true
+ end
end
- end
+ rescue Errno::ENOENT
+ raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
+ end
end
def can_have_child?(name, is_dir)
diff --git a/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb b/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb
index fa4fda4eb6..90627a1c75 100644
--- a/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb
+++ b/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb
@@ -18,6 +18,7 @@
#
require 'chef/chef_fs/file_system/file_system_entry'
+require 'chef/chef_fs/file_system/not_found_error'
class Chef
module ChefFS
@@ -49,9 +50,13 @@ class Chef
def children
# Except cookbooks and data bag dirs, all things must be json files
- Dir.entries(file_path).sort.
- select { |child_name| can_have_child?(child_name, File.directory?(File.join(file_path, child_name))) }.
- map { |child_name| ChefRepositoryFileSystemEntry.new(child_name, self) }
+ begin
+ Dir.entries(file_path).sort.
+ select { |child_name| can_have_child?(child_name, File.directory?(File.join(file_path, child_name))) }.
+ map { |child_name| ChefRepositoryFileSystemEntry.new(child_name, self) }
+ rescue Errno::ENOENT
+ raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
+ end
end
end
diff --git a/lib/chef/chef_fs/file_system/multiplexed_dir.rb b/lib/chef/chef_fs/file_system/multiplexed_dir.rb
index 01d8bfe7f2..06d4af705d 100644
--- a/lib/chef/chef_fs/file_system/multiplexed_dir.rb
+++ b/lib/chef/chef_fs/file_system/multiplexed_dir.rb
@@ -17,7 +17,7 @@ class Chef
end
def children
- @children ||= begin
+ begin
result = []
seen = {}
# If multiple things have the same name, the first one wins.
diff --git a/lib/chef/cookbook_uploader.rb b/lib/chef/cookbook_uploader.rb
index 9ba5b2bd8b..3ead26e56d 100644
--- a/lib/chef/cookbook_uploader.rb
+++ b/lib/chef/cookbook_uploader.rb
@@ -137,15 +137,17 @@ class Chef
timestamp = Time.now.utc.iso8601
file_contents = File.open(file, "rb") {|f| f.read}
# TODO - 5/28/2010, cw: make signing and sending the request streaming
- sign_obj = Mixlib::Authentication::SignedHeaderAuth.signing_object(
- :http_method => :put,
- :path => URI.parse(url).path,
- :body => file_contents,
- :timestamp => timestamp,
- :user_id => rest.client_name
- )
headers = { 'content-type' => 'application/x-binary', 'content-md5' => checksum64, :accept => 'application/json' }
- headers.merge!(sign_obj.sign(OpenSSL::PKey::RSA.new(rest.signing_key)))
+ if rest.signing_key
+ sign_obj = Mixlib::Authentication::SignedHeaderAuth.signing_object(
+ :http_method => :put,
+ :path => URI.parse(url).path,
+ :body => file_contents,
+ :timestamp => timestamp,
+ :user_id => rest.client_name
+ )
+ headers.merge!(sign_obj.sign(OpenSSL::PKey::RSA.new(rest.signing_key)))
+ end
begin
RestClient::Resource.new(url, :headers=>headers, :timeout=>1800, :open_timeout=>1800).put(file_contents)