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
@@ -1,56 +0,0 @@
1
- #
2
- # Author:: Adam Edwards (<adamed@opscode.com>)
3
- # Copyright:: Copyright (c) 2013 Opscode, 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
-
20
- require 'chef/exceptions'
21
- require 'chef/platform/query_helpers'
22
- require 'chef/win32/error' if Chef::Platform.windows?
23
- require 'chef/win32/api/system' if Chef::Platform.windows?
24
-
25
- class Chef
26
- module Mixin
27
- module WindowsEnvHelper
28
-
29
- if Chef::Platform.windows?
30
- include Chef::ReservedNames::Win32::API::System
31
- end
32
-
33
- #see: http://msdn.microsoft.com/en-us/library/ms682653%28VS.85%29.aspx
34
- HWND_BROADCAST = 0xffff
35
- WM_SETTINGCHANGE = 0x001A
36
- SMTO_BLOCK = 0x0001
37
- SMTO_ABORTIFHUNG = 0x0002
38
- SMTO_NOTIMEOUTIFNOTHUNG = 0x0008
39
-
40
- def broadcast_env_change
41
- flags = SMTO_BLOCK | SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG
42
- SendMessageTimeoutA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, FFI::MemoryPointer.from_string('Environment').address, flags, 5000, nil)
43
- end
44
-
45
- def expand_path(path)
46
- # http://msdn.microsoft.com/en-us/library/windows/desktop/ms724265%28v=vs.85%29.aspx
47
- # Max size of env block on windows is 32k
48
- buf = 0.chr * 32 * 1024
49
- if ExpandEnvironmentStringsA(path, buf, buf.length) == 0
50
- Chef::ReservedNames::Win32::Error.raise!
51
- end
52
- buf.strip
53
- end
54
- end
55
- end
56
- end
@@ -1,175 +0,0 @@
1
- #
2
- # Author:: Adam Edwards (<adamed@getchef.com>)
3
- #
4
- # Copyright:: 2014, Chef Software, Inc.
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/util/powershell/cmdlet'
20
- require 'chef/util/dsc/configuration_generator'
21
- require 'chef/util/dsc/local_configuration_manager'
22
-
23
- class Chef
24
- class Provider
25
- class DscScript < Chef::Provider
26
- def initialize(dsc_resource, run_context)
27
- super(dsc_resource, run_context)
28
- @dsc_resource = dsc_resource
29
- @resource_converged = false
30
- @operations = {
31
- :set => Proc.new { |config_manager, document|
32
- config_manager.set_configuration(document)
33
- },
34
- :test => Proc.new { |config_manager, document|
35
- config_manager.test_configuration(document)
36
- }}
37
- end
38
-
39
- def action_run
40
- if ! @resource_converged
41
- converge_by(generate_description) do
42
- run_configuration(:set)
43
- Chef::Log.info("DSC resource configuration completed successfully")
44
- end
45
- end
46
- end
47
-
48
- def load_current_resource
49
- if supports_dsc?
50
- @dsc_resources_info = run_configuration(:test)
51
- @resource_converged = @dsc_resources_info.all? do |resource|
52
- !resource.changes_state?
53
- end
54
- end
55
- end
56
-
57
- def whyrun_supported?
58
- true
59
- end
60
-
61
- def define_resource_requirements
62
- requirements.assert(:run) do |a|
63
- err = [
64
- 'Could not find PowerShell DSC support on the system',
65
- powershell_info_str,
66
- "Powershell 4.0 or higher was not detected on your system and is required to use the dsc_script resource.",
67
- ]
68
- a.assertion { supports_dsc? }
69
- a.failure_message Chef::Exceptions::NoProviderAvailable, err.join(' ')
70
- a.whyrun err + ["Assuming a previous resource installs Powershell 4.0 or higher."]
71
- a.block_action!
72
- end
73
- end
74
-
75
- protected
76
-
77
- def supports_dsc?
78
- run_context && Chef::Platform.supports_dsc?(node)
79
- end
80
-
81
- def run_configuration(operation)
82
- config_directory = ::Dir.mktmpdir("chef-dsc-script")
83
- configuration_data_path = get_configuration_data_path(config_directory)
84
- configuration_flags = get_augmented_configuration_flags(configuration_data_path)
85
-
86
- config_manager = Chef::Util::DSC::LocalConfigurationManager.new(@run_context.node, config_directory)
87
-
88
- begin
89
- configuration_document = generate_configuration_document(config_directory, configuration_flags)
90
- @operations[operation].call(config_manager, configuration_document)
91
- rescue Exception => e
92
- Chef::Log.error("DSC operation failed: #{e.message.to_s}")
93
- raise e
94
- ensure
95
- ::FileUtils.rm_rf(config_directory)
96
- end
97
- end
98
-
99
- def get_augmented_configuration_flags(configuration_data_path)
100
- updated_flags = @dsc_resource.flags.nil? ? {} : @dsc_resource.flags.dup
101
- if configuration_data_path
102
- Chef::Util::PathHelper.validate_path(configuration_data_path)
103
- updated_flags[:configurationdata] = configuration_data_path
104
- end
105
- updated_flags
106
- end
107
-
108
- def generate_configuration_document(config_directory, configuration_flags)
109
- shellout_flags = {
110
- :cwd => @dsc_resource.cwd,
111
- :environment => @dsc_resource.environment,
112
- :timeout => @dsc_resource.timeout
113
- }
114
-
115
- generator = Chef::Util::DSC::ConfigurationGenerator.new(@run_context.node, config_directory)
116
-
117
- if @dsc_resource.command
118
- generator.configuration_document_from_script_path(@dsc_resource.command, configuration_name, configuration_flags, shellout_flags)
119
- else
120
- # If code is also not provided, we mimic what the other script resources do (execute nothing)
121
- Chef::Log.warn("Neither code or command were provided for dsc_resource[#{@dsc_resource.name}].") unless @dsc_resource.code
122
- generator.configuration_document_from_script_code(@dsc_resource.code || '', configuration_flags, shellout_flags)
123
- end
124
- end
125
-
126
- def get_configuration_data_path(config_directory)
127
- if @dsc_resource.configuration_data_script
128
- @dsc_resource.configuration_data_script
129
- elsif @dsc_resource.configuration_data
130
- configuration_data_path = "#{config_directory}/chef_dsc_config_data.psd1"
131
- ::File.open(configuration_data_path, 'wt') do | script |
132
- script.write(@dsc_resource.configuration_data)
133
- end
134
- configuration_data_path
135
- end
136
- end
137
-
138
- def configuration_name
139
- @dsc_resource.configuration_name || @dsc_resource.name
140
- end
141
-
142
- def configuration_friendly_name
143
- if @dsc_resource.code
144
- @dsc_resource.name
145
- else
146
- configuration_name
147
- end
148
- end
149
-
150
- private
151
-
152
- def generate_description
153
- ["converge DSC configuration '#{configuration_friendly_name}'"] +
154
- @dsc_resources_info.map do |resource|
155
- if resource.changes_state?
156
- # We ignore the last log message because it only contains the time it took, which looks weird
157
- cleaned_messages = resource.change_log[0..-2].map { |c| c.sub(/^#{Regexp.escape(resource.name)}/, '').strip }
158
- "converge DSC resource #{resource.name} by #{cleaned_messages.find_all{ |c| c != ''}.join("\n")}"
159
- else
160
- # This is needed because a dsc script can have resouces that are both converged and not
161
- "converge DSC resource #{resource.name} by doing nothing because it is already converged"
162
- end
163
- end
164
- end
165
-
166
- def powershell_info_str
167
- if run_context && run_context.node[:languages] && run_context.node[:languages][:powershell]
168
- install_info = "Powershell #{run_context.node[:languages][:powershell][:version]} was found on the system."
169
- else
170
- install_info = 'Powershell was not found.'
171
- end
172
- end
173
- end
174
- end
175
- end
@@ -1,126 +0,0 @@
1
- #
2
- # Author:: Adam Edwards (<adamed@getchef.com>)
3
- # Copyright:: Copyright (c) 2014 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/exceptions'
20
-
21
- class Chef
22
- class Resource
23
- class DscScript < Chef::Resource
24
-
25
- provides :dsc_script, :on_platforms => ["windows"]
26
-
27
- def initialize(name, run_context=nil)
28
- super
29
- @allowed_actions.push(:run)
30
- @action = :run
31
- @provider = Chef::Provider::DscScript
32
- @resource_name = :dsc_script
33
- end
34
-
35
- def code(arg=nil)
36
- if arg && command
37
- raise ArgumentError, "Only one of 'code' and 'command' attributes may be specified"
38
- end
39
- if arg && configuration_name
40
- raise ArgumentError, "The 'code' and 'command' attributes may not be used together"
41
- end
42
- set_or_return(
43
- :code,
44
- arg,
45
- :kind_of => [ String ]
46
- )
47
- end
48
-
49
- def configuration_name(arg=nil)
50
- if arg && code
51
- raise ArgumentError, "Attribute `configuration_name` may not be set if `code` is set"
52
- end
53
- set_or_return(
54
- :configuration_name,
55
- arg,
56
- :kind_of => [ String ]
57
- )
58
- end
59
-
60
- def command(arg=nil)
61
- if arg && code
62
- raise ArgumentError, "The 'code' and 'command' attributes may not be used together"
63
- end
64
- set_or_return(
65
- :command,
66
- arg,
67
- :kind_of => [ String ]
68
- )
69
- end
70
-
71
- def configuration_data(arg=nil)
72
- if arg && configuration_data_script
73
- raise ArgumentError, "The 'configuration_data' and 'configuration_data_script' attributes may not be used together"
74
- end
75
- set_or_return(
76
- :configuration_data,
77
- arg,
78
- :kind_of => [ String ]
79
- )
80
- end
81
-
82
- def configuration_data_script(arg=nil)
83
- if arg && configuration_data
84
- raise ArgumentError, "The 'configuration_data' and 'configuration_data_script' attributes may not be used together"
85
- end
86
- set_or_return(
87
- :configuration_data_script,
88
- arg,
89
- :kind_of => [ String ]
90
- )
91
- end
92
-
93
- def flags(arg=nil)
94
- set_or_return(
95
- :flags,
96
- arg,
97
- :kind_of => [ Hash ]
98
- )
99
- end
100
-
101
- def cwd(arg=nil)
102
- set_or_return(
103
- :cwd,
104
- arg,
105
- :kind_of => [ String ]
106
- )
107
- end
108
-
109
- def environment(arg=nil)
110
- set_or_return(
111
- :environment,
112
- arg,
113
- :kind_of => [ Hash ]
114
- )
115
- end
116
-
117
- def timeout(arg=nil)
118
- set_or_return(
119
- :timeout,
120
- arg,
121
- :kind_of => [ Integer ]
122
- )
123
- end
124
- end
125
- end
126
- end
@@ -1,205 +0,0 @@
1
- # inspired by/cargo-culted from http://stanislavvitvitskiy.blogspot.com/2008/12/multipart-post-in-ruby.html
2
- # On Apr 6, 2010, at 3:00 PM, Stanislav Vitvitskiy wrote:
3
- #
4
- # It's free to use / modify / distribute. No need to mention anything. Just copy/paste and use.
5
- #
6
- # Regards,
7
- # Stan
8
-
9
- require 'net/http'
10
- require 'mixlib/authentication/signedheaderauth'
11
- require 'openssl'
12
- require 'chef/version'
13
-
14
- class Chef
15
- class StreamingCookbookUploader
16
-
17
- DefaultHeaders = { 'accept' => 'application/json', 'x-chef-version' => ::Chef::VERSION }
18
-
19
- class << self
20
-
21
- def post(to_url, user_id, secret_key_filename, params = {}, headers = {})
22
- make_request(:post, to_url, user_id, secret_key_filename, params, headers)
23
- end
24
-
25
- def put(to_url, user_id, secret_key_filename, params = {}, headers = {})
26
- make_request(:put, to_url, user_id, secret_key_filename, params, headers)
27
- end
28
-
29
- def make_request(http_verb, to_url, user_id, secret_key_filename, params = {}, headers = {})
30
- Chef::Log.warn('[DEPRECATED] StreamingCookbookUploader class is deprecated. It will be removed in Chef 12. Please use CookbookSiteStreamingUploader instead.')
31
- boundary = '----RubyMultipartClient' + rand(1000000).to_s + 'ZZZZZ'
32
- parts = []
33
- content_file = nil
34
-
35
- timestamp = Time.now.utc.iso8601
36
- secret_key = OpenSSL::PKey::RSA.new(File.read(secret_key_filename))
37
-
38
- unless params.nil? || params.empty?
39
- params.each do |key, value|
40
- if value.kind_of?(File)
41
- content_file = value
42
- filepath = value.path
43
- filename = File.basename(filepath)
44
- parts << StringPart.new( "--" + boundary + "\r\n" +
45
- "Content-Disposition: form-data; name=\"" + key.to_s + "\"; filename=\"" + filename + "\"\r\n" +
46
- "Content-Type: application/octet-stream\r\n\r\n")
47
- parts << StreamPart.new(value, File.size(filepath))
48
- parts << StringPart.new("\r\n")
49
- else
50
- parts << StringPart.new( "--" + boundary + "\r\n" +
51
- "Content-Disposition: form-data; name=\"" + key.to_s + "\"\r\n\r\n")
52
- parts << StringPart.new(value.to_s + "\r\n")
53
- end
54
- end
55
- parts << StringPart.new("--" + boundary + "--\r\n")
56
- end
57
-
58
- body_stream = MultipartStream.new(parts)
59
-
60
- timestamp = Time.now.utc.iso8601
61
-
62
- url = URI.parse(to_url)
63
-
64
- Chef::Log.logger.debug("Signing: method: #{http_verb}, path: #{url.path}, file: #{content_file}, User-id: #{user_id}, Timestamp: #{timestamp}")
65
-
66
- # We use the body for signing the request if the file parameter
67
- # wasn't a valid file or wasn't included. Extract the body (with
68
- # multi-part delimiters intact) to sign the request.
69
- # TODO: tim: 2009-12-28: It'd be nice to remove this special case, and
70
- # always hash the entire request body. In the file case it would just be
71
- # expanded multipart text - the entire body of the POST.
72
- content_body = parts.inject("") { |result,part| result + part.read(0, part.size) }
73
- content_file.rewind if content_file # we consumed the file for the above operation, so rewind it.
74
-
75
- signing_options = {
76
- :http_method=>http_verb,
77
- :path=>url.path,
78
- :user_id=>user_id,
79
- :timestamp=>timestamp}
80
- (content_file && signing_options[:file] = content_file) || (signing_options[:body] = (content_body || ""))
81
-
82
- headers.merge!(Mixlib::Authentication::SignedHeaderAuth.signing_object(signing_options).sign(secret_key))
83
-
84
- content_file.rewind if content_file
85
-
86
- # net/http doesn't like symbols for header keys, so we'll to_s each one just in case
87
- headers = DefaultHeaders.merge(Hash[*headers.map{ |k,v| [k.to_s, v] }.flatten])
88
-
89
- req = case http_verb
90
- when :put
91
- Net::HTTP::Put.new(url.path, headers)
92
- when :post
93
- Net::HTTP::Post.new(url.path, headers)
94
- end
95
- req.content_length = body_stream.size
96
- req.content_type = 'multipart/form-data; boundary=' + boundary unless parts.empty?
97
- req.body_stream = body_stream
98
-
99
- http = Net::HTTP.new(url.host, url.port)
100
- if url.scheme == "https"
101
- http.use_ssl = true
102
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
103
- end
104
- res = http.request(req)
105
- #res = http.start {|http_proc| http_proc.request(req) }
106
-
107
- # alias status to code and to_s to body for test purposes
108
- # TODO: stop the following madness!
109
- class << res
110
- alias :to_s :body
111
-
112
- # BUGBUG this makes the response compatible with what respsonse_steps expects to test headers (response.headers[] -> response[])
113
- def headers
114
- self
115
- end
116
-
117
- def status
118
- code.to_i
119
- end
120
- end
121
- res
122
- end
123
-
124
- end
125
-
126
- class StreamPart
127
- def initialize(stream, size)
128
- Chef::Log.warn('[DEPRECATED] StreamingCookbookUploader::StreamPart class is deprecated. It will be removed in Chef 12. Please use CookbookSiteStreamingUploader::StreamPart instead.')
129
- @stream, @size = stream, size
130
- end
131
-
132
- def size
133
- @size
134
- end
135
-
136
- # read the specified amount from the stream
137
- def read(offset, how_much)
138
- @stream.read(how_much)
139
- end
140
- end
141
-
142
- class StringPart
143
- def initialize(str)
144
- Chef::Log.warn('[DEPRECATED] StreamingCookbookUploader::StringPart class is deprecated. It will be removed in Chef 12. Please use CookbookSiteStreamingUploader::StringPart instead.')
145
- @str = str
146
- end
147
-
148
- def size
149
- @str.length
150
- end
151
-
152
- # read the specified amount from the string startiung at the offset
153
- def read(offset, how_much)
154
- @str[offset, how_much]
155
- end
156
- end
157
-
158
- class MultipartStream
159
- def initialize(parts)
160
- Chef::Log.warn('[DEPRECATED] StreamingCookbookUploader::MultipartStream class is deprecated. It will be removed in Chef 12. Please use CookbookSiteStreamingUploader::MultipartStream instead.')
161
- @parts = parts
162
- @part_no = 0
163
- @part_offset = 0
164
- end
165
-
166
- def size
167
- @parts.inject(0) {|size, part| size + part.size}
168
- end
169
-
170
- def read(how_much)
171
- return nil if @part_no >= @parts.size
172
-
173
- how_much_current_part = @parts[@part_no].size - @part_offset
174
-
175
- how_much_current_part = if how_much_current_part > how_much
176
- how_much
177
- else
178
- how_much_current_part
179
- end
180
-
181
- how_much_next_part = how_much - how_much_current_part
182
-
183
- current_part = @parts[@part_no].read(@part_offset, how_much_current_part)
184
-
185
- # recurse into the next part if the current one was not large enough
186
- if how_much_next_part > 0
187
- @part_no += 1
188
- @part_offset = 0
189
- next_part = read(how_much_next_part)
190
- current_part + if next_part
191
- next_part
192
- else
193
- ''
194
- end
195
- else
196
- @part_offset += how_much_current_part
197
- current_part
198
- end
199
- end
200
- end
201
-
202
- end
203
-
204
-
205
- end