chef 12.9.41 → 12.10.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +52 -13
  3. data/README.md +145 -0
  4. data/Rakefile +4 -14
  5. data/VERSION +1 -1
  6. data/acceptance/.gitignore +0 -1
  7. data/acceptance/Gemfile +2 -2
  8. data/acceptance/Gemfile.lock +235 -0
  9. data/acceptance/fips/.kitchen.yml +5 -1
  10. data/acceptance/fips/test/integration/{fips → fips-integration}/serverspec/Gemfile +0 -0
  11. data/acceptance/fips/test/integration/fips-integration/serverspec/fips-integration_spec.rb +51 -0
  12. data/acceptance/fips/test/integration/fips-unit-functional/serverspec/Gemfile +3 -0
  13. data/acceptance/fips/test/integration/fips-unit-functional/serverspec/fips-unit-functional_spec.rb +56 -0
  14. data/{chef-windows.gemspec → chef-universal-mingw32.gemspec} +0 -0
  15. data/chef.gemspec +0 -6
  16. data/{lib → lib-backcompat}/chef/chef_fs/file_system/already_exists_error.rb +0 -0
  17. data/{lib → lib-backcompat}/chef/chef_fs/file_system/cookbook_frozen_error.rb +0 -0
  18. data/{lib → lib-backcompat}/chef/chef_fs/file_system/default_environment_cannot_be_modified_error.rb +0 -0
  19. data/{lib → lib-backcompat}/chef/chef_fs/file_system/file_system_error.rb +0 -0
  20. data/{lib → lib-backcompat}/chef/chef_fs/file_system/must_delete_recursively_error.rb +0 -0
  21. data/{lib → lib-backcompat}/chef/chef_fs/file_system/not_found_error.rb +0 -0
  22. data/{lib → lib-backcompat}/chef/chef_fs/file_system/operation_failed_error.rb +0 -0
  23. data/{lib → lib-backcompat}/chef/chef_fs/file_system/operation_not_allowed_error.rb +0 -0
  24. data/lib-backcompat/chef/chef_fs/file_system/repository/chef_repository_file_system_acls_dir.rb +5 -0
  25. data/lib-backcompat/chef/chef_fs/file_system/repository/chef_repository_file_system_client_keys_dir.rb +5 -0
  26. data/lib-backcompat/chef/chef_fs/file_system/repository/chef_repository_file_system_entry.rb +6 -0
  27. data/lib-backcompat/chef/chef_fs/file_system/repository/chef_repository_file_system_policies_dir.rb +5 -0
  28. data/{lib → lib-backcompat}/chef/chef_fs/file_system/repository/file_system_root_dir.rb +1 -0
  29. data/lib/chef/chef_fs/file_system/repository/acl.rb +38 -0
  30. data/lib/chef/chef_fs/file_system/repository/{chef_repository_file_system_acls_dir.rb → acls_dir.rb} +14 -5
  31. data/lib/chef/chef_fs/file_system/repository/acls_sub_dir.rb +42 -0
  32. data/lib/chef/chef_fs/file_system/repository/base_file.rb +120 -0
  33. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +1 -1
  34. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +36 -32
  35. data/lib/chef/chef_fs/file_system/repository/client.rb +38 -0
  36. data/lib/chef/chef_fs/file_system/repository/client_key.rb +38 -0
  37. data/lib/chef/chef_fs/file_system/repository/{chef_repository_file_system_client_keys_dir.rb → client_keys_dir.rb} +9 -5
  38. data/lib/chef/chef_fs/file_system/repository/client_keys_sub_dir.rb +42 -0
  39. data/lib/chef/chef_fs/file_system/repository/clients_dir.rb +40 -0
  40. data/lib/chef/chef_fs/file_system/repository/container.rb +38 -0
  41. data/lib/chef/chef_fs/file_system/repository/containers_dir.rb +41 -0
  42. data/lib/chef/chef_fs/file_system/repository/cookbooks_dir.rb +0 -1
  43. data/lib/chef/chef_fs/file_system/repository/data_bag_item.rb +3 -79
  44. data/lib/chef/chef_fs/file_system/repository/directory.rb +15 -2
  45. data/lib/chef/chef_fs/file_system/repository/environment.rb +38 -0
  46. data/lib/chef/chef_fs/file_system/repository/environments_dir.rb +41 -0
  47. data/lib/chef/chef_fs/file_system/repository/file_system_entry.rb +66 -30
  48. data/lib/chef/chef_fs/file_system/repository/group.rb +38 -0
  49. data/lib/chef/chef_fs/file_system/repository/groups_dir.rb +41 -0
  50. data/lib/chef/chef_fs/file_system/repository/node.rb +38 -0
  51. data/lib/chef/chef_fs/file_system/repository/nodes_dir.rb +41 -0
  52. data/lib/chef/chef_fs/file_system/repository/{chef_repository_file_system_policies_dir.rb → policies_dir.rb} +9 -5
  53. data/lib/chef/chef_fs/file_system/repository/policy.rb +38 -0
  54. data/lib/chef/chef_fs/file_system/repository/policy_group.rb +38 -0
  55. data/lib/chef/chef_fs/file_system/repository/policy_groups_dir.rb +41 -0
  56. data/lib/chef/chef_fs/file_system/repository/role.rb +38 -0
  57. data/lib/chef/chef_fs/file_system/repository/roles_dir.rb +41 -0
  58. data/lib/chef/chef_fs/file_system/repository/user.rb +38 -0
  59. data/lib/chef/chef_fs/file_system/repository/users_dir.rb +41 -0
  60. data/lib/chef/dsl/declare_resource.rb +182 -7
  61. data/lib/chef/http/json_input.rb +2 -2
  62. data/lib/chef/knife.rb +1 -1
  63. data/lib/chef/mixin/shell_out.rb +10 -21
  64. data/lib/chef/property.rb +9 -2
  65. data/lib/chef/provider.rb +8 -7
  66. data/lib/chef/provider/apt_repository.rb +8 -6
  67. data/lib/chef/provider/directory.rb +15 -1
  68. data/lib/chef/provider/env/windows.rb +1 -1
  69. data/lib/chef/provider/mdadm.rb +1 -0
  70. data/lib/chef/provider/package/easy_install.rb +2 -0
  71. data/lib/chef/provider/package/rubygems.rb +4 -1
  72. data/lib/chef/provider/package/windows.rb +1 -1
  73. data/lib/chef/recipe.rb +1 -2
  74. data/lib/chef/resource/apt_repository.rb +6 -6
  75. data/lib/chef/resource/mdadm.rb +9 -0
  76. data/lib/chef/resource_collection.rb +5 -0
  77. data/lib/chef/resource_collection/resource_list.rb +10 -0
  78. data/lib/chef/resource_collection/resource_set.rb +14 -11
  79. data/lib/chef/version.rb +1 -1
  80. data/spec/functional/resource/git_spec.rb +1 -3
  81. data/spec/functional/resource/group_spec.rb +5 -5
  82. data/spec/functional/tiny_server_spec.rb +1 -1
  83. data/spec/functional/util/powershell/cmdlet_spec.rb +1 -1
  84. data/spec/functional/win32/registry_spec.rb +3 -3
  85. data/spec/integration/solo/solo_spec.rb +2 -2
  86. data/spec/support/shared/functional/securable_resource.rb +1 -1
  87. data/spec/support/shared/unit/provider/file.rb +3 -3
  88. data/spec/support/shared/unit/windows_script_resource.rb +1 -1
  89. data/spec/unit/application/apply_spec.rb +1 -0
  90. data/spec/unit/chef_fs/file_system/repository/base_file_spec.rb +128 -0
  91. data/spec/unit/chef_fs/file_system/repository/directory_spec.rb +174 -0
  92. data/spec/unit/cookbook/metadata_spec.rb +1 -1
  93. data/spec/unit/dsl/declare_resource_spec.rb +335 -0
  94. data/spec/unit/knife/bootstrap_spec.rb +2 -2
  95. data/spec/unit/mixin/shell_out_spec.rb +4 -0
  96. data/spec/unit/node/attribute_spec.rb +1 -1
  97. data/spec/unit/node/immutable_collections_spec.rb +2 -2
  98. data/spec/unit/node_map_spec.rb +1 -1
  99. data/spec/unit/property/validation_spec.rb +23 -7
  100. data/spec/unit/provider/apt_repository_spec.rb +5 -0
  101. data/spec/unit/provider/apt_update_spec.rb +1 -0
  102. data/spec/unit/provider/directory_spec.rb +0 -7
  103. data/spec/unit/provider/file/content_spec.rb +1 -1
  104. data/spec/unit/provider/mdadm_spec.rb +9 -0
  105. data/spec/unit/provider/package/easy_install_spec.rb +6 -0
  106. data/spec/unit/provider/package/rubygems_spec.rb +8 -4
  107. data/spec/unit/provider/package/yum_spec.rb +1 -1
  108. data/spec/unit/provider/powershell_script_spec.rb +1 -1
  109. data/spec/unit/provider/user/dscl_spec.rb +6 -6
  110. data/spec/unit/recipe_spec.rb +1 -0
  111. data/spec/unit/resource/apt_repository_spec.rb +4 -0
  112. data/spec/unit/resource/file/verification_spec.rb +1 -1
  113. data/spec/unit/resource/file_spec.rb +2 -2
  114. data/spec/unit/resource/mdadm_spec.rb +7 -2
  115. data/spec/unit/resource_collection_spec.rb +30 -0
  116. data/spec/unit/resource_spec.rb +1 -1
  117. data/tasks/bin/bundle-platform +15 -0
  118. data/tasks/bin/bundle-platform.bat +2 -0
  119. data/tasks/bin/create-override-gemfile +110 -0
  120. data/tasks/bin/run_chef_tests +17 -0
  121. data/tasks/bin/run_external_test +47 -0
  122. data/tasks/bundle.rb +97 -0
  123. data/tasks/bundle_util.rb +94 -0
  124. data/tasks/changelog.rb +12 -0
  125. data/tasks/dependencies.rb +147 -0
  126. data/tasks/gemfile_util.rb +390 -0
  127. data/tasks/maintainers.rb +2 -1
  128. data/tasks/rspec.rb +2 -1
  129. metadata +61 -83
  130. data/acceptance/fips/test/integration/fips/serverspec/fips_spec.rb +0 -39
  131. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_entry.rb +0 -83
  132. data/tasks/external_tests.rb +0 -64
@@ -17,13 +17,21 @@
17
17
  #
18
18
 
19
19
  require "chef/chef_fs/file_system/base_fs_dir"
20
- require "chef/chef_fs/file_system/repository/chef_repository_file_system_acls_dir"
20
+ require "chef/chef_fs/file_system/repository/acls_dir"
21
+ require "chef/chef_fs/file_system/repository/clients_dir"
21
22
  require "chef/chef_fs/file_system/repository/cookbooks_dir"
22
23
  require "chef/chef_fs/file_system/repository/cookbook_artifacts_dir"
24
+ require "chef/chef_fs/file_system/repository/containers_dir"
23
25
  require "chef/chef_fs/file_system/repository/data_bags_dir"
24
- require "chef/chef_fs/file_system/repository/chef_repository_file_system_client_keys_dir"
25
- require "chef/chef_fs/file_system/repository/chef_repository_file_system_entry"
26
- require "chef/chef_fs/file_system/repository/chef_repository_file_system_policies_dir"
26
+ require "chef/chef_fs/file_system/repository/environments_dir"
27
+ require "chef/chef_fs/file_system/repository/groups_dir"
28
+ require "chef/chef_fs/file_system/repository/nodes_dir"
29
+ require "chef/chef_fs/file_system/repository/policy_groups_dir"
30
+ require "chef/chef_fs/file_system/repository/roles_dir"
31
+ require "chef/chef_fs/file_system/repository/users_dir"
32
+ require "chef/chef_fs/file_system/repository/client_keys_dir"
33
+ require "chef/chef_fs/file_system/repository/file_system_entry"
34
+ require "chef/chef_fs/file_system/repository/policies_dir"
27
35
  require "chef/chef_fs/file_system/repository/versioned_cookbooks_dir"
28
36
  require "chef/chef_fs/file_system/multiplexed_dir"
29
37
  require "chef/chef_fs/data_handler/client_data_handler"
@@ -142,7 +150,7 @@ class Chef
142
150
  existing_paths = root_paths.select { |path| File.exists?(path) }
143
151
  if existing_paths.size > 0
144
152
  MultiplexedDir.new(existing_paths.map do |path|
145
- dir = ChefRepositoryFileSystemEntry.new(name, parent, path)
153
+ dir = FileSystemEntry.new(name, parent, path)
146
154
  dir.write_pretty_json = !!write_pretty_json
147
155
  dir
148
156
  end)
@@ -166,6 +174,14 @@ class Chef
166
174
  return NonexistentFSObject.new(name, self)
167
175
  end
168
176
  case name
177
+ when "acls"
178
+ dirs = paths.map { |path| AclsDir.new(name, self, path) }
179
+ when "client_keys"
180
+ dirs = paths.map { |path| ClientKeysDir.new(name, self, path) }
181
+ when "clients"
182
+ dirs = paths.map { |path| ClientsDir.new(name, self, path) }
183
+ when "containers"
184
+ dirs = paths.map { |path| ContainersDir.new(name, self, path) }
169
185
  when "cookbooks"
170
186
  if versioned_cookbooks
171
187
  dirs = paths.map { |path| VersionedCookbooksDir.new(name, self, path) }
@@ -174,36 +190,24 @@ class Chef
174
190
  end
175
191
  when "cookbook_artifacts"
176
192
  dirs = paths.map { |path| CookbookArtifactsDir.new(name, self, path) }
177
- when "policies"
178
- dirs = paths.map { |path| ChefRepositoryFileSystemPoliciesDir.new(name, self, path) }
179
193
  when "data_bags"
180
194
  dirs = paths.map { |path| DataBagsDir.new(name, self, path) }
181
- when "acls"
182
- dirs = paths.map { |path| ChefRepositoryFileSystemAclsDir.new(name, self, path) }
183
- when "client_keys"
184
- dirs = paths.map { |path| ChefRepositoryFileSystemClientKeysDir.new(name, self, path) }
195
+ when "environments"
196
+ dirs = paths.map { |path| EnvironmentsDir.new(name, self, path) }
197
+ when "groups"
198
+ dirs = paths.map { |path| GroupsDir.new(name, self, path) }
199
+ when "nodes"
200
+ dirs = paths.map { |path| NodesDir.new(name, self, path) }
201
+ when "policy_groups"
202
+ dirs = paths.map { |path| PolicyGroupsDir.new(name, self, path) }
203
+ when "policies"
204
+ dirs = paths.map { |path| PoliciesDir.new(name, self, path) }
205
+ when "roles"
206
+ dirs = paths.map { |path| RolesDir.new(name, self, path) }
207
+ when "users"
208
+ dirs = paths.map { |path| UsersDir.new(name, self, path) }
185
209
  else
186
- data_handler = case name
187
- when "clients"
188
- Chef::ChefFS::DataHandler::ClientDataHandler.new
189
- when "environments"
190
- Chef::ChefFS::DataHandler::EnvironmentDataHandler.new
191
- when "nodes"
192
- Chef::ChefFS::DataHandler::NodeDataHandler.new
193
- when "policy_groups"
194
- Chef::ChefFS::DataHandler::PolicyGroupDataHandler.new
195
- when "roles"
196
- Chef::ChefFS::DataHandler::RoleDataHandler.new
197
- when "users"
198
- Chef::ChefFS::DataHandler::UserDataHandler.new
199
- when "groups"
200
- Chef::ChefFS::DataHandler::GroupDataHandler.new
201
- when "containers"
202
- Chef::ChefFS::DataHandler::ContainerDataHandler.new
203
- else
204
- raise "Unknown top level path #{name}"
205
- end
206
- dirs = paths.map { |path| ChefRepositoryFileSystemEntry.new(name, self, path, data_handler) }
210
+ raise "Unknown top level path #{name}"
207
211
  end
208
212
  MultiplexedDir.new(dirs)
209
213
  end
@@ -0,0 +1,38 @@
1
+ #
2
+ # Author:: Thom May (<thom@chef.io>)
3
+ # Copyright:: Copyright 2013-2016, Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require "chef/chef_fs/data_handler/client_data_handler"
20
+ require "chef/chef_fs/file_system/repository/base_file"
21
+
22
+ class Chef
23
+ module ChefFS
24
+ module FileSystem
25
+ module Repository
26
+
27
+ class Client < BaseFile
28
+
29
+ def initialize(name, parent)
30
+ @data_handler = Chef::ChefFS::DataHandler::ClientDataHandler.new
31
+ super
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ #
2
+ # Author:: Thom May (<thom@chef.io>)
3
+ # Copyright:: Copyright 2013-2016, Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require "chef/chef_fs/data_handler/client_key_data_handler"
20
+ require "chef/chef_fs/file_system/repository/base_file"
21
+
22
+ class Chef
23
+ module ChefFS
24
+ module FileSystem
25
+ module Repository
26
+
27
+ class ClientKey < BaseFile
28
+
29
+ def initialize(name, parent)
30
+ @data_handler = Chef::ChefFS::DataHandler::ClientKeyDataHandler.new
31
+ super
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -16,21 +16,25 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "chef/chef_fs/file_system/repository/chef_repository_file_system_entry"
19
+ require "chef/chef_fs/file_system/repository/client_keys_sub_dir"
20
20
  require "chef/chef_fs/data_handler/client_key_data_handler"
21
+ require "chef/chef_fs/file_system/repository/directory"
21
22
 
22
23
  class Chef
23
24
  module ChefFS
24
25
  module FileSystem
25
26
  module Repository
26
- class ChefRepositoryFileSystemClientKeysDir < ChefRepositoryFileSystemEntry
27
- def initialize(name, parent, path = nil)
28
- super(name, parent, path, Chef::ChefFS::DataHandler::ClientKeyDataHandler.new)
29
- end
27
+ class ClientKeysDir < Repository::Directory
30
28
 
31
29
  def can_have_child?(name, is_dir)
32
30
  is_dir && !name.start_with?(".")
33
31
  end
32
+
33
+ protected
34
+
35
+ def make_child_entry(child_name)
36
+ ClientKeysSubDir.new(child_name, self)
37
+ end
34
38
  end
35
39
  end
36
40
  end
@@ -0,0 +1,42 @@
1
+ #
2
+ # Author:: Jordan Running (<jr@chef.io>)
3
+ # Copyright:: Copyright 2013-2016, Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require "chef/chef_fs/file_system/repository/client_key"
20
+ require "chef/chef_fs/data_handler/client_key_data_handler"
21
+ require "chef/chef_fs/file_system/repository/directory"
22
+
23
+ class Chef
24
+ module ChefFS
25
+ module FileSystem
26
+ module Repository
27
+ class ClientKeysSubDir < Repository::Directory
28
+
29
+ def can_have_child?(name, is_dir)
30
+ !is_dir && File.extname(name) == ".json"
31
+ end
32
+
33
+ protected
34
+
35
+ def make_child_entry(child_name)
36
+ ClientKey.new(child_name, self)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,40 @@
1
+ #
2
+ # Author:: John Keiser (<jkeiser@chef.io>)
3
+ # Author:: Ho-Sheng Hsiao (<hosh@chef.io>)
4
+ # Copyright:: Copyright 2012-2016, Chef Software Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require "chef/chef_fs/file_system/repository/client"
21
+ require "chef/chef_fs/file_system/repository/directory"
22
+ require "chef/chef_fs/file_system/exceptions"
23
+
24
+ class Chef
25
+ module ChefFS
26
+ module FileSystem
27
+ module Repository
28
+ class ClientsDir < Repository::Directory
29
+ def can_have_child?(name, is_dir)
30
+ !is_dir && File.extname(name) == ".json"
31
+ end
32
+
33
+ def make_child_entry(child_name)
34
+ Client.new(child_name, self)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,38 @@
1
+ #
2
+ # Author:: Thom May (<thom@chef.io>)
3
+ # Copyright:: Copyright 2013-2016, Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require "chef/chef_fs/data_handler/container_data_handler"
20
+ require "chef/chef_fs/file_system/repository/base_file"
21
+
22
+ class Chef
23
+ module ChefFS
24
+ module FileSystem
25
+ module Repository
26
+
27
+ class Container < BaseFile
28
+
29
+ def initialize(name, parent)
30
+ @data_handler = Chef::ChefFS::DataHandler::ContainerDataHandler.new
31
+ super
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,41 @@
1
+ #
2
+ # Author:: John Keiser (<jkeiser@chef.io>)
3
+ # Author:: Ho-Sheng Hsiao (<hosh@chef.io>)
4
+ # Copyright:: Copyright 2012-2016, Chef Software Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require "chef/chef_fs/file_system/repository/container"
21
+ require "chef/chef_fs/file_system/repository/directory"
22
+ require "chef/chef_fs/file_system/exceptions"
23
+
24
+ class Chef
25
+ module ChefFS
26
+ module FileSystem
27
+ module Repository
28
+ class ContainersDir < Repository::Directory
29
+
30
+ def can_have_child?(name, is_dir)
31
+ !is_dir && File.extname(name) == ".json"
32
+ end
33
+
34
+ def make_child_entry(child_name)
35
+ Container.new(child_name, self)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -17,7 +17,6 @@
17
17
  #
18
18
 
19
19
  require "chef/chef_fs/file_system/repository/directory"
20
- require "chef/chef_fs/file_system/repository/chef_repository_file_system_entry"
21
20
  require "chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir"
22
21
  require "chef/cookbook/chefignore"
23
22
 
@@ -17,97 +17,21 @@
17
17
  #
18
18
 
19
19
  require "chef/chef_fs/data_handler/data_bag_item_data_handler"
20
+ require "chef/chef_fs/file_system/repository/base_file"
20
21
 
21
22
  class Chef
22
23
  module ChefFS
23
24
  module FileSystem
24
25
  module Repository
25
26
 
26
- class DataBagItem
27
-
28
- attr_reader :name
29
- attr_reader :parent
30
- attr_reader :path
31
- attr_reader :file_path
27
+ class DataBagItem < BaseFile
32
28
 
33
29
  def initialize(name, parent)
34
- @parent = parent
35
- @name = name
36
- @path = Chef::ChefFS::PathUtils.join(parent.path, name)
37
30
  @data_handler = Chef::ChefFS::DataHandler::DataBagItemDataHandler.new
38
- @file_path = "#{parent.file_path}/#{name}"
39
- end
40
-
41
- # Public API callied by chef_fs/file_system
42
- def dir?
43
- false
44
- end
45
-
46
- def name_valid?
47
- !name.start_with?(".") && name.end_with?(".json")
48
- end
49
-
50
- def fs_entry_valid?
51
- name_valid? && File.file?(file_path)
52
- end
53
-
54
- def create(file_contents)
55
- if exists?
56
- raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, self)
57
- else
58
- write(file_contents)
59
- end
60
- end
61
-
62
- def can_have_child?(name, is_dir)
63
- false
64
- end
65
-
66
- def write_pretty_json=(value)
67
- @write_pretty_json = value
68
- end
69
-
70
- def write_pretty_json
71
- @write_pretty_json.nil? ? root.write_pretty_json : @write_pretty_json
31
+ super
72
32
  end
73
33
 
74
- def path_for_printing
75
- file_path
76
- end
77
-
78
- def delete(recurse)
79
- File.delete(file_path)
80
- rescue Errno::ENOENT
81
- raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
82
- end
83
-
84
- def exists?
85
- File.exists?(file_path)
86
- end
87
-
88
- def read
89
- begin
90
- File.open(file_path, "rb") { |f| f.read }
91
- rescue Errno::ENOENT
92
- raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
93
- end
94
- end
95
-
96
- def write(content)
97
- File.open(file_path, "wb") do |file|
98
- file.write(content)
99
- end
100
- end
101
-
102
- def root
103
- parent.root
104
- end
105
-
106
- def compare_to(other)
107
- nil
108
- end
109
34
  end
110
-
111
35
  end
112
36
  end
113
37
  end