chef 11.18.12-x86-mingw32 → 12.0.0.alpha.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (307) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +10 -0
  3. data/README.md +1 -1
  4. data/distro/common/html/_sources/index.txt +5 -2
  5. data/distro/common/html/_sources/knife_serve.txt +19 -0
  6. data/distro/common/html/_sources/knife_ssl_check.txt +2 -2
  7. data/distro/common/html/_sources/knife_ssl_fetch.txt +2 -2
  8. data/distro/common/html/_static/basic.css +1 -1
  9. data/distro/common/html/_static/doctools.js +1 -1
  10. data/distro/common/html/_static/searchtools.js +1 -1
  11. data/distro/common/html/_static/websupport.js +1 -1
  12. data/distro/common/html/ctl_chef_client.html +19 -9
  13. data/distro/common/html/ctl_chef_server.html +7 -1
  14. data/distro/common/html/ctl_chef_shell.html +3 -4
  15. data/distro/common/html/ctl_chef_solo.html +12 -7
  16. data/distro/common/html/index.html +19 -12
  17. data/distro/common/html/knife.html +1 -2
  18. data/distro/common/html/knife_bootstrap.html +16 -5
  19. data/distro/common/html/knife_client.html +8 -5
  20. data/distro/common/html/knife_common_options.html +11 -12
  21. data/distro/common/html/knife_configure.html +2 -3
  22. data/distro/common/html/knife_cookbook.html +16 -17
  23. data/distro/common/html/knife_cookbook_site.html +19 -18
  24. data/distro/common/html/knife_data_bag.html +6 -7
  25. data/distro/common/html/knife_delete.html +2 -3
  26. data/distro/common/html/knife_deps.html +2 -3
  27. data/distro/common/html/knife_diff.html +3 -4
  28. data/distro/common/html/knife_download.html +6 -7
  29. data/distro/common/html/knife_edit.html +0 -1
  30. data/distro/common/html/knife_environment.html +3 -4
  31. data/distro/common/html/knife_exec.html +0 -1
  32. data/distro/common/html/knife_index_rebuild.html +0 -1
  33. data/distro/common/html/knife_list.html +5 -6
  34. data/distro/common/html/knife_node.html +13 -6
  35. data/distro/common/html/knife_raw.html +0 -1
  36. data/distro/common/html/knife_recipe_list.html +0 -1
  37. data/distro/common/html/knife_role.html +1 -2
  38. data/distro/common/html/knife_search.html +2 -3
  39. data/distro/common/html/knife_serve.html +79 -0
  40. data/distro/common/html/knife_show.html +1 -2
  41. data/distro/common/html/knife_ssh.html +2 -3
  42. data/distro/common/html/knife_ssl_check.html +12 -9
  43. data/distro/common/html/knife_ssl_fetch.html +9 -10
  44. data/distro/common/html/knife_status.html +2 -3
  45. data/distro/common/html/knife_tag.html +0 -1
  46. data/distro/common/html/knife_upload.html +3 -4
  47. data/distro/common/html/knife_user.html +2 -3
  48. data/distro/common/html/knife_using.html +0 -1
  49. data/distro/common/html/knife_xargs.html +3 -4
  50. data/distro/common/html/search.html +0 -1
  51. data/distro/common/html/searchindex.js +1 -1
  52. data/lib/chef/api_client.rb +1 -1
  53. data/lib/chef/application.rb +24 -67
  54. data/lib/chef/application/client.rb +1 -1
  55. data/lib/chef/application/knife.rb +1 -1
  56. data/lib/chef/chef_fs/chef_fs_data_store.rb +2 -3
  57. data/lib/chef/chef_fs/command_line.rb +2 -3
  58. data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -5
  59. data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -2
  60. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -2
  61. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +2 -2
  62. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +2 -3
  63. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +4 -5
  64. data/lib/chef/config.rb +26 -2
  65. data/lib/chef/config_fetcher.rb +1 -1
  66. data/lib/chef/cookbook/cookbook_version_loader.rb +4 -4
  67. data/lib/chef/cookbook/metadata.rb +1 -1
  68. data/lib/chef/cookbook/synchronizer.rb +50 -8
  69. data/lib/chef/cookbook_uploader.rb +9 -23
  70. data/lib/chef/cookbook_version.rb +3 -2
  71. data/lib/chef/data_bag.rb +1 -1
  72. data/lib/chef/data_bag_item.rb +1 -1
  73. data/lib/chef/dsl/recipe.rb +1 -14
  74. data/lib/chef/encrypted_data_bag_item/decryptor.rb +3 -3
  75. data/lib/chef/environment.rb +1 -1
  76. data/lib/chef/exceptions.rb +2 -24
  77. data/lib/chef/file_content_management/tempfile.rb +8 -1
  78. data/lib/chef/formatters/base.rb +0 -7
  79. data/lib/chef/http.rb +12 -19
  80. data/lib/chef/http/json_input.rb +12 -1
  81. data/lib/chef/json_compat.rb +45 -64
  82. data/lib/chef/knife.rb +2 -5
  83. data/lib/chef/knife/bootstrap.rb +2 -2
  84. data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -2
  85. data/lib/chef/knife/bootstrap/centos5-gems.erb +2 -2
  86. data/lib/chef/knife/bootstrap/chef-aix.erb +2 -2
  87. data/lib/chef/knife/bootstrap/chef-full.erb +2 -2
  88. data/lib/chef/knife/bootstrap/fedora13-gems.erb +2 -2
  89. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +2 -2
  90. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +2 -2
  91. data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +2 -2
  92. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  93. data/lib/chef/knife/cookbook_site_install.rb +10 -34
  94. data/lib/chef/knife/cookbook_site_list.rb +1 -1
  95. data/lib/chef/knife/cookbook_site_search.rb +1 -1
  96. data/lib/chef/knife/cookbook_site_share.rb +3 -3
  97. data/lib/chef/knife/cookbook_site_show.rb +3 -3
  98. data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
  99. data/lib/chef/knife/cookbook_upload.rb +1 -1
  100. data/lib/chef/knife/core/subcommand_loader.rb +0 -24
  101. data/lib/chef/knife/core/ui.rb +8 -7
  102. data/lib/chef/knife/deps.rb +2 -3
  103. data/lib/chef/knife/serve.rb +2 -1
  104. data/lib/chef/local_mode.rb +105 -0
  105. data/lib/chef/mixin/file_class.rb +1 -4
  106. data/lib/chef/mixin/shell_out.rb +15 -0
  107. data/lib/chef/mixin/windows_architecture_helper.rb +0 -16
  108. data/lib/chef/node.rb +1 -1
  109. data/lib/chef/platform/query_helpers.rb +1 -5
  110. data/lib/chef/policy_builder/expand_node_object.rb +3 -0
  111. data/lib/chef/provider.rb +2 -0
  112. data/lib/chef/provider/cookbook_file.rb +0 -1
  113. data/lib/chef/provider/deploy.rb +0 -1
  114. data/lib/chef/provider/deploy/revision.rb +1 -1
  115. data/lib/chef/provider/env.rb +10 -25
  116. data/lib/chef/provider/env/windows.rb +23 -10
  117. data/lib/chef/provider/execute.rb +0 -3
  118. data/lib/chef/provider/file.rb +0 -3
  119. data/lib/chef/provider/git.rb +0 -6
  120. data/lib/chef/provider/group/dscl.rb +9 -27
  121. data/lib/chef/provider/group/gpasswd.rb +0 -3
  122. data/lib/chef/provider/group/groupmod.rb +0 -4
  123. data/lib/chef/provider/group/suse.rb +0 -3
  124. data/lib/chef/provider/group/usermod.rb +0 -3
  125. data/lib/chef/provider/link.rb +22 -5
  126. data/lib/chef/provider/log.rb +15 -4
  127. data/lib/chef/provider/mdadm.rb +0 -3
  128. data/lib/chef/provider/mount/mount.rb +0 -2
  129. data/lib/chef/provider/mount/solaris.rb +0 -2
  130. data/lib/chef/provider/package.rb +0 -1
  131. data/lib/chef/provider/package/apt.rb +0 -3
  132. data/lib/chef/provider/package/dpkg.rb +0 -1
  133. data/lib/chef/provider/package/easy_install.rb +0 -4
  134. data/lib/chef/provider/package/freebsd/base.rb +0 -3
  135. data/lib/chef/provider/package/freebsd/pkgng.rb +0 -2
  136. data/lib/chef/provider/package/freebsd/port.rb +0 -2
  137. data/lib/chef/provider/package/ips.rb +0 -3
  138. data/lib/chef/provider/package/paludis.rb +0 -5
  139. data/lib/chef/provider/package/portage.rb +0 -2
  140. data/lib/chef/provider/package/rpm.rb +2 -4
  141. data/lib/chef/provider/package/rubygems.rb +0 -4
  142. data/lib/chef/provider/package/smartos.rb +0 -3
  143. data/lib/chef/provider/package/windows/msi.rb +0 -2
  144. data/lib/chef/provider/package/yum.rb +0 -4
  145. data/lib/chef/provider/package/zypper.rb +0 -3
  146. data/lib/chef/provider/registry_key.rb +0 -2
  147. data/lib/chef/provider/remote_directory.rb +0 -1
  148. data/lib/chef/provider/remote_file.rb +0 -1
  149. data/lib/chef/provider/remote_file/cache_control_data.rb +1 -3
  150. data/lib/chef/provider/remote_file/content.rb +0 -1
  151. data/lib/chef/provider/remote_file/fetcher.rb +0 -2
  152. data/lib/chef/provider/remote_file/ftp.rb +0 -1
  153. data/lib/chef/provider/resource_update.rb +0 -3
  154. data/lib/chef/provider/service/freebsd.rb +0 -3
  155. data/lib/chef/provider/service/init.rb +0 -3
  156. data/lib/chef/provider/service/macosx.rb +0 -1
  157. data/lib/chef/provider/service/redhat.rb +0 -2
  158. data/lib/chef/provider/service/simple.rb +0 -3
  159. data/lib/chef/provider/service/solaris.rb +0 -3
  160. data/lib/chef/provider/service/systemd.rb +15 -14
  161. data/lib/chef/provider/service/windows.rb +0 -3
  162. data/lib/chef/provider/subversion.rb +0 -2
  163. data/lib/chef/provider/template.rb +0 -2
  164. data/lib/chef/provider/template/content.rb +0 -1
  165. data/lib/chef/provider/user/dscl.rb +156 -549
  166. data/lib/chef/provider/user/solaris.rb +0 -1
  167. data/lib/chef/provider/user/useradd.rb +0 -3
  168. data/lib/chef/provider/whyrun_safe_ruby_block.rb +1 -1
  169. data/lib/chef/providers.rb +0 -1
  170. data/lib/chef/resource.rb +1 -4
  171. data/lib/chef/resource/freebsd_package.rb +2 -10
  172. data/lib/chef/resource/lwrp_base.rb +1 -12
  173. data/lib/chef/resource/user.rb +0 -18
  174. data/lib/chef/resource_collection.rb +1 -1
  175. data/lib/chef/resource_reporter.rb +10 -10
  176. data/lib/chef/resources.rb +0 -1
  177. data/lib/chef/role.rb +3 -3
  178. data/lib/chef/run_list.rb +1 -1
  179. data/lib/chef/tasks/chef_repo.rake +131 -264
  180. data/lib/chef/user.rb +1 -1
  181. data/lib/chef/util/path_helper.rb +2 -2
  182. data/lib/chef/version.rb +9 -1
  183. data/lib/chef/win32/api/system.rb +0 -9
  184. data/spec/data/bootstrap/test-hints.erb +1 -1
  185. data/spec/data/bootstrap/test.erb +1 -1
  186. data/spec/functional/dsl/reboot_pending_spec.rb +53 -58
  187. data/spec/functional/knife/cookbook_delete_spec.rb +3 -3
  188. data/spec/functional/knife/exec_spec.rb +1 -1
  189. data/spec/functional/mixin/shell_out_spec.rb +48 -0
  190. data/spec/functional/resource/base.rb +0 -10
  191. data/spec/functional/resource/group_spec.rb +1 -5
  192. data/spec/functional/resource/link_spec.rb +8 -0
  193. data/spec/functional/resource/{user/useradd_spec.rb → user_spec.rb} +1 -1
  194. data/spec/integration/knife/chef_fs_data_store_spec.rb +3 -3
  195. data/spec/integration/knife/chef_repo_path_spec.rb +1 -6
  196. data/spec/integration/knife/chef_repository_file_system_spec.rb +1 -1
  197. data/spec/integration/knife/chefignore_spec.rb +1 -1
  198. data/spec/integration/knife/common_options_spec.rb +50 -3
  199. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +1 -1
  200. data/spec/integration/knife/delete_spec.rb +1 -1
  201. data/spec/integration/knife/deps_spec.rb +1 -1
  202. data/spec/integration/knife/diff_spec.rb +3 -3
  203. data/spec/integration/knife/download_spec.rb +3 -3
  204. data/spec/integration/knife/list_spec.rb +1 -1
  205. data/spec/integration/knife/raw_spec.rb +1 -11
  206. data/spec/integration/knife/redirection_spec.rb +1 -1
  207. data/spec/integration/knife/serve_spec.rb +2 -2
  208. data/spec/integration/knife/show_spec.rb +1 -1
  209. data/spec/integration/knife/upload_spec.rb +9 -9
  210. data/spec/spec_helper.rb +0 -9
  211. data/spec/support/pedant/pedant_config.rb +2 -1
  212. data/spec/support/pedant/run_pedant.rb +2 -1
  213. data/spec/support/platform_helpers.rb +5 -24
  214. data/spec/support/shared/integration/integration_helper.rb +2 -1
  215. data/spec/support/shared/matchers.rb +17 -0
  216. data/spec/tiny_server.rb +1 -2
  217. data/spec/unit/api_client_spec.rb +3 -3
  218. data/spec/unit/application_spec.rb +9 -32
  219. data/spec/unit/config_fetcher_spec.rb +1 -1
  220. data/spec/unit/cookbook/metadata_spec.rb +3 -7
  221. data/spec/unit/cookbook/synchronizer_spec.rb +441 -226
  222. data/spec/unit/cookbook_loader_spec.rb +1 -1
  223. data/spec/unit/cookbook_uploader_spec.rb +160 -0
  224. data/spec/unit/cookbook_version_spec.rb +0 -4
  225. data/spec/unit/data_bag_item_spec.rb +1 -5
  226. data/spec/unit/data_bag_spec.rb +1 -5
  227. data/spec/unit/deprecation_spec.rb +1 -1
  228. data/spec/unit/dsl/recipe_spec.rb +12 -0
  229. data/spec/unit/encrypted_data_bag_item_spec.rb +7 -14
  230. data/spec/unit/environment_spec.rb +3 -7
  231. data/spec/unit/exceptions_spec.rb +0 -6
  232. data/spec/unit/http/json_input_spec.rb +128 -0
  233. data/spec/unit/json_compat_spec.rb +17 -58
  234. data/spec/unit/knife/client_create_spec.rb +3 -3
  235. data/spec/unit/knife/configure_client_spec.rb +6 -5
  236. data/spec/unit/knife/cookbook_delete_spec.rb +1 -1
  237. data/spec/unit/knife/cookbook_download_spec.rb +5 -5
  238. data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +1 -0
  239. data/spec/unit/knife/cookbook_metadata_spec.rb +1 -1
  240. data/spec/unit/knife/cookbook_site_download_spec.rb +10 -11
  241. data/spec/unit/knife/cookbook_site_install_spec.rb +116 -161
  242. data/spec/unit/knife/cookbook_site_share_spec.rb +8 -8
  243. data/spec/unit/knife/cookbook_upload_spec.rb +3 -2
  244. data/spec/unit/knife/core/bootstrap_context_spec.rb +3 -3
  245. data/spec/unit/knife/core/subcommand_loader_spec.rb +1 -66
  246. data/spec/unit/knife/data_bag_from_file_spec.rb +2 -1
  247. data/spec/unit/knife/tag_create_spec.rb +3 -3
  248. data/spec/unit/knife/tag_delete_spec.rb +3 -3
  249. data/spec/unit/knife/user_create_spec.rb +1 -1
  250. data/spec/unit/knife_spec.rb +14 -14
  251. data/spec/unit/lwrp_spec.rb +1 -21
  252. data/spec/unit/mixin/shell_out_spec.rb +92 -0
  253. data/spec/unit/node_spec.rb +0 -4
  254. data/spec/unit/platform/query_helpers_spec.rb +0 -23
  255. data/spec/unit/provider/env/windows_spec.rb +34 -70
  256. data/spec/unit/provider/env_spec.rb +11 -76
  257. data/spec/unit/provider/group/dscl_spec.rb +1 -38
  258. data/spec/unit/provider/log_spec.rb +18 -0
  259. data/spec/unit/provider/package/rpm_spec.rb +0 -12
  260. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +1 -1
  261. data/spec/unit/provider/service/systemd_service_spec.rb +44 -27
  262. data/spec/unit/provider/user/dscl_spec.rb +264 -660
  263. data/spec/unit/provider/user/useradd_spec.rb +0 -1
  264. data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +2 -2
  265. data/spec/unit/provider_spec.rb +12 -0
  266. data/spec/unit/recipe_spec.rb +0 -41
  267. data/spec/unit/resource_collection_spec.rb +1 -5
  268. data/spec/unit/resource_reporter_spec.rb +3 -51
  269. data/spec/unit/resource_spec.rb +3 -14
  270. data/spec/unit/rest_spec.rb +1 -4
  271. data/spec/unit/role_spec.rb +0 -10
  272. data/spec/unit/run_list_spec.rb +1 -5
  273. data/spec/unit/user_spec.rb +1 -5
  274. metadata +20 -100
  275. data/lib/chef/mixin/windows_env_helper.rb +0 -56
  276. data/lib/chef/provider/dsc_script.rb +0 -175
  277. data/lib/chef/resource/dsc_script.rb +0 -126
  278. data/lib/chef/streaming_cookbook_uploader.rb +0 -205
  279. data/lib/chef/util/dsc/configuration_generator.rb +0 -115
  280. data/lib/chef/util/dsc/lcm_output_parser.rb +0 -133
  281. data/lib/chef/util/dsc/local_configuration_manager.rb +0 -141
  282. data/lib/chef/util/dsc/resource_info.rb +0 -26
  283. data/lib/chef/util/powershell/cmdlet.rb +0 -136
  284. data/lib/chef/util/powershell/cmdlet_result.rb +0 -46
  285. data/spec/data/mac_users/10.7-8.plist.xml +0 -559
  286. data/spec/data/mac_users/10.7-8.shadow.xml +0 -11
  287. data/spec/data/mac_users/10.7.plist.xml +0 -559
  288. data/spec/data/mac_users/10.7.shadow.xml +0 -11
  289. data/spec/data/mac_users/10.8.plist.xml +0 -559
  290. data/spec/data/mac_users/10.8.shadow.xml +0 -21
  291. data/spec/data/mac_users/10.9.plist.xml +0 -560
  292. data/spec/data/mac_users/10.9.shadow.xml +0 -21
  293. data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +0 -51
  294. data/spec/functional/resource/dsc_script_spec.rb +0 -382
  295. data/spec/functional/resource/env_spec.rb +0 -182
  296. data/spec/functional/resource/user/dscl_spec.rb +0 -199
  297. data/spec/functional/util/powershell/cmdlet_spec.rb +0 -113
  298. data/spec/support/lib/chef/resource/zen_follower.rb +0 -46
  299. data/spec/support/shared/shared_examples.rb +0 -10
  300. data/spec/unit/chef_fs/data_handler/group_handler_spec.rb +0 -63
  301. data/spec/unit/formatters/base_spec.rb +0 -48
  302. data/spec/unit/provider/dsc_script_spec.rb +0 -174
  303. data/spec/unit/resource/dsc_script_spec.rb +0 -98
  304. data/spec/unit/util/dsc/configuration_generator_spec.rb +0 -171
  305. data/spec/unit/util/dsc/lcm_output_parser_spec.rb +0 -169
  306. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +0 -139
  307. data/spec/unit/util/powershell/cmdlet_spec.rb +0 -106
@@ -17,10 +17,10 @@
17
17
  #
18
18
 
19
19
  require 'yaml'
20
+ require 'ffi_yajl'
20
21
  require 'openssl'
21
22
  require 'base64'
22
23
  require 'digest/sha2'
23
- require 'chef/json_compat'
24
24
  require 'chef/encrypted_data_bag_item'
25
25
  require 'chef/encrypted_data_bag_item/unsupported_encrypted_data_bag_item_format'
26
26
  require 'chef/encrypted_data_bag_item/unacceptable_encrypted_data_bag_item_format'
@@ -121,8 +121,8 @@ class Chef::EncryptedDataBagItem
121
121
  end
122
122
 
123
123
  def for_decrypted_item
124
- Chef::JSONCompat.parse(decrypted_data)["json_wrapper"]
125
- rescue Chef::Exceptions::JSON::ParseError
124
+ FFI_Yajl::Parser.parse(decrypted_data)["json_wrapper"]
125
+ rescue FFI_Yajl::ParseError
126
126
  # convert to a DecryptionFailure error because the most likely scenario
127
127
  # here is that the decryption step was unsuccessful but returned bad
128
128
  # data rather than raising an error.
@@ -129,7 +129,7 @@ class Chef
129
129
  end
130
130
 
131
131
  def to_json(*a)
132
- Chef::JSONCompat.to_json(to_hash, *a)
132
+ to_hash.to_json(*a)
133
133
  end
134
134
 
135
135
  def update_from!(o)
@@ -83,7 +83,6 @@ class Chef
83
83
  class RequestedUIDUnavailable < RuntimeError; end
84
84
  class InvalidHomeDirectory < ArgumentError; end
85
85
  class DsclCommandFailed < RuntimeError; end
86
- class PlistUtilCommandFailed < RuntimeError; end
87
86
  class UserIDNotFound < ArgumentError; end
88
87
  class GroupIDNotFound < ArgumentError; end
89
88
  class ConflictingMembersInGroup < ArgumentError; end
@@ -117,8 +116,6 @@ class Chef
117
116
  class ObsoleteDependencySyntax < ArgumentError; end
118
117
  class InvalidDataBagPath < ArgumentError; end
119
118
 
120
- class PowershellCmdletException < RuntimeError; end
121
-
122
119
  # A different version of a cookbook was added to a
123
120
  # VersionedRecipeList than the one already there.
124
121
  class CookbookVersionConflict < ArgumentError ; end
@@ -134,17 +131,6 @@ class Chef
134
131
  # Version constraints are not allowed in chef-solo
135
132
  class IllegalVersionConstraint < NotImplementedError; end
136
133
 
137
- class MetadataNotValid < StandardError; end
138
- class MetadataNotFound < StandardError
139
- attr_reader :install_path
140
- attr_reader :cookbook_name
141
- def initialize(install_path, cookbook_name)
142
- @install_path = install_path
143
- @cookbook_name = cookbook_name
144
- super "No metadata.rb or metadata.json found for cookbook #{@cookbook_name} in #{@install_path}"
145
- end
146
- end
147
-
148
134
  # File operation attempted but no permissions to perform it
149
135
  class InsufficientPermissions < RuntimeError; end
150
136
 
@@ -189,8 +175,6 @@ class Chef
189
175
 
190
176
  class ChildConvergeError < RuntimeError; end
191
177
 
192
- class NoProviderAvailable < RuntimeError; end
193
-
194
178
  class MissingRole < RuntimeError
195
179
  NULL = Object.new
196
180
 
@@ -278,7 +262,7 @@ class Chef
278
262
  "non_existent_cookbooks" => non_existent_cookbooks,
279
263
  "cookbooks_with_no_versions" => cookbooks_with_no_matching_versions
280
264
  }
281
- Chef::JSONCompat.to_json(result, *a)
265
+ result.to_json(*a)
282
266
  end
283
267
  end
284
268
 
@@ -313,7 +297,7 @@ class Chef
313
297
  "non_existent_cookbooks" => non_existent_cookbooks,
314
298
  "most_constrained_cookbooks" => most_constrained_cookbooks
315
299
  }
316
- Chef::JSONCompat.to_json(result, *a)
300
+ result.to_json(*a)
317
301
  end
318
302
  end
319
303
 
@@ -348,11 +332,5 @@ class Chef
348
332
  end
349
333
 
350
334
  class BadProxyURI < RuntimeError; end
351
-
352
- # Raised by Chef::JSONCompat
353
- class JSON
354
- class EncodeError < RuntimeError; end
355
- class ParseError < RuntimeError; end
356
- end
357
335
  end
358
336
  end
@@ -54,7 +54,14 @@ class Chef
54
54
  end
55
55
 
56
56
  def tempfile_dirname
57
- Chef::Config[:file_staging_uses_destdir] ? ::File.dirname(@new_resource.path) : Dir::tmpdir
57
+ # in why-run mode we need to create a Tempfile to compare against, which we will never
58
+ # wind up deploying, but our enclosing directory for the destdir may not exist yet, so
59
+ # instead we can reliably always create a Tempfile to compare against in Dir::tmpdir
60
+ if Chef::Config[:file_staging_uses_destdir] && !Chef::Config[:why_run]
61
+ ::File.dirname(@new_resource.path)
62
+ else
63
+ Dir::tmpdir
64
+ end
58
65
  end
59
66
  end
60
67
  end
@@ -93,13 +93,6 @@ class Chef
93
93
 
94
94
  def indent_by(amount)
95
95
  @output.indent += amount
96
- if @output.indent < 0
97
- # This is left commented out for now. We need to uncomment it and fix at least one bug in
98
- # the formatter, and then leave this line uncommented in the future.
99
- #Chef::Log.warn "Internal Formatter Error -- Attempt to indent by negative number of spaces"
100
- @output.indent = 0
101
- end
102
- @output.indent
103
96
  end
104
97
 
105
98
  # Input: a Formatters::ErrorDescription object.
@@ -289,26 +289,11 @@ class Chef
289
289
  def retrying_http_errors(url)
290
290
  http_attempts = 0
291
291
  begin
292
- loop do
293
- http_attempts += 1
294
- response, request, return_value = yield
295
- # handle HTTP 50X Error
296
- if response.kind_of?(Net::HTTPServerError)
297
- if http_retry_count - http_attempts + 1 > 0
298
- sleep_time = 1 + (2 ** http_attempts) + rand(2 ** http_attempts)
299
- Chef::Log.error("Server returned error #{response.code} for #{url}, retrying #{http_attempts}/#{http_retry_count} in #{sleep_time}s")
300
- sleep(sleep_time)
301
- redo
302
- end
303
- end
304
- return [response, request, return_value]
305
- end
292
+ http_attempts += 1
293
+
294
+ yield
295
+
306
296
  rescue SocketError, Errno::ETIMEDOUT => e
307
- if http_retry_count - http_attempts + 1 > 0
308
- Chef::Log.error("Error connecting to #{url}, retry #{http_attempts}/#{http_retry_count}")
309
- sleep(http_retry_delay)
310
- retry
311
- end
312
297
  e.message.replace "Error connecting to #{url} - #{e.message}"
313
298
  raise e
314
299
  rescue Errno::ECONNREFUSED
@@ -325,6 +310,14 @@ class Chef
325
310
  retry
326
311
  end
327
312
  raise Timeout::Error, "Timeout connecting to #{url}, giving up"
313
+ rescue Net::HTTPFatalError => e
314
+ if http_retry_count - http_attempts + 1 > 0
315
+ sleep_time = 1 + (2 ** http_attempts) + rand(2 ** http_attempts)
316
+ Chef::Log.error("Server returned error for #{url}, retrying #{http_attempts}/#{http_retry_count} in #{sleep_time}s")
317
+ sleep(sleep_time)
318
+ retry
319
+ end
320
+ raise
328
321
  end
329
322
  end
330
323
 
@@ -29,7 +29,8 @@ class Chef
29
29
  end
30
30
 
31
31
  def handle_request(method, url, headers={}, data=false)
32
- if data
32
+ if data && should_encode_as_json?(headers)
33
+ headers.delete_if { |key, _value| key.downcase == 'content-type' }
33
34
  headers["Content-Type"] = 'application/json'
34
35
  data = Chef::JSONCompat.to_json(data)
35
36
  # Force encoding to binary to fix SSL related EOFErrors
@@ -52,6 +53,16 @@ class Chef
52
53
  [http_response, rest_request, return_value]
53
54
  end
54
55
 
56
+ private
57
+
58
+ def should_encode_as_json?(headers)
59
+ # ruby/Net::HTTP don't enforce capitalized headers (it normalizes them
60
+ # for you before sending the request), so we have to account for all
61
+ # the variations we might find
62
+ requested_content_type = headers.find {|k, v| k.downcase == "content-type" }
63
+ requested_content_type.nil? || requested_content_type.last.include?("json")
64
+ end
65
+
55
66
  end
56
67
  end
57
68
  end
@@ -18,9 +18,7 @@
18
18
  # Wrapper class for interacting with JSON.
19
19
 
20
20
  require 'ffi_yajl'
21
- require 'chef/exceptions'
22
- # We're requiring this to prevent breaking consumers using Hash.to_json
23
- require 'json'
21
+ require 'ffi_yajl/json_gem' # XXX: parts of chef require JSON gem's Hash#to_json monkeypatch
24
22
 
25
23
  class Chef
26
24
  class JSONCompat
@@ -42,24 +40,15 @@ class Chef
42
40
 
43
41
  class <<self
44
42
 
45
- # API to use to avoid create_addtions
46
- def parse(source, opts = {})
47
- begin
48
- FFI_Yajl::Parser.parse(source, opts)
49
- rescue FFI_Yajl::ParseError => e
50
- raise Chef::Exceptions::JSON::ParseError, e.message
51
- end
52
- end
53
-
54
43
  # Just call the JSON gem's parse method with a modified :max_nesting field
55
44
  def from_json(source, opts = {})
56
- obj = parse(source, opts)
45
+ obj = ::FFI_Yajl::Parser.parse(source)
57
46
 
58
47
  # JSON gem requires top level object to be a Hash or Array (otherwise
59
48
  # you get the "must contain two octets" error). Yajl doesn't impose the
60
49
  # same limitation. For compatibility, we re-impose this condition.
61
50
  unless obj.kind_of?(Hash) or obj.kind_of?(Array)
62
- raise Chef::Exceptions::JSON::ParseError, "Top level JSON object must be a Hash or Array. (actual: #{obj.class})"
51
+ raise JSON::ParserError, "Top level JSON object must be a Hash or Array. (actual: #{obj.class})"
63
52
  end
64
53
 
65
54
  # The old default in the json gem (which we are mimicing because we
@@ -77,17 +66,17 @@ class Chef
77
66
  # to an instance of Chef classes if desired.
78
67
  def map_to_rb_obj(json_obj)
79
68
  case json_obj
80
- when Hash
81
- mapped_hash = map_hash_to_rb_obj(json_obj)
82
- if json_obj.has_key?(JSON_CLASS) && (class_to_inflate = class_for_json_class(json_obj[JSON_CLASS]))
83
- class_to_inflate.json_create(mapped_hash)
84
- else
85
- mapped_hash
86
- end
87
- when Array
88
- json_obj.map {|e| map_to_rb_obj(e) }
69
+ when Hash
70
+ mapped_hash = map_hash_to_rb_obj(json_obj)
71
+ if json_obj.has_key?(JSON_CLASS) && (class_to_inflate = class_for_json_class(json_obj[JSON_CLASS]))
72
+ class_to_inflate.json_create(mapped_hash)
89
73
  else
90
- json_obj
74
+ mapped_hash
75
+ end
76
+ when Array
77
+ json_obj.map {|e| map_to_rb_obj(e) }
78
+ else
79
+ json_obj
91
80
  end
92
81
  end
93
82
 
@@ -99,60 +88,52 @@ class Chef
99
88
  end
100
89
 
101
90
  def to_json(obj, opts = nil)
102
- begin
103
- FFI_Yajl::Encoder.encode(obj, opts)
104
- rescue FFI_Yajl::EncodeError => e
105
- raise Chef::Exceptions::JSON::EncodeError, e.message
106
- end
91
+ obj.to_json(opts)
107
92
  end
108
93
 
109
94
  def to_json_pretty(obj, opts = nil)
110
- opts ||= {}
111
- options_map = {}
112
- options_map[:pretty] = true
113
- options_map[:indent] = opts[:indent] if opts.has_key?(:indent)
114
- to_json(obj, options_map).chomp
95
+ ::JSON.pretty_generate(obj, opts)
115
96
  end
116
97
 
98
+
117
99
  # Map +json_class+ to a Class object. We use a +case+ instead of a Hash
118
100
  # assigned to a constant because otherwise this file could not be loaded
119
101
  # until all the constants were defined, which means you'd have to load
120
102
  # the world to get json, which would make knife very slow.
121
103
  def class_for_json_class(json_class)
122
104
  case json_class
123
- when CHEF_APICLIENT
124
- Chef::ApiClient
125
- when CHEF_CHECKSUM
126
- Chef::Checksum
127
- when CHEF_COOKBOOKVERSION
128
- Chef::CookbookVersion
129
- when CHEF_DATABAG
130
- Chef::DataBag
131
- when CHEF_DATABAGITEM
132
- Chef::DataBagItem
133
- when CHEF_ENVIRONMENT
134
- Chef::Environment
135
- when CHEF_NODE
136
- Chef::Node
137
- when CHEF_ROLE
138
- Chef::Role
139
- when CHEF_SANDBOX
140
- # a falsey return here will disable object inflation/"create
141
- # additions" in the caller. In Chef 11 this is correct, we just have
142
- # a dummy Chef::Sandbox class for compat with Chef 10 servers.
143
- false
144
- when CHEF_RESOURCE
145
- Chef::Resource
146
- when CHEF_RESOURCECOLLECTION
147
- Chef::ResourceCollection
148
- when /^Chef::Resource/
149
- Chef::Resource.find_subclass_by_name(json_class)
150
- else
151
- raise Chef::Exceptions::JSON::ParseError, "Unsupported `json_class` type '#{json_class}'"
105
+ when CHEF_APICLIENT
106
+ Chef::ApiClient
107
+ when CHEF_CHECKSUM
108
+ Chef::Checksum
109
+ when CHEF_COOKBOOKVERSION
110
+ Chef::CookbookVersion
111
+ when CHEF_DATABAG
112
+ Chef::DataBag
113
+ when CHEF_DATABAGITEM
114
+ Chef::DataBagItem
115
+ when CHEF_ENVIRONMENT
116
+ Chef::Environment
117
+ when CHEF_NODE
118
+ Chef::Node
119
+ when CHEF_ROLE
120
+ Chef::Role
121
+ when CHEF_SANDBOX
122
+ # a falsey return here will disable object inflation/"create
123
+ # additions" in the caller. In Chef 11 this is correct, we just have
124
+ # a dummy Chef::Sandbox class for compat with Chef 10 servers.
125
+ false
126
+ when CHEF_RESOURCE
127
+ Chef::Resource
128
+ when CHEF_RESOURCECOLLECTION
129
+ Chef::ResourceCollection
130
+ when /^Chef::Resource/
131
+ Chef::Resource.find_subclass_by_name(json_class)
132
+ else
133
+ raise JSON::ParserError, "Unsupported `json_class` type '#{json_class}'"
152
134
  end
153
135
  end
154
136
 
155
137
  end
156
138
  end
157
139
  end
158
-
@@ -25,6 +25,7 @@ require 'chef/mixin/convert_to_class_name'
25
25
  require 'chef/mixin/path_sanity'
26
26
  require 'chef/knife/core/subcommand_loader'
27
27
  require 'chef/knife/core/ui'
28
+ require 'chef/local_mode'
28
29
  require 'chef/rest'
29
30
  require 'pp'
30
31
 
@@ -488,11 +489,8 @@ class Chef
488
489
  ui.error "You need to add a #run method to your knife command before you can use it"
489
490
  end
490
491
  enforce_path_sanity
491
- Chef::Application.setup_server_connectivity
492
- begin
492
+ Chef::LocalMode.with_server_connectivity do
493
493
  run
494
- ensure
495
- Chef::Application.destroy_server_connectivity
496
494
  end
497
495
  rescue Exception => e
498
496
  raise if raise_exception || Chef::Config[:verbosity] == 2
@@ -625,4 +623,3 @@ class Chef
625
623
 
626
624
  end
627
625
  end
628
-
@@ -126,7 +126,7 @@ class Chef
126
126
  :short => "-j JSON_ATTRIBS",
127
127
  :long => "--json-attributes",
128
128
  :description => "A JSON string to be added to the first run of chef-client",
129
- :proc => lambda { |o| Chef::JSONCompat.parse(o) },
129
+ :proc => lambda { |o| JSON.parse(o) },
130
130
  :default => {}
131
131
 
132
132
  option :host_key_verify,
@@ -141,7 +141,7 @@ class Chef
141
141
  :proc => Proc.new { |h|
142
142
  Chef::Config[:knife][:hints] ||= Hash.new
143
143
  name, path = h.split("=")
144
- Chef::Config[:knife][:hints][name] = path ? Chef::JSONCompat.parse(::File.read(path)) : Hash.new }
144
+ Chef::Config[:knife][:hints][name] = path ? JSON.parse(::File.read(path)) : Hash.new }
145
145
 
146
146
  option :secret,
147
147
  :short => "-s SECRET",
@@ -29,7 +29,7 @@ mkdir -p /etc/chef/ohai/hints
29
29
 
30
30
  <% @chef_config[:knife][:hints].each do |name, hash| -%>
31
31
  cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP'
32
- <%= Chef::JSONCompat.to_json(hash) %>
32
+ <%= hash.to_json %>
33
33
  EOP
34
34
  <% end -%>
35
35
  <% end -%>
@@ -56,7 +56,7 @@ https_proxy "<%= knife_config[:bootstrap_proxy] %>"
56
56
  EOP
57
57
 
58
58
  cat > /etc/chef/first-boot.json <<'EOP'
59
- <%= Chef::JSONCompat.to_json(first_boot) %>
59
+ <%= first_boot.to_json %>
60
60
  EOP
61
61
 
62
62
  <%= start_chef %>'
@@ -46,7 +46,7 @@ mkdir -p /etc/chef/ohai/hints
46
46
 
47
47
  <% @chef_config[:knife][:hints].each do |name, hash| -%>
48
48
  cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP'
49
- <%= Chef::JSONCompat.to_json(hash) %>
49
+ <%= hash.to_json %>
50
50
  EOP
51
51
  <% end -%>
52
52
  <% end -%>
@@ -56,7 +56,7 @@ cat > /etc/chef/client.rb <<'EOP'
56
56
  EOP
57
57
 
58
58
  cat > /etc/chef/first-boot.json <<'EOP'
59
- <%= Chef::JSONCompat.to_json(first_boot) %>
59
+ <%= first_boot.to_json %>
60
60
  EOP
61
61
 
62
62
  <%= start_chef %>'
@@ -42,7 +42,7 @@ mkdir -p /etc/chef/ohai/hints
42
42
 
43
43
  <% @chef_config[:knife][:hints].each do |name, hash| -%>
44
44
  cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP'
45
- <%= Chef::JSONCompat.to_json(hash) %>
45
+ <%= hash.to_json %>
46
46
  EOP
47
47
  <% end -%>
48
48
  <% end -%>
@@ -52,7 +52,7 @@ cat > /etc/chef/client.rb <<'EOP'
52
52
  EOP
53
53
 
54
54
  cat > /etc/chef/first-boot.json <<'EOP'
55
- <%= Chef::JSONCompat.to_json(first_boot) %>
55
+ <%= first_boot.to_json %>
56
56
  EOP
57
57
 
58
58
  <%= start_chef %>'