diff options
author | danielsdeleo <dan@getchef.com> | 2015-01-23 16:44:43 -0800 |
---|---|---|
committer | danielsdeleo <dan@getchef.com> | 2015-01-27 12:46:14 -0800 |
commit | 2d847d2caae854f93c0ab5d6de57bf2452dc3e8c (patch) | |
tree | c57cd776caa6b4c89506c5ef94871d1557258ca4 | |
parent | 2f817d8d00135abadc9a279e20a448f9ffe91a1c (diff) | |
download | chef-policyfile-native-api-support.tar.gz |
Improve policy ChefFS supportpolicyfile-native-api-support
5 files changed, 56 insertions, 5 deletions
diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb index 3813d0edb4..9b4f7320b8 100644 --- a/lib/chef/chef_fs/chef_fs_data_store.rb +++ b/lib/chef/chef_fs/chef_fs_data_store.rb @@ -369,6 +369,11 @@ class Chef if path.length >= 3 path[2] = "#{path[2]}.json" end + elsif path[0] == 'policies' + path = path.dup + if path.length >= 3 + path[2] = "#{path[2]}.json" + end elsif path[0] == 'cookbooks' if path.length == 2 raise ChefZero::DataStore::DataNotFoundError.new(path) @@ -445,10 +450,13 @@ class Chef def with_dir(path) # Do not automatically create data bags create = !(path[0] == 'data' && path.size >= 2) + begin yield get_dir(_to_chef_fs_path(path), create) rescue Chef::ChefFS::FileSystem::NotFoundError => e - raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e) + err = ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e) + err.set_backtrace(e.backtrace) + raise err end end diff --git a/lib/chef/chef_fs/data_handler/policy_data_handler.rb b/lib/chef/chef_fs/data_handler/policy_data_handler.rb index 9c1be5ea64..769c13c364 100644 --- a/lib/chef/chef_fs/data_handler/policy_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/policy_data_handler.rb @@ -4,6 +4,10 @@ class Chef module ChefFS module DataHandler class PolicyDataHandler < DataHandlerBase + + def normalize(policy, entry) + policy + end end end end diff --git a/lib/chef/chef_fs/file_system.rb b/lib/chef/chef_fs/file_system.rb index 730fa0e5cc..3ab59046cc 100644 --- a/lib/chef/chef_fs/file_system.rb +++ b/lib/chef/chef_fs/file_system.rb @@ -379,7 +379,7 @@ class Chef should_copy = true src_value = nil else - are_same, src_value, dest_value = compare(src_entry, dest_entry) + are_same, src_value, _dest_value = compare(src_entry, dest_entry) should_copy = !are_same end if should_copy diff --git a/lib/chef/chef_fs/file_system/chef_repository_file_system_policies_dir.rb b/lib/chef/chef_fs/file_system/chef_repository_file_system_policies_dir.rb new file mode 100644 index 0000000000..42768f10b7 --- /dev/null +++ b/lib/chef/chef_fs/file_system/chef_repository_file_system_policies_dir.rb @@ -0,0 +1,38 @@ +# +# Author:: John Keiser (<jkeiser@opscode.com>) +# Copyright:: Copyright (c) 2012 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'chef/chef_fs/file_system/chef_repository_file_system_entry' +require 'chef/chef_fs/data_handler/policy_data_handler' + +class Chef + module ChefFS + module FileSystem + + class ChefRepositoryFileSystemPoliciesDir < ChefRepositoryFileSystemEntry + def initialize(name, parent, path = nil) + super(name, parent, path, Chef::ChefFS::DataHandler::PolicyDataHandler.new) + end + + def can_have_child?(name, is_dir) + is_dir && !name.start_with?('.') + end + end + end + end +end + diff --git a/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb b/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb index 132d6a2b7e..d03baf91fe 100644 --- a/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb @@ -21,12 +21,12 @@ require 'chef/chef_fs/file_system/chef_repository_file_system_entry' require 'chef/chef_fs/file_system/chef_repository_file_system_acls_dir' require 'chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir' require 'chef/chef_fs/file_system/chef_repository_file_system_data_bags_dir' +require 'chef/chef_fs/file_system/chef_repository_file_system_policies_dir' require 'chef/chef_fs/file_system/multiplexed_dir' require 'chef/chef_fs/data_handler/client_data_handler' require 'chef/chef_fs/data_handler/environment_data_handler' require 'chef/chef_fs/data_handler/node_data_handler' require 'chef/chef_fs/data_handler/role_data_handler' -require 'chef/chef_fs/data_handler/policy_data_handler' require 'chef/chef_fs/data_handler/user_data_handler' require 'chef/chef_fs/data_handler/group_data_handler' require 'chef/chef_fs/data_handler/container_data_handler' @@ -34,6 +34,7 @@ require 'chef/chef_fs/data_handler/container_data_handler' class Chef module ChefFS module FileSystem + # # Represents the root of a local Chef repository, with directories for # nodes, cookbooks, roles, etc. under it. @@ -158,6 +159,8 @@ class Chef dirs = paths.map { |path| ChefRepositoryFileSystemCookbooksDir.new(name, self, path) } elsif name == 'data_bags' dirs = paths.map { |path| ChefRepositoryFileSystemDataBagsDir.new(name, self, path) } + elsif name == 'policies' + dirs = paths.map { |path| ChefRepositoryFileSystemPoliciesDir.new(name, self, path) } elsif name == 'acls' dirs = paths.map { |path| ChefRepositoryFileSystemAclsDir.new(name, self, path) } else @@ -170,8 +173,6 @@ class Chef Chef::ChefFS::DataHandler::NodeDataHandler.new when 'roles' Chef::ChefFS::DataHandler::RoleDataHandler.new - when 'policies' - Chef::ChefFS::DataHandler::PolicyDataHandler.new when 'users' Chef::ChefFS::DataHandler::UserDataHandler.new when 'groups' |