diff options
author | Thom May <thom@chef.io> | 2016-04-13 17:18:13 +0100 |
---|---|---|
committer | Thom May <thom@chef.io> | 2016-04-13 18:52:09 +0100 |
commit | d4a7d82ae1042a601f768edca3bdb94f81a3a387 (patch) | |
tree | b0dcf7965c6941ea2a29679ebf2a0e0527683bd8 /lib | |
parent | bf121d46ad8e73b9927bfe3c9a241ecbe9d13c9f (diff) | |
download | chef-d4a7d82ae1042a601f768edca3bdb94f81a3a387.tar.gz |
Ensure most directories are subclasses of Directorytm/flow_252
This doesn't yet change the cookbook classes, but everything that is a
directory is treated as such.
Diffstat (limited to 'lib')
12 files changed, 374 insertions, 35 deletions
diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_acls_dir.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_acls_dir.rb index c347e808f9..cb4c495156 100644 --- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_acls_dir.rb +++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_acls_dir.rb @@ -17,6 +17,7 @@ # require "chef/chef_fs/file_system/repository/chef_repository_file_system_entry" +require "chef/chef_fs/file_system/repository/directory" require "chef/chef_fs/file_system/chef_server/acls_dir" require "chef/chef_fs/data_handler/acl_data_handler" @@ -24,14 +25,17 @@ class Chef module ChefFS module FileSystem module Repository - class ChefRepositoryFileSystemAclsDir < ChefRepositoryFileSystemEntry - def initialize(name, parent, path = nil) - super(name, parent, path, Chef::ChefFS::DataHandler::AclDataHandler.new) - end + class ChefRepositoryFileSystemAclsDir < Repository::Directory def can_have_child?(name, is_dir) is_dir ? Chef::ChefFS::FileSystem::ChefServer::AclsDir::ENTITY_TYPES.include?(name) : name == "organization.json" end + + protected + + def make_child_entry(child_name) + ChefRepositoryFileSystemEntry.new(child_name, self, nil, Chef::ChefFS::DataHandler::AclDataHandler.new) + end end end end diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_client_keys_dir.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_client_keys_dir.rb index 237d1035ad..544f089096 100644 --- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_client_keys_dir.rb +++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_client_keys_dir.rb @@ -18,19 +18,23 @@ require "chef/chef_fs/file_system/repository/chef_repository_file_system_entry" require "chef/chef_fs/data_handler/client_key_data_handler" +require "chef/chef_fs/file_system/repository/directory" class Chef module ChefFS module FileSystem module Repository class ChefRepositoryFileSystemClientKeysDir < ChefRepositoryFileSystemEntry - def initialize(name, parent, path = nil) - super(name, parent, path, Chef::ChefFS::DataHandler::ClientKeyDataHandler.new) - end def can_have_child?(name, is_dir) is_dir && !name.start_with?(".") end + + protected + + def make_child_entry(child_name) + ChefRepositoryFileSystemEntry.new(child_name, self, nil, Chef::ChefFS::DataHandler::ClientKeyDataHandler.new) + end end end end 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 c7209ba634..4457910317 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 @@ -18,9 +18,17 @@ require "chef/chef_fs/file_system/base_fs_dir" require "chef/chef_fs/file_system/repository/chef_repository_file_system_acls_dir" +require "chef/chef_fs/file_system/repository/clients_dir" require "chef/chef_fs/file_system/repository/cookbooks_dir" require "chef/chef_fs/file_system/repository/cookbook_artifacts_dir" +require "chef/chef_fs/file_system/repository/containers_dir" require "chef/chef_fs/file_system/repository/data_bags_dir" +require "chef/chef_fs/file_system/repository/environments_dir" +require "chef/chef_fs/file_system/repository/groups_dir" +require "chef/chef_fs/file_system/repository/nodes_dir" +require "chef/chef_fs/file_system/repository/policy_groups_dir" +require "chef/chef_fs/file_system/repository/roles_dir" +require "chef/chef_fs/file_system/repository/users_dir" require "chef/chef_fs/file_system/repository/chef_repository_file_system_client_keys_dir" require "chef/chef_fs/file_system/repository/chef_repository_file_system_entry" require "chef/chef_fs/file_system/repository/chef_repository_file_system_policies_dir" @@ -166,6 +174,14 @@ class Chef return NonexistentFSObject.new(name, self) end case name + when "acls" + dirs = paths.map { |path| ChefRepositoryFileSystemAclsDir.new(name, self, path) } + when "client_keys" + dirs = paths.map { |path| ChefRepositoryFileSystemClientKeysDir.new(name, self, path) } + when "clients" + dirs = paths.map { |path| ClientsDir.new(name, self, path) } + when "containers" + dirs = paths.map { |path| ContainersDir.new(name, self, path) } when "cookbooks" if versioned_cookbooks dirs = paths.map { |path| VersionedCookbooksDir.new(name, self, path) } @@ -174,36 +190,24 @@ class Chef end when "cookbook_artifacts" dirs = paths.map { |path| CookbookArtifactsDir.new(name, self, path) } - when "policies" - dirs = paths.map { |path| ChefRepositoryFileSystemPoliciesDir.new(name, self, path) } when "data_bags" dirs = paths.map { |path| DataBagsDir.new(name, self, path) } - when "acls" - dirs = paths.map { |path| ChefRepositoryFileSystemAclsDir.new(name, self, path) } - when "client_keys" - dirs = paths.map { |path| ChefRepositoryFileSystemClientKeysDir.new(name, self, path) } + when "environments" + dirs = paths.map { |path| EnvironmentsDir.new(name, self, path) } + when "groups" + dirs = paths.map { |path| GroupsDir.new(name, self, path) } + when "nodes" + dirs = paths.map { |path| NodesDir.new(name, self, path) } + when "policy_groups" + dirs = paths.map { |path| PolicyGroupsDir.new(name, self, path) } + when "policies" + dirs = paths.map { |path| ChefRepositoryFileSystemPoliciesDir.new(name, self, path) } + when "roles" + dirs = paths.map { |path| RolesDir.new(name, self, path) } + when "users" + dirs = paths.map { |path| UsersDir.new(name, self, path) } else - data_handler = case name - when "clients" - Chef::ChefFS::DataHandler::ClientDataHandler.new - when "environments" - Chef::ChefFS::DataHandler::EnvironmentDataHandler.new - when "nodes" - Chef::ChefFS::DataHandler::NodeDataHandler.new - when "policy_groups" - Chef::ChefFS::DataHandler::PolicyGroupDataHandler.new - when "roles" - Chef::ChefFS::DataHandler::RoleDataHandler.new - when "users" - Chef::ChefFS::DataHandler::UserDataHandler.new - when "groups" - Chef::ChefFS::DataHandler::GroupDataHandler.new - when "containers" - Chef::ChefFS::DataHandler::ContainerDataHandler.new - else - raise "Unknown top level path #{name}" - end - dirs = paths.map { |path| ChefRepositoryFileSystemEntry.new(name, self, path, data_handler) } + raise "Unknown top level path #{name}" end MultiplexedDir.new(dirs) end diff --git a/lib/chef/chef_fs/file_system/repository/clients_dir.rb b/lib/chef/chef_fs/file_system/repository/clients_dir.rb new file mode 100644 index 0000000000..6e23a6b8be --- /dev/null +++ b/lib/chef/chef_fs/file_system/repository/clients_dir.rb @@ -0,0 +1,40 @@ +# +# Author:: John Keiser (<jkeiser@chef.io>) +# Author:: Ho-Sheng Hsiao (<hosh@chef.io>) +# Copyright:: Copyright 2012-2016, Chef Software 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/repository/chef_repository_file_system_entry" +require "chef/chef_fs/file_system/repository/directory" +require "chef/chef_fs/file_system/exceptions" + +class Chef + module ChefFS + module FileSystem + module Repository + class ClientsDir < Repository::Directory + def can_have_child?(name, is_dir) + !is_dir && File.extname(name) == ".json" + end + + def make_child_entry(child_name) + ChefRepositoryFileSystemEntry.new(child_name, self, nil, Chef::ChefFS::DataHandler::ClientDataHandler.new) + end + end + end + end + end +end diff --git a/lib/chef/chef_fs/file_system/repository/containers_dir.rb b/lib/chef/chef_fs/file_system/repository/containers_dir.rb new file mode 100644 index 0000000000..b5ff84be7b --- /dev/null +++ b/lib/chef/chef_fs/file_system/repository/containers_dir.rb @@ -0,0 +1,41 @@ +# +# Author:: John Keiser (<jkeiser@chef.io>) +# Author:: Ho-Sheng Hsiao (<hosh@chef.io>) +# Copyright:: Copyright 2012-2016, Chef Software 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/repository/chef_repository_file_system_entry" +require "chef/chef_fs/file_system/repository/directory" +require "chef/chef_fs/file_system/exceptions" + +class Chef + module ChefFS + module FileSystem + module Repository + class ContainersDir < Repository::Directory + + def can_have_child?(name, is_dir) + !is_dir && File.extname(name) == ".json" + end + + def make_child_entry(child_name) + ChefRepositoryFileSystemEntry.new(child_name, self, nil, Chef::ChefFS::DataHandler::ContainerDataHandler.new) + end + end + end + end + end +end diff --git a/lib/chef/chef_fs/file_system/repository/directory.rb b/lib/chef/chef_fs/file_system/repository/directory.rb index 35dd9f2540..20f6f82108 100644 --- a/lib/chef/chef_fs/file_system/repository/directory.rb +++ b/lib/chef/chef_fs/file_system/repository/directory.rb @@ -66,7 +66,7 @@ class Chef def children dir_ls.sort. map { |child_name| make_child_entry(child_name) }. - select { |new_child| new_child.fs_entry_valid? && can_have_child?(new_child.name, new_child.dir?)} + select { |new_child| new_child.fs_entry_valid? && can_have_child?(new_child.name, new_child.dir?) } rescue Errno::ENOENT => e raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e) end diff --git a/lib/chef/chef_fs/file_system/repository/environments_dir.rb b/lib/chef/chef_fs/file_system/repository/environments_dir.rb new file mode 100644 index 0000000000..50b6dbefca --- /dev/null +++ b/lib/chef/chef_fs/file_system/repository/environments_dir.rb @@ -0,0 +1,41 @@ +# +# Author:: John Keiser (<jkeiser@chef.io>) +# Author:: Ho-Sheng Hsiao (<hosh@chef.io>) +# Copyright:: Copyright 2012-2016, Chef Software 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/repository/chef_repository_file_system_entry" +require "chef/chef_fs/data_handler/environment_data_handler" +require "chef/chef_fs/file_system/repository/directory" + +class Chef + module ChefFS + module FileSystem + module Repository + class EnvironmentsDir < Repository::Directory + + def can_have_child?(name, is_dir) + !is_dir && File.extname(name) == ".json" + end + + def make_child_entry(child_name) + ChefRepositoryFileSystemEntry.new(child_name, self, nil, Chef::ChefFS::DataHandler::EnvironmentDataHandler.new) + end + end + end + end + end +end diff --git a/lib/chef/chef_fs/file_system/repository/groups_dir.rb b/lib/chef/chef_fs/file_system/repository/groups_dir.rb new file mode 100644 index 0000000000..f9ca4956b0 --- /dev/null +++ b/lib/chef/chef_fs/file_system/repository/groups_dir.rb @@ -0,0 +1,41 @@ +# +# Author:: John Keiser (<jkeiser@chef.io>) +# Author:: Ho-Sheng Hsiao (<hosh@chef.io>) +# Copyright:: Copyright 2012-2016, Chef Software 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/repository/chef_repository_file_system_entry" +require "chef/chef_fs/file_system/repository/directory" +require "chef/chef_fs/file_system/exceptions" + +class Chef + module ChefFS + module FileSystem + module Repository + class GroupsDir < Repository::Directory + + def can_have_child?(name, is_dir) + !is_dir && File.extname(name) == ".json" + end + + def make_child_entry(child_name) + ChefRepositoryFileSystemEntry.new(child_name, self, nil, Chef::ChefFS::DataHandler::GroupDataHandler.new) + end + end + end + end + end +end diff --git a/lib/chef/chef_fs/file_system/repository/nodes_dir.rb b/lib/chef/chef_fs/file_system/repository/nodes_dir.rb new file mode 100644 index 0000000000..7263dc3132 --- /dev/null +++ b/lib/chef/chef_fs/file_system/repository/nodes_dir.rb @@ -0,0 +1,41 @@ +# +# Author:: John Keiser (<jkeiser@chef.io>) +# Author:: Ho-Sheng Hsiao (<hosh@chef.io>) +# Copyright:: Copyright 2012-2016, Chef Software 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/repository/chef_repository_file_system_entry" +require "chef/chef_fs/file_system/repository/directory" +require "chef/chef_fs/file_system/exceptions" + +class Chef + module ChefFS + module FileSystem + module Repository + class NodesDir < Repository::Directory + + def can_have_child?(name, is_dir) + !is_dir && File.extname(name) == ".json" + end + + def make_child_entry(child_name) + ChefRepositoryFileSystemEntry.new(child_name, self, nil, Chef::ChefFS::DataHandler::NodeDataHandler.new) + end + end + end + end + end +end diff --git a/lib/chef/chef_fs/file_system/repository/policy_groups_dir.rb b/lib/chef/chef_fs/file_system/repository/policy_groups_dir.rb new file mode 100644 index 0000000000..314c375879 --- /dev/null +++ b/lib/chef/chef_fs/file_system/repository/policy_groups_dir.rb @@ -0,0 +1,41 @@ +# +# Author:: John Keiser (<jkeiser@chef.io>) +# Author:: Ho-Sheng Hsiao (<hosh@chef.io>) +# Copyright:: Copyright 2012-2016, Chef Software 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/repository/chef_repository_file_system_entry" +require "chef/chef_fs/file_system/repository/directory" +require "chef/chef_fs/file_system/exceptions" + +class Chef + module ChefFS + module FileSystem + module Repository + class PolicyGroupsDir < Repository::Directory + + def can_have_child?(name, is_dir) + !is_dir && File.extname(name) == ".json" + end + + def make_child_entry(child_name) + ChefRepositoryFileSystemEntry.new(child_name, self, nil, Chef::ChefFS::DataHandler::PolicyGroupDataHandler.new) + end + end + end + end + end +end diff --git a/lib/chef/chef_fs/file_system/repository/roles_dir.rb b/lib/chef/chef_fs/file_system/repository/roles_dir.rb new file mode 100644 index 0000000000..e3acd3a730 --- /dev/null +++ b/lib/chef/chef_fs/file_system/repository/roles_dir.rb @@ -0,0 +1,41 @@ +# +# Author:: John Keiser (<jkeiser@chef.io>) +# Author:: Ho-Sheng Hsiao (<hosh@chef.io>) +# Copyright:: Copyright 2012-2016, Chef Software 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/repository/chef_repository_file_system_entry" +require "chef/chef_fs/file_system/repository/directory" +require "chef/chef_fs/file_system/exceptions" + +class Chef + module ChefFS + module FileSystem + module Repository + class RolesDir < Repository::Directory + + def can_have_child?(name, is_dir) + !is_dir && File.extname(name) == ".json" + end + + def make_child_entry(child_name) + ChefRepositoryFileSystemEntry.new(child_name, self, nil, Chef::ChefFS::DataHandler::RoleDataHandler.new) + end + end + end + end + end +end diff --git a/lib/chef/chef_fs/file_system/repository/users_dir.rb b/lib/chef/chef_fs/file_system/repository/users_dir.rb new file mode 100644 index 0000000000..928bb2d699 --- /dev/null +++ b/lib/chef/chef_fs/file_system/repository/users_dir.rb @@ -0,0 +1,41 @@ +# +# Author:: John Keiser (<jkeiser@chef.io>) +# Author:: Ho-Sheng Hsiao (<hosh@chef.io>) +# Copyright:: Copyright 2012-2016, Chef Software 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/repository/chef_repository_file_system_entry" +require "chef/chef_fs/file_system/repository/directory" +require "chef/chef_fs/file_system/exceptions" + +class Chef + module ChefFS + module FileSystem + module Repository + class UsersDir < Repository::Directory + + def can_have_child?(name, is_dir) + !is_dir && File.extname(name) == ".json" + end + + def make_child_entry(child_name) + ChefRepositoryFileSystemEntry.new(child_name, self, nil, Chef::ChefFS::DataHandler::UserDataHandler.new) + end + end + end + end + end +end |