diff options
Diffstat (limited to 'lib/chef/chef_fs')
5 files changed, 96 insertions, 96 deletions
diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb index 8237729e89..d7541a592e 100644 --- a/lib/chef/chef_fs/chef_fs_data_store.rb +++ b/lib/chef/chef_fs/chef_fs_data_store.rb @@ -172,11 +172,11 @@ class Chef @memory_store.create_dir(path, name, *options) else with_parent_dir(path + [name], *options) do |parent, name| - begin - parent.create_child(name, nil) - rescue Chef::ChefFS::FileSystem::AlreadyExistsError => e - raise ChefZero::DataStore::DataAlreadyExistsError.new(to_zero_path(e.entry), e) - end + + parent.create_child(name, nil) + rescue Chef::ChefFS::FileSystem::AlreadyExistsError => e + raise ChefZero::DataStore::DataAlreadyExistsError.new(to_zero_path(e.entry), e) + end end end @@ -251,11 +251,11 @@ class Chef end with_parent_dir(path + [name], *options) do |parent, name| - begin - parent.create_child(name, data) - rescue Chef::ChefFS::FileSystem::AlreadyExistsError => e - raise ChefZero::DataStore::DataAlreadyExistsError.new(to_zero_path(e.entry), e) - end + + parent.create_child(name, data) + rescue Chef::ChefFS::FileSystem::AlreadyExistsError => e + raise ChefZero::DataStore::DataAlreadyExistsError.new(to_zero_path(e.entry), e) + end end end @@ -349,11 +349,11 @@ class Chef else with_entry(path) do |entry| - begin - entry.read - rescue Chef::ChefFS::FileSystem::NotFoundError => e - raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e) - end + + entry.read + rescue Chef::ChefFS::FileSystem::NotFoundError => e + raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e) + end end end @@ -433,15 +433,15 @@ class Chef else with_entry(path) do |entry| - begin - if %w{cookbooks cookbook_artifacts}.include?(path[0]) && path.length >= 3 - entry.delete(true) - else - entry.delete(false) - end - rescue Chef::ChefFS::FileSystem::NotFoundError => e - raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e) + + if %w{cookbooks cookbook_artifacts}.include?(path[0]) && path.length >= 3 + entry.delete(true) + else + entry.delete(false) end + rescue Chef::ChefFS::FileSystem::NotFoundError => e + raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e) + end end end @@ -471,11 +471,11 @@ class Chef else with_entry(path) do |entry| - begin - entry.delete(options.include?(:recursive)) - rescue Chef::ChefFS::FileSystem::NotFoundError => e - raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e) - end + + entry.delete(options.include?(:recursive)) + rescue Chef::ChefFS::FileSystem::NotFoundError => e + raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e) + end end end @@ -487,11 +487,11 @@ class Chef # LIST /policies elsif path == [ "policies" ] with_entry([ path[0] ]) do |policies| - begin - policies.children.map { |policy| policy.name[0..-6].rpartition("-")[0] }.uniq - rescue Chef::ChefFS::FileSystem::NotFoundError - [] - end + + policies.children.map { |policy| policy.name[0..-6].rpartition("-")[0] }.uniq + rescue Chef::ChefFS::FileSystem::NotFoundError + [] + end # LIST /policies/POLICY/revisions @@ -524,19 +524,19 @@ class Chef elsif %w{cookbooks cookbook_artifacts}.include?(path[0]) && path.length == 1 with_entry(path) do |entry| - begin - if path[0] == "cookbook_artifacts" - entry.children.map { |child| child.name.rpartition("-")[0] }.uniq - elsif chef_fs.versioned_cookbooks - # /cookbooks/name-version -> /cookbooks/name - entry.children.map { |child| split_name_version(child.name)[0] }.uniq - else - entry.children.map(&:name) - end - rescue Chef::ChefFS::FileSystem::NotFoundError - # If the cookbooks dir doesn't exist, we have no cookbooks (not 404) - [] + + if path[0] == "cookbook_artifacts" + entry.children.map { |child| child.name.rpartition("-")[0] }.uniq + elsif chef_fs.versioned_cookbooks + # /cookbooks/name-version -> /cookbooks/name + entry.children.map { |child| split_name_version(child.name)[0] }.uniq + else + entry.children.map(&:name) end + rescue Chef::ChefFS::FileSystem::NotFoundError + # If the cookbooks dir doesn't exist, we have no cookbooks (not 404) + [] + end elsif %w{cookbooks cookbook_artifacts}.include?(path[0]) && path.length == 2 @@ -560,16 +560,16 @@ class Chef else result = with_entry(path) do |entry| - begin - entry.children.map { |c| zero_filename(c) }.sort - rescue Chef::ChefFS::FileSystem::NotFoundError => e - # /cookbooks, /data, etc. never return 404 - if path_always_exists?(path) - [] - else - raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e) - end + + entry.children.map { |c| zero_filename(c) }.sort + rescue Chef::ChefFS::FileSystem::NotFoundError => e + # /cookbooks, /data, etc. never return 404 + if path_always_exists?(path) + [] + else + raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e) end + end # Older versions of chef-zero do not understand policies and cookbook_artifacts, diff --git a/lib/chef/chef_fs/file_system/chef_server/acl_entry.rb b/lib/chef/chef_fs/file_system/chef_server/acl_entry.rb index adf3c26cda..db29ce7ba7 100644 --- a/lib/chef/chef_fs/file_system/chef_server/acl_entry.rb +++ b/lib/chef/chef_fs/file_system/chef_server/acl_entry.rb @@ -47,17 +47,17 @@ class Chef # ACL writes are fun. acls = data_handler.normalize(Chef::JSONCompat.parse(file_contents), self) PERMISSIONS.each do |permission| - begin - rest.put("#{api_path}/#{permission}", { permission => acls[permission] }) - rescue Timeout::Error => e - raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, e, "Timeout writing: #{e}") - rescue Net::HTTPClientException => e - if e.response.code == "404" - raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e) - else - raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, e, "HTTP error writing: #{e}") - end + + rest.put("#{api_path}/#{permission}", { permission => acls[permission] }) + rescue Timeout::Error => e + raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, e, "Timeout writing: #{e}") + rescue Net::HTTPClientException => e + if e.response.code == "404" + raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e) + else + raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, e, "HTTP error writing: #{e}") end + end end end diff --git a/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb b/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb index bcb6b94edf..d852a3bc2e 100644 --- a/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb +++ b/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb @@ -44,15 +44,15 @@ class Chef actual_invites = _read_json.inject({}) { |h, val| h[val["username"]] = val["id"]; h } invites = actual_invites.keys (desired_invites - invites).each do |invite| - begin - rest.post(api_path, { "user" => invite }) - rescue Net::HTTPClientException => e - if e.response.code == "409" - Chef::Log.warn("Could not invite #{invite} to organization #{org}: #{api_error_text(e.response)}") - else - raise - end + + rest.post(api_path, { "user" => invite }) + rescue Net::HTTPClientException => e + if e.response.code == "409" + Chef::Log.warn("Could not invite #{invite} to organization #{org}: #{api_error_text(e.response)}") + else + raise end + end (invites - desired_invites).each do |invite| rest.delete(File.join(api_path, actual_invites[invite])) diff --git a/lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb b/lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb index 31c5f880f8..ded890cc32 100644 --- a/lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb +++ b/lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb @@ -43,15 +43,15 @@ class Chef desired_members = minimize_value(Chef::JSONCompat.parse(contents, create_additions: false)) members = minimize_value(_read_json) (desired_members - members).each do |member| - begin - rest.post(api_path, "username" => member) - rescue Net::HTTPClientException => e - if %w{404 405}.include?(e.response.code) - raise "Chef server at #{api_path} does not allow you to directly add members. Please either upgrade your Chef server or move the users you want into invitations.json instead of members.json." - else - raise - end + + rest.post(api_path, "username" => member) + rescue Net::HTTPClientException => e + if %w{404 405}.include?(e.response.code) + raise "Chef server at #{api_path} does not allow you to directly add members. Please either upgrade your Chef server or move the users you want into invitations.json instead of members.json." + else + raise end + end (members - desired_members).each do |member| rest.delete(File.join(api_path, member)) diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb index 431b9ecb22..c384113a02 100644 --- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb @@ -109,23 +109,23 @@ class Chef child = root_dir.create_child(name, file_contents) else child_paths[name].each do |path| - begin - ::FileUtils.mkdir_p(path) - ::FileUtils.chmod(0700, path) - if ChefUtils.windows? - all_mask = Chef::ReservedNames::Win32::API::Security::GENERIC_ALL - administrators = Chef::ReservedNames::Win32::Security::SID.Administrators - owner = Chef::ReservedNames::Win32::Security::SID.default_security_object_owner - dacl = Chef::ReservedNames::Win32::Security::ACL.create([ - Chef::ReservedNames::Win32::Security::ACE.access_allowed(owner, all_mask), - Chef::ReservedNames::Win32::Security::ACE.access_allowed(administrators, all_mask), - ]) - so = Chef::ReservedNames::Win32::Security::SecurableObject.new(path) - so.owner = owner - so.set_dacl(dacl, false) - end - rescue Errno::EEXIST + + ::FileUtils.mkdir_p(path) + ::FileUtils.chmod(0700, path) + if ChefUtils.windows? + all_mask = Chef::ReservedNames::Win32::API::Security::GENERIC_ALL + administrators = Chef::ReservedNames::Win32::Security::SID.Administrators + owner = Chef::ReservedNames::Win32::Security::SID.default_security_object_owner + dacl = Chef::ReservedNames::Win32::Security::ACL.create([ + Chef::ReservedNames::Win32::Security::ACE.access_allowed(owner, all_mask), + Chef::ReservedNames::Win32::Security::ACE.access_allowed(administrators, all_mask), + ]) + so = Chef::ReservedNames::Win32::Security::SecurableObject.new(path) + so.owner = owner + so.set_dacl(dacl, false) end + rescue Errno::EEXIST + end child = make_child_entry(name) end |