chef 12.18.31 → 12.19.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (305) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -4
  3. data/README.md +12 -13
  4. data/VERSION +1 -1
  5. data/acceptance/Gemfile +4 -4
  6. data/acceptance/Gemfile.lock +70 -69
  7. data/chef-universal-mingw32.gemspec +2 -3
  8. data/chef.gemspec +6 -6
  9. data/lib/chef/api_client.rb +8 -10
  10. data/lib/chef/api_client_v1.rb +9 -11
  11. data/lib/chef/application/apply.rb +8 -10
  12. data/lib/chef/application/client.rb +1 -1
  13. data/lib/chef/application/exit_code.rb +3 -5
  14. data/lib/chef/application/knife.rb +2 -2
  15. data/lib/chef/application/windows_service.rb +29 -30
  16. data/lib/chef/application/windows_service_manager.rb +1 -1
  17. data/lib/chef/audit/audit_event_proxy.rb +2 -2
  18. data/lib/chef/audit/control_group_data.rb +1 -1
  19. data/lib/chef/chef_class.rb +1 -0
  20. data/lib/chef/chef_fs/chef_fs_data_store.rb +5 -7
  21. data/lib/chef/chef_fs/command_line.rb +15 -16
  22. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +1 -1
  23. data/lib/chef/chef_fs/data_handler/container_data_handler.rb +1 -1
  24. data/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +1 -1
  25. data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
  26. data/lib/chef/chef_fs/data_handler/environment_data_handler.rb +1 -1
  27. data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -1
  28. data/lib/chef/chef_fs/data_handler/node_data_handler.rb +1 -1
  29. data/lib/chef/chef_fs/data_handler/organization_data_handler.rb +1 -1
  30. data/lib/chef/chef_fs/data_handler/role_data_handler.rb +1 -1
  31. data/lib/chef/chef_fs/data_handler/user_data_handler.rb +1 -1
  32. data/lib/chef/chef_fs/file_pattern.rb +2 -2
  33. data/lib/chef/chef_fs/file_system.rb +1 -1
  34. data/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb +5 -6
  35. data/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb +8 -10
  36. data/lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb +8 -10
  37. data/lib/chef/chef_fs/file_system/chef_server/nodes_dir.rb +10 -12
  38. data/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb +28 -30
  39. data/lib/chef/chef_fs/file_system/chef_server/policy_group_entry.rb +1 -1
  40. data/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb +27 -29
  41. data/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb +18 -24
  42. data/lib/chef/chef_fs/file_system/memory/memory_file.rb +1 -1
  43. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +10 -12
  44. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +10 -12
  45. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +9 -13
  46. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +2 -0
  47. data/lib/chef/chef_fs/file_system/repository/cookbooks_dir.rb +1 -1
  48. data/lib/chef/chef_fs/file_system/repository/nodes_dir.rb +3 -0
  49. data/lib/chef/chef_fs/parallelizer.rb +9 -11
  50. data/lib/chef/cookbook/cookbook_version_loader.rb +25 -31
  51. data/lib/chef/cookbook/metadata.rb +26 -26
  52. data/lib/chef/cookbook/syntax_check.rb +1 -1
  53. data/lib/chef/cookbook_version.rb +3 -3
  54. data/lib/chef/data_bag.rb +1 -1
  55. data/lib/chef/data_bag_item.rb +3 -3
  56. data/lib/chef/data_collector.rb +3 -4
  57. data/lib/chef/decorator.rb +1 -1
  58. data/lib/chef/deprecated.rb +30 -0
  59. data/lib/chef/dsl/audit.rb +2 -2
  60. data/lib/chef/dsl/declare_resource.rb +1 -1
  61. data/lib/chef/dsl/platform_introspection.rb +29 -31
  62. data/lib/chef/dsl/reboot_pending.rb +1 -1
  63. data/lib/chef/dsl/resources.rb +6 -8
  64. data/lib/chef/encrypted_data_bag_item.rb +2 -2
  65. data/lib/chef/environment.rb +9 -11
  66. data/lib/chef/event_loggers/windows_eventlog.rb +1 -1
  67. data/lib/chef/exceptions.rb +4 -1
  68. data/lib/chef/file_access_control/unix.rb +14 -14
  69. data/lib/chef/file_access_control/windows.rb +1 -1
  70. data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +4 -5
  71. data/lib/chef/formatters/error_mapper.rb +6 -6
  72. data/lib/chef/http/api_versions.rb +50 -0
  73. data/lib/chef/http/validate_content_length.rb +2 -2
  74. data/lib/chef/json_compat.rb +6 -10
  75. data/lib/chef/key.rb +5 -5
  76. data/lib/chef/knife.rb +4 -4
  77. data/lib/chef/knife/cookbook_site_install.rb +2 -2
  78. data/lib/chef/knife/core/cookbook_scm_repo.rb +2 -2
  79. data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
  80. data/lib/chef/knife/core/status_presenter.rb +1 -1
  81. data/lib/chef/knife/core/ui.rb +19 -25
  82. data/lib/chef/knife/data_bag_secret_options.rb +1 -1
  83. data/lib/chef/knife/deps.rb +32 -34
  84. data/lib/chef/knife/help.rb +1 -1
  85. data/lib/chef/knife/list.rb +1 -1
  86. data/lib/chef/knife/search.rb +2 -2
  87. data/lib/chef/knife/ssh.rb +37 -27
  88. data/lib/chef/knife/ssl_check.rb +1 -1
  89. data/lib/chef/knife/user_delete.rb +1 -1
  90. data/lib/chef/mash.rb +1 -1
  91. data/lib/chef/mixin/command.rb +2 -2
  92. data/lib/chef/mixin/create_path.rb +3 -5
  93. data/lib/chef/mixin/from_file.rb +2 -2
  94. data/lib/chef/mixin/get_source_from_package.rb +2 -2
  95. data/lib/chef/mixin/notifying_block.rb +7 -9
  96. data/lib/chef/mixin/params_validate.rb +3 -3
  97. data/lib/chef/mixin/securable.rb +1 -1
  98. data/lib/chef/mixin/shell_out.rb +23 -3
  99. data/lib/chef/mixin/unformatter.rb +2 -2
  100. data/lib/chef/mixin/uris.rb +4 -6
  101. data/lib/chef/mixin/versioned_api.rb +69 -0
  102. data/lib/chef/mixin/which.rb +25 -8
  103. data/lib/chef/mixin/windows_architecture_helper.rb +2 -2
  104. data/lib/chef/mixin/xml_escape.rb +3 -5
  105. data/lib/chef/monkey_patches/webrick-utils.rb +1 -1
  106. data/lib/chef/node.rb +8 -8
  107. data/lib/chef/node/attribute.rb +4 -4
  108. data/lib/chef/node/common_api.rb +5 -7
  109. data/lib/chef/org.rb +10 -12
  110. data/lib/chef/platform/provider_mapping.rb +7 -7
  111. data/lib/chef/platform/query_helpers.rb +1 -1
  112. data/lib/chef/policy_builder/policyfile.rb +1 -0
  113. data/lib/chef/property.rb +31 -0
  114. data/lib/chef/provider/batch.rb +1 -1
  115. data/lib/chef/provider/breakpoint.rb +1 -1
  116. data/lib/chef/provider/cookbook_file.rb +3 -3
  117. data/lib/chef/provider/cron.rb +38 -38
  118. data/lib/chef/provider/deploy.rb +81 -81
  119. data/lib/chef/provider/deploy/revision.rb +3 -5
  120. data/lib/chef/provider/directory.rb +32 -32
  121. data/lib/chef/provider/dsc_resource.rb +22 -6
  122. data/lib/chef/provider/env.rb +28 -28
  123. data/lib/chef/provider/env/windows.rb +1 -1
  124. data/lib/chef/provider/erl_call.rb +13 -13
  125. data/lib/chef/provider/execute.rb +5 -2
  126. data/lib/chef/provider/file.rb +49 -51
  127. data/lib/chef/provider/git.rb +55 -55
  128. data/lib/chef/provider/http_request.rb +36 -36
  129. data/lib/chef/provider/launchd.rb +2 -2
  130. data/lib/chef/provider/link.rb +50 -50
  131. data/lib/chef/provider/log.rb +2 -2
  132. data/lib/chef/provider/mdadm.rb +25 -25
  133. data/lib/chef/provider/mount/aix.rb +2 -2
  134. data/lib/chef/provider/mount/mount.rb +2 -2
  135. data/lib/chef/provider/ohai.rb +1 -1
  136. data/lib/chef/provider/osx_profile.rb +23 -23
  137. data/lib/chef/provider/package.rb +74 -56
  138. data/lib/chef/provider/package/aix.rb +55 -52
  139. data/lib/chef/provider/package/apt.rb +15 -13
  140. data/lib/chef/provider/package/cab.rb +49 -20
  141. data/lib/chef/provider/package/chocolatey.rb +9 -10
  142. data/lib/chef/provider/package/dnf.rb +20 -18
  143. data/lib/chef/provider/package/dnf/dnf_helper.py +1 -1
  144. data/lib/chef/provider/package/dnf/python_helper.rb +63 -26
  145. data/lib/chef/provider/package/dnf/version.rb +1 -1
  146. data/lib/chef/provider/package/dpkg.rb +8 -9
  147. data/lib/chef/provider/package/easy_install.rb +22 -22
  148. data/lib/chef/provider/package/freebsd/base.rb +10 -10
  149. data/lib/chef/provider/package/freebsd/pkg.rb +15 -15
  150. data/lib/chef/provider/package/freebsd/pkgng.rb +13 -15
  151. data/lib/chef/provider/package/freebsd/port.rb +7 -7
  152. data/lib/chef/provider/package/homebrew.rb +11 -10
  153. data/lib/chef/provider/package/ips.rb +18 -23
  154. data/lib/chef/provider/package/macports.rb +23 -23
  155. data/lib/chef/provider/package/msu.rb +11 -11
  156. data/lib/chef/provider/package/openbsd.rb +25 -22
  157. data/lib/chef/provider/package/pacman.rb +16 -16
  158. data/lib/chef/provider/package/paludis.rb +26 -27
  159. data/lib/chef/provider/package/portage.rb +22 -22
  160. data/lib/chef/provider/package/powershell.rb +17 -17
  161. data/lib/chef/provider/package/rpm.rb +25 -25
  162. data/lib/chef/provider/package/rubygems.rb +60 -60
  163. data/lib/chef/provider/package/smartos.rb +16 -16
  164. data/lib/chef/provider/package/solaris.rb +44 -44
  165. data/lib/chef/provider/package/windows.rb +3 -3
  166. data/lib/chef/provider/package/windows/exe.rb +6 -6
  167. data/lib/chef/provider/package/windows/msi.rb +6 -6
  168. data/lib/chef/provider/package/yum.rb +318 -268
  169. data/lib/chef/provider/package/yum/rpm_utils.rb +34 -34
  170. data/lib/chef/provider/package/yum/yum_cache.rb +12 -12
  171. data/lib/chef/provider/package/zypper.rb +11 -11
  172. data/lib/chef/provider/powershell_script.rb +15 -7
  173. data/lib/chef/provider/reboot.rb +10 -10
  174. data/lib/chef/provider/registry_key.rb +39 -39
  175. data/lib/chef/provider/remote_directory.rb +3 -3
  176. data/lib/chef/provider/remote_file.rb +3 -3
  177. data/lib/chef/provider/route.rb +1 -1
  178. data/lib/chef/provider/ruby_block.rb +3 -3
  179. data/lib/chef/provider/script.rb +42 -6
  180. data/lib/chef/provider/service.rb +49 -49
  181. data/lib/chef/provider/service/solaris.rb +1 -1
  182. data/lib/chef/provider/service/systemd.rb +1 -1
  183. data/lib/chef/provider/subversion.rb +39 -39
  184. data/lib/chef/provider/systemd_unit.rb +2 -0
  185. data/lib/chef/provider/template.rb +3 -3
  186. data/lib/chef/provider/user.rb +42 -42
  187. data/lib/chef/provider/whyrun_safe_ruby_block.rb +4 -4
  188. data/lib/chef/resource.rb +27 -16
  189. data/lib/chef/resource/apt_repository.rb +0 -1
  190. data/lib/chef/resource/chef_gem.rb +1 -1
  191. data/lib/chef/resource/dnf_package.rb +6 -3
  192. data/lib/chef/resource/dsc_resource.rb +9 -1
  193. data/lib/chef/resource/execute.rb +70 -6
  194. data/lib/chef/resource/file/verification/systemd_unit.rb +67 -0
  195. data/lib/chef/resource/freebsd_package.rb +1 -1
  196. data/lib/chef/resource/gem_package.rb +1 -1
  197. data/lib/chef/resource/launchd.rb +13 -1
  198. data/lib/chef/resource/package.rb +2 -2
  199. data/lib/chef/resource/registry_key.rb +1 -1
  200. data/lib/chef/resource/yum_package.rb +12 -3
  201. data/lib/chef/resource/yum_repository.rb +0 -1
  202. data/lib/chef/resource_collection/resource_collection_serialization.rb +3 -3
  203. data/lib/chef/resource_collection/resource_set.rb +2 -2
  204. data/lib/chef/resource_reporter.rb +1 -1
  205. data/lib/chef/run_context.rb +3 -3
  206. data/lib/chef/run_list/run_list_item.rb +1 -1
  207. data/lib/chef/run_list/versioned_recipe_list.rb +6 -6
  208. data/lib/chef/server_api.rb +2 -0
  209. data/lib/chef/server_api_versions.rb +40 -0
  210. data/lib/chef/shell.rb +1 -1
  211. data/lib/chef/shell/ext.rb +3 -3
  212. data/lib/chef/shell/shell_session.rb +1 -1
  213. data/lib/chef/user.rb +9 -11
  214. data/lib/chef/user_v1.rb +9 -11
  215. data/lib/chef/util/diff.rb +1 -1
  216. data/lib/chef/util/dsc/lcm_output_parser.rb +1 -1
  217. data/lib/chef/util/selinux.rb +1 -1
  218. data/lib/chef/util/windows/net_group.rb +18 -30
  219. data/lib/chef/util/windows/net_use.rb +7 -11
  220. data/lib/chef/util/windows/net_user.rb +11 -17
  221. data/lib/chef/util/windows/volume.rb +9 -15
  222. data/lib/chef/version.rb +1 -1
  223. data/lib/chef/version_class.rb +1 -1
  224. data/lib/chef/win32/api.rb +4 -6
  225. data/lib/chef/win32/api/file.rb +25 -31
  226. data/lib/chef/win32/api/installer.rb +2 -2
  227. data/lib/chef/win32/file.rb +4 -6
  228. data/lib/chef/win32/registry.rb +9 -9
  229. data/lib/chef/win32/security.rb +2 -2
  230. data/lib/chef/win32/security/acl.rb +2 -2
  231. data/lib/chef/win32/unicode.rb +2 -2
  232. data/lib/chef/win32/version.rb +1 -1
  233. data/spec/data/prefer_metadata_json/metadata.json +51 -0
  234. data/spec/data/prefer_metadata_json/metadata.rb +6 -0
  235. data/spec/data/prefer_metadata_json/recipes/default.rb +0 -0
  236. data/spec/functional/knife/ssh_spec.rb +5 -5
  237. data/spec/functional/resource/batch_spec.rb +5 -1
  238. data/spec/functional/resource/dsc_script_spec.rb +2 -4
  239. data/spec/functional/resource/execute_spec.rb +17 -0
  240. data/spec/functional/resource/user/dscl_spec.rb +2 -4
  241. data/spec/integration/client/client_spec.rb +33 -0
  242. data/spec/integration/recipes/recipe_dsl_spec.rb +58 -58
  243. data/spec/spec_helper.rb +4 -0
  244. data/spec/support/chef_helpers.rb +5 -7
  245. data/spec/support/platform_helpers.rb +6 -0
  246. data/spec/support/platforms/prof/gc.rb +4 -6
  247. data/spec/support/shared/context/client.rb +1 -1
  248. data/spec/support/shared/functional/execute_resource.rb +150 -0
  249. data/spec/support/shared/functional/windows_script.rb +74 -4
  250. data/spec/support/shared/unit/execute_resource.rb +37 -0
  251. data/spec/support/shared/unit/provider/file.rb +10 -0
  252. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +9 -0
  253. data/spec/unit/cookbook/syntax_check_spec.rb +8 -2
  254. data/spec/unit/http/api_versions_spec.rb +69 -0
  255. data/spec/unit/knife/ssh_spec.rb +34 -36
  256. data/spec/unit/mixin/versioned_api_spec.rb +107 -0
  257. data/spec/unit/mixin/which.rb +160 -0
  258. data/spec/unit/platform_spec.rb +28 -1
  259. data/spec/unit/provider/deploy_spec.rb +1 -1
  260. data/spec/unit/provider/directory_spec.rb +10 -0
  261. data/spec/unit/provider/dsc_resource_spec.rb +175 -0
  262. data/spec/unit/provider/execute_spec.rb +0 -1
  263. data/spec/unit/provider/launchd_spec.rb +2 -2
  264. data/spec/unit/provider/package/aix_spec.rb +22 -22
  265. data/spec/unit/provider/package/apt_spec.rb +27 -27
  266. data/spec/unit/provider/package/cab_spec.rb +59 -5
  267. data/spec/unit/provider/package/dnf/python_helper_spec.rb +29 -0
  268. data/spec/unit/provider/package/dpkg_spec.rb +16 -16
  269. data/spec/unit/provider/package/easy_install_spec.rb +18 -18
  270. data/spec/unit/provider/package/freebsd/pkg_spec.rb +15 -15
  271. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +9 -9
  272. data/spec/unit/provider/package/freebsd/port_spec.rb +9 -9
  273. data/spec/unit/provider/package/homebrew_spec.rb +9 -9
  274. data/spec/unit/provider/package/ips_spec.rb +37 -31
  275. data/spec/unit/provider/package/macports_spec.rb +10 -10
  276. data/spec/unit/provider/package/openbsd_spec.rb +10 -10
  277. data/spec/unit/provider/package/pacman_spec.rb +6 -6
  278. data/spec/unit/provider/package/paludis_spec.rb +7 -7
  279. data/spec/unit/provider/package/portage_spec.rb +6 -7
  280. data/spec/unit/provider/package/rpm_spec.rb +23 -23
  281. data/spec/unit/provider/package/rubygems_spec.rb +38 -38
  282. data/spec/unit/provider/package/solaris_spec.rb +15 -15
  283. data/spec/unit/provider/package/windows_spec.rb +2 -1
  284. data/spec/unit/provider/package/yum_spec.rb +51 -43
  285. data/spec/unit/provider/package/zypper_spec.rb +34 -34
  286. data/spec/unit/provider/package_spec.rb +8 -0
  287. data/spec/unit/provider/remote_file/sftp_spec.rb +3 -3
  288. data/spec/unit/provider/route_spec.rb +7 -1
  289. data/spec/unit/provider/script_spec.rb +49 -6
  290. data/spec/unit/resource/dsc_resource_spec.rb +6 -0
  291. data/spec/unit/resource/execute_spec.rb +214 -0
  292. data/spec/unit/resource/file/verification/systemd_unit_spec.rb +103 -0
  293. data/spec/unit/resource/freebsd_package_spec.rb +2 -2
  294. data/spec/unit/resource/package_spec.rb +5 -0
  295. data/spec/unit/resource/yum_package_spec.rb +42 -1
  296. data/spec/unit/resource_reporter_spec.rb +1 -1
  297. data/spec/unit/resource_spec.rb +18 -0
  298. data/spec/unit/server_api_versions_spec.rb +44 -0
  299. data/spec/unit/util/selinux_spec.rb +3 -14
  300. data/spec/unit/win32/error_spec.rb +67 -0
  301. data/spec/unit/win32/security_spec.rb +66 -0
  302. data/tasks/changelog.rb +1 -1
  303. data/tasks/dependencies.rb +20 -4
  304. metadata +39 -18
  305. data/lib/chef/monkey_patches/net-ssh-multi.rb +0 -141
@@ -579,7 +579,7 @@ class Chef
579
579
  def load_from(resource)
580
580
  resource.instance_variables.each do |iv|
581
581
  unless iv == :@source_line || iv == :@action || iv == :@not_if || iv == :@only_if
582
- self.instance_variable_set(iv, resource.instance_variable_get(iv))
582
+ instance_variable_set(iv, resource.instance_variable_get(iv))
583
583
  end
584
584
  end
585
585
  end
@@ -667,21 +667,34 @@ class Chef
667
667
 
668
668
  def to_text
669
669
  return "suppressed sensitive resource output" if sensitive
670
- ivars = instance_variables.map { |ivar| ivar.to_sym } - HIDDEN_IVARS
671
670
  text = "# Declared in #{@source_line}\n\n"
672
671
  text << "#{resource_name}(\"#{name}\") do\n"
672
+
673
+ all_props = {}
674
+ self.class.state_properties.map do |p|
675
+ all_props[p.name.to_s] = p.sensitive? ? '"*sensitive value suppressed*"' : value_to_text(p.get(self))
676
+ end
677
+
678
+ ivars = instance_variables.map { |ivar| ivar.to_sym } - HIDDEN_IVARS
673
679
  ivars.each do |ivar|
674
- if (value = instance_variable_get(ivar)) && !(value.respond_to?(:empty?) && value.empty?)
675
- value_string = value.respond_to?(:to_text) ? value.to_text : value.inspect
676
- text << " #{ivar.to_s.sub(/^@/, '')} #{value_string}\n"
680
+ iv = ivar.to_s.sub(/^@/, "")
681
+ if all_props.keys.include?(iv)
682
+ text << " #{iv} #{all_props[iv]}\n"
683
+ elsif (value = instance_variable_get(ivar)) && !(value.respond_to?(:empty?) && value.empty?)
684
+ text << " #{iv} #{value_to_text(value)}\n"
677
685
  end
678
686
  end
687
+
679
688
  [@not_if, @only_if].flatten.each do |conditional|
680
689
  text << " #{conditional.to_text}\n"
681
690
  end
682
691
  text << "end\n"
683
692
  end
684
693
 
694
+ def value_to_text(value)
695
+ value.respond_to?(:to_text) ? value.to_text : value.inspect
696
+ end
697
+
685
698
  def inspect
686
699
  ivars = instance_variables.map { |ivar| ivar.to_sym } - FORBIDDEN_IVARS
687
700
  ivars.inject("<#{self}") do |str, ivar|
@@ -726,7 +739,7 @@ class Chef
726
739
  end
727
740
 
728
741
  def self.json_create(o)
729
- resource = self.new(o["instance_vars"]["@name"])
742
+ resource = new(o["instance_vars"]["@name"])
730
743
  o["instance_vars"].each do |k, v|
731
744
  resource.instance_variable_set("@#{k}".to_sym, v)
732
745
  end
@@ -1036,7 +1049,7 @@ class Chef
1036
1049
  # A::B::BlahDBlah -> blah_d_blah
1037
1050
  #
1038
1051
  def self.use_automatic_resource_name
1039
- automatic_name = convert_to_snake_case(self.name.split("::")[-1])
1052
+ automatic_name = convert_to_snake_case(name.split("::")[-1])
1040
1053
  resource_name automatic_name
1041
1054
  end
1042
1055
 
@@ -1486,7 +1499,7 @@ class Chef
1486
1499
  if args.size == 1
1487
1500
  args.first
1488
1501
  else
1489
- return *args
1502
+ args
1490
1503
  end
1491
1504
  end
1492
1505
 
@@ -1567,14 +1580,12 @@ class Chef
1567
1580
 
1568
1581
  # @api private
1569
1582
  def lookup_provider_constant(name, action = :nothing)
1570
- begin
1571
- self.class.provider_base.const_get(convert_to_class_name(name.to_s))
1572
- rescue NameError => e
1573
- if e.to_s =~ /#{Regexp.escape(self.class.provider_base.to_s)}/
1574
- raise ArgumentError, "No provider found to match '#{name}'"
1575
- else
1576
- raise e
1577
- end
1583
+ self.class.provider_base.const_get(convert_to_class_name(name.to_s))
1584
+ rescue NameError => e
1585
+ if e.to_s =~ /#{Regexp.escape(self.class.provider_base.to_s)}/
1586
+ raise ArgumentError, "No provider found to match '#{name}'"
1587
+ else
1588
+ raise e
1578
1589
  end
1579
1590
  end
1580
1591
 
@@ -38,7 +38,6 @@ class Chef
38
38
 
39
39
  property :cookbook, [String, nil, false], default: nil, desired_state: false, nillable: true, coerce: proc { |x| x ? x : nil }
40
40
  property :cache_rebuild, [TrueClass, FalseClass], default: true, desired_state: false
41
- property :sensitive, [TrueClass, FalseClass], default: false, desired_state: false
42
41
 
43
42
  default_action :add
44
43
  allowed_actions :add, :remove
@@ -40,7 +40,7 @@ class Chef
40
40
 
41
41
  if compile_time || compile_time.nil?
42
42
  Array(action).each do |action|
43
- self.run_action(action)
43
+ run_action(action)
44
44
  end
45
45
  Gem.clear_paths
46
46
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright 2016, Chef Software, Inc.
2
+ # Copyright:: Copyright 2016-2017, Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,18 +16,21 @@
16
16
  #
17
17
 
18
18
  require "chef/resource/package"
19
+ require "chef/mixin/which"
20
+ require "chef/mixin/shell_out"
19
21
 
20
22
  class Chef
21
23
  class Resource
22
24
  class DnfPackage < Chef::Resource::Package
23
25
  extend Chef::Mixin::Which
26
+ extend Chef::Mixin::ShellOut
24
27
 
25
28
  resource_name :dnf_package
26
29
 
27
30
  allowed_actions :install, :upgrade, :remove, :purge, :reconfig, :lock, :unlock, :flush_cache
28
31
 
29
- provides :package, os: "linux", platform_family: %w{rhel fedora} do
30
- which("dnf")
32
+ provides :package, platform_family: %w{rhel fedora} do
33
+ which("dnf") && shell_out("rpm -q dnf").stdout =~ /^dnf-[1-9]/
31
34
  end
32
35
 
33
36
  provides :dnf_package
@@ -29,7 +29,7 @@ class Chef
29
29
  # to dump the actual ivars
30
30
  class ToTextHash < Hash
31
31
  def to_text
32
- descriptions = self.map do |(property, obj)|
32
+ descriptions = map do |(property, obj)|
33
33
  obj_text = if obj.respond_to?(:to_text)
34
34
  obj.to_text
35
35
  else
@@ -68,6 +68,14 @@ class Chef
68
68
  end
69
69
  end
70
70
 
71
+ def module_version(arg = nil)
72
+ set_or_return(
73
+ :module_version,
74
+ arg,
75
+ :kind_of => [ String ]
76
+ )
77
+ end
78
+
71
79
  def property(property_name, value = nil)
72
80
  if not property_name.is_a?(Symbol)
73
81
  raise TypeError, "A property name of type Symbol must be specified, '#{property_name}' of type #{property_name.class} was given"
@@ -135,12 +135,18 @@ class Chef
135
135
  )
136
136
  end
137
137
 
138
- def user(arg = nil)
139
- set_or_return(
140
- :user,
141
- arg,
142
- :kind_of => [ String, Integer ]
143
- )
138
+ property :user, [ String, Integer ]
139
+
140
+ property :domain, String
141
+
142
+ property :password, String, sensitive: true
143
+
144
+ def sensitive(args = nil)
145
+ if password
146
+ true
147
+ else
148
+ super
149
+ end
144
150
  end
145
151
 
146
152
  def self.set_guard_inherited_attributes(*inherited_attributes)
@@ -159,6 +165,64 @@ class Chef
159
165
  ancestor_attributes.concat(@class_inherited_attributes ? @class_inherited_attributes : []).uniq
160
166
  end
161
167
 
168
+ def after_created
169
+ validate_identity_platform(user, password, domain)
170
+ identity = qualify_user(user, password, domain)
171
+ domain(identity[:domain])
172
+ user(identity[:user])
173
+ end
174
+
175
+ def validate_identity_platform(specified_user, password = nil, specified_domain = nil)
176
+ if node[:platform_family] == "windows"
177
+ if specified_user && password.nil?
178
+ raise ArgumentError, "A value for `password` must be specified when a value for `user` is specified on the Windows platform"
179
+ end
180
+ else
181
+ if password || specified_domain
182
+ raise Exceptions::UnsupportedPlatform, "Values for `domain` and `password` are only supported on the Windows platform"
183
+ end
184
+ end
185
+ end
186
+
187
+ def qualify_user(specified_user, password = nil, specified_domain = nil)
188
+ domain = specified_domain
189
+ user = specified_user
190
+
191
+ if specified_user.nil? && ! specified_domain.nil?
192
+ raise ArgumentError, "The domain `#{specified_domain}` was specified, but no user name was given"
193
+ end
194
+
195
+ # if domain is provided in both username and domain
196
+ if specified_user && ((specified_user.include? '\\') || (specified_user.include? "@")) && specified_domain
197
+ raise ArgumentError, "The domain is provided twice. Username: `#{specified_user}`, Domain: `#{specified_domain}`. Please specify domain only once."
198
+ end
199
+
200
+ if ! specified_user.nil? && specified_domain.nil?
201
+ # Splitting username of format: Domain\Username
202
+ domain_and_user = user.split('\\')
203
+
204
+ if domain_and_user.length == 2
205
+ domain = domain_and_user[0]
206
+ user = domain_and_user[1]
207
+ elsif domain_and_user.length == 1
208
+ # Splitting username of format: Username@Domain
209
+ domain_and_user = user.split("@")
210
+ if domain_and_user.length == 2
211
+ domain = domain_and_user[1]
212
+ user = domain_and_user[0]
213
+ elsif domain_and_user.length != 1
214
+ raise ArgumentError, "The specified user name `#{user}` is not a syntactically valid user name"
215
+ end
216
+ end
217
+ end
218
+
219
+ if ( password || domain ) && user.nil?
220
+ raise ArgumentError, "A value for `password` or `domain` was specified without specification of a value for `user`"
221
+ end
222
+
223
+ { domain: domain, user: user }
224
+ end
225
+
162
226
  set_guard_inherited_attributes(
163
227
  :cwd,
164
228
  :environment,
@@ -0,0 +1,67 @@
1
+ #
2
+ # Author:: Mal Graty (<mal.graty@googlemail.com>)
3
+ # Copyright:: Copyright 2013-2017, 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/mixin/which"
20
+
21
+ class Chef
22
+ class Resource
23
+ class File
24
+ class Verification
25
+
26
+ #
27
+ # Systemd provides a binary for verifying the correctness of
28
+ # unit files. Unfortunately some units have constraints on the
29
+ # filename meaning that normal verification against temp files
30
+ # won't work.
31
+ #
32
+ # Working around that requires placing a copy of the temp file
33
+ # in a temp directory, under its real name and running the
34
+ # verification tool against that file.
35
+ #
36
+
37
+ class SystemdUnit < Chef::Resource::File::Verification
38
+ include Chef::Mixin::Which
39
+
40
+ provides :systemd_unit
41
+
42
+ def initialize(parent_resource, command, opts, &block)
43
+ super
44
+ @command = systemd_analyze_cmd
45
+ end
46
+
47
+ def verify(path, opts = {})
48
+ return true unless systemd_analyze_path
49
+ Dir.mktmpdir("chef-systemd-unit") do |dir|
50
+ temp = "#{dir}/#{::File.basename(@parent_resource.path)}"
51
+ ::FileUtils.cp(path, temp)
52
+ verify_command(temp, opts)
53
+ end
54
+ end
55
+
56
+ def systemd_analyze_cmd
57
+ @systemd_analyze_cmd ||= "#{systemd_analyze_path} verify %{path}"
58
+ end
59
+
60
+ def systemd_analyze_path
61
+ @systemd_analyze_path ||= which("systemd-analyze")
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -37,7 +37,7 @@ class Chef
37
37
  end
38
38
 
39
39
  def supports_pkgng?
40
- ships_with_pkgng? || !!shell_out!("make -V WITH_PKGNG", :env => nil).stdout.match(/yes/i)
40
+ ships_with_pkgng? || !!shell_out_compact!("make", "-V", "WITH_PKGNG", :env => nil).stdout.match(/yes/i)
41
41
  end
42
42
 
43
43
  private
@@ -34,7 +34,7 @@ class Chef
34
34
  # gem will be installed via the gems API. When a String is given, the gem
35
35
  # will be installed by shelling out to the gem command. Using a Hash of
36
36
  # options with an explicit gem_binary will result in undefined behavior.
37
- property :options, [ String, Hash, nil ], desired_state: false
37
+ property :options, [ String, Hash, Array, nil ], desired_state: false
38
38
 
39
39
  end
40
40
  end
@@ -33,7 +33,7 @@ class Chef
33
33
  property :backup, [Integer, FalseClass]
34
34
  property :cookbook, String
35
35
  property :group, [String, Integer]
36
- property :hash, Hash
36
+ property :plist_hash, Hash
37
37
  property :mode, [String, Integer]
38
38
  property :owner, [String, Integer]
39
39
  property :path, String
@@ -139,6 +139,18 @@ class Chef
139
139
  property :wait_for_debugger, [ TrueClass, FalseClass ]
140
140
  property :watch_paths, Array
141
141
  property :working_directory, String
142
+
143
+ # hash is an instance method on Object and needs to return a Fixnum.
144
+ def hash(arg = nil)
145
+ Chef.deprecated(:launchd_hash_property, "Property `hash` on the `launchd` resource has changed to `plist_hash`." \
146
+ "Please use `plist_hash` instead. This will raise an exception in Chef 13.")
147
+
148
+ set_or_return(
149
+ :plist_hash,
150
+ arg,
151
+ :kind_of => Hash
152
+ )
153
+ end
142
154
  end
143
155
  end
144
156
  end
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@chef.io>)
3
3
  # Author:: Tyler Cloke (<tyler@chef.io>)
4
- # Copyright:: Copyright 2008-2016, Chef Software, Inc.
4
+ # Copyright:: Copyright 2008-2017, Chef Software Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -36,7 +36,7 @@ class Chef
36
36
  property :package_name, [ String, Array ], identity: true
37
37
 
38
38
  property :version, [ String, Array ]
39
- property :options, String
39
+ property :options, [ String, Array ]
40
40
  property :response_file, String, desired_state: false
41
41
  property :response_file_variables, Hash, default: lazy { {} }, desired_state: false
42
42
  property :source, String, desired_state: false
@@ -96,7 +96,7 @@ class Chef
96
96
  end
97
97
  end
98
98
  @unscrubbed_values = @values
99
- elsif self.instance_variable_defined?(:@values)
99
+ elsif instance_variable_defined?(:@values)
100
100
  scrub_values(@values)
101
101
  end
102
102
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: AJ Christensen (<aj@chef.io>)
3
- # Copyright:: Copyright 2008-2016, Chef Software, Inc.
3
+ # Copyright:: Copyright 2008-2017, Chef Software Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,8 +24,17 @@ class Chef
24
24
  resource_name :yum_package
25
25
  provides :package, os: "linux", platform_family: %w{rhel fedora}
26
26
 
27
- # Install a specific arch
28
- property :arch, [ String, Array ]
27
+ # XXX: the coercions here are due to the provider promiscuously updating the properties on the
28
+ # new_resource which causes immutable modification exceptions when passed an immutable node array.
29
+ #
30
+ # <lecture>
31
+ # THIS is why updating the new_resource in a provider is so terrible, and is equivalent to methods scribbling over
32
+ # its own arguments as unintended side-effects (and why functional languages that don't allow modifcations
33
+ # of variables eliminate entire classes of bugs).
34
+ # </lecture>
35
+ property :package_name, [ String, Array ], identity: true, coerce: proc { |x| x.is_a?(Array) ? x.to_a : x }
36
+ property :version, [ String, Array ], coerce: proc { |x| x.is_a?(Array) ? x.to_a : x }
37
+ property :arch, [ String, Array ], coerce: proc { |x| x.is_a?(Array) ? x.to_a : x }
29
38
 
30
39
  property :flush_cache,
31
40
  Hash,
@@ -58,7 +58,6 @@ class Chef
58
58
  property :repo_gpgcheck, [TrueClass, FalseClass]
59
59
  property :report_instanceid, [TrueClass, FalseClass]
60
60
  property :repositoryid, String, regex: /.*/, name_property: true
61
- property :sensitive, [TrueClass, FalseClass], default: false
62
61
  property :skip_if_unavailable, [TrueClass, FalseClass]
63
62
  property :source, String, regex: /.*/
64
63
  property :sslcacert, String, regex: /.*/
@@ -21,8 +21,8 @@ class Chef
21
21
  # Serialize this object as a hash
22
22
  def to_hash
23
23
  instance_vars = Hash.new
24
- self.instance_variables.each do |iv|
25
- instance_vars[iv] = self.instance_variable_get(iv)
24
+ instance_variables.each do |iv|
25
+ instance_vars[iv] = instance_variable_get(iv)
26
26
  end
27
27
  {
28
28
  "json_class" => self.class.name,
@@ -40,7 +40,7 @@ class Chef
40
40
 
41
41
  module ClassMethods
42
42
  def json_create(o)
43
- collection = self.new()
43
+ collection = new()
44
44
  o["instance_vars"].each do |k, v|
45
45
  collection.instance_variable_set(k.to_sym, v)
46
46
  end