chef 15.10.12-universal-mingw32 → 15.14.0-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -10
  3. data/README.md +3 -3
  4. data/Rakefile +1 -1
  5. data/chef-universal-mingw32.gemspec +2 -2
  6. data/chef.gemspec +3 -3
  7. data/distro/powershell/chef/chef.psm1 +3 -3
  8. data/distro/templates/powershell/chef/chef.psm1.erb +3 -3
  9. data/lib/chef/api_client/registration.rb +2 -2
  10. data/lib/chef/application/apply.rb +2 -2
  11. data/lib/chef/application/exit_code.rb +2 -2
  12. data/lib/chef/chef_fs/chef_fs_data_store.rb +3 -3
  13. data/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb +1 -1
  14. data/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb +1 -1
  15. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +1 -1
  16. data/lib/chef/chef_fs/file_system/repository/base_file.rb +1 -0
  17. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +2 -2
  18. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +1 -1
  19. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +2 -2
  20. data/lib/chef/chef_fs/file_system/repository/directory.rb +1 -1
  21. data/lib/chef/chef_fs/file_system/repository/file_system_entry.rb +1 -1
  22. data/lib/chef/chef_fs/path_utils.rb +3 -3
  23. data/lib/chef/cookbook/file_system_file_vendor.rb +1 -1
  24. data/lib/chef/cookbook_version.rb +4 -4
  25. data/lib/chef/data_bag.rb +2 -2
  26. data/lib/chef/data_collector/error_handlers.rb +1 -1
  27. data/lib/chef/deprecated.rb +13 -1
  28. data/lib/chef/dsl/declare_resource.rb +1 -1
  29. data/lib/chef/dsl/platform_introspection.rb +3 -1
  30. data/lib/chef/environment.rb +2 -2
  31. data/lib/chef/exceptions.rb +3 -0
  32. data/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb +2 -2
  33. data/lib/chef/formatters/error_inspectors/registration_error_inspector.rb +7 -7
  34. data/lib/chef/http.rb +2 -1
  35. data/lib/chef/knife.rb +26 -20
  36. data/lib/chef/knife/bootstrap.rb +30 -31
  37. data/lib/chef/knife/bootstrap/chef_vault_handler.rb +12 -8
  38. data/lib/chef/knife/bootstrap/client_builder.rb +23 -19
  39. data/lib/chef/knife/bootstrap/templates/chef-full.erb +9 -9
  40. data/lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb +3 -1
  41. data/lib/chef/knife/bootstrap/train_connector.rb +1 -0
  42. data/lib/chef/knife/cookbook_download.rb +1 -1
  43. data/lib/chef/knife/cookbook_metadata.rb +1 -1
  44. data/lib/chef/knife/cookbook_site_search.rb +1 -1
  45. data/lib/chef/knife/cookbook_site_show.rb +1 -1
  46. data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
  47. data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
  48. data/lib/chef/knife/core/hashed_command_loader.rb +3 -2
  49. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  50. data/lib/chef/knife/core/windows_bootstrap_context.rb +18 -3
  51. data/lib/chef/knife/exec.rb +2 -2
  52. data/lib/chef/knife/ssh.rb +21 -2
  53. data/lib/chef/log.rb +1 -1
  54. data/lib/chef/mixin/create_path.rb +8 -8
  55. data/lib/chef/mixin/openssl_helper.rb +26 -3
  56. data/lib/chef/mixin/template.rb +1 -0
  57. data/lib/chef/node/mixin/deep_merge_cache.rb +7 -7
  58. data/lib/chef/node_map.rb +5 -2
  59. data/lib/chef/provider/mount/solaris.rb +0 -1
  60. data/lib/chef/provider/package/cab.rb +1 -1
  61. data/lib/chef/provider/package/chocolatey.rb +4 -3
  62. data/lib/chef/provider/package/msu.rb +1 -0
  63. data/lib/chef/provider/package/powershell.rb +5 -1
  64. data/lib/chef/provider/package/snap.rb +96 -27
  65. data/lib/chef/provider/package/zypper.rb +0 -1
  66. data/lib/chef/provider/service/arch.rb +2 -2
  67. data/lib/chef/provider/service/debian.rb +1 -1
  68. data/lib/chef/provider/service/gentoo.rb +2 -2
  69. data/lib/chef/provider/service/macosx.rb +2 -2
  70. data/lib/chef/provider/service/openbsd.rb +1 -1
  71. data/lib/chef/provider/service/redhat.rb +2 -2
  72. data/lib/chef/provider/service/simple.rb +3 -3
  73. data/lib/chef/provider/service/upstart.rb +1 -1
  74. data/lib/chef/provider/windows_task.rb +1 -1
  75. data/lib/chef/provider/yum_repository.rb +1 -1
  76. data/lib/chef/provider/zypper_repository.rb +31 -11
  77. data/lib/chef/resource.rb +2 -0
  78. data/lib/chef/resource/archive_file.rb +28 -8
  79. data/lib/chef/resource/build_essential.rb +1 -1
  80. data/lib/chef/resource/cron_access.rb +13 -5
  81. data/lib/chef/resource/cron_d.rb +1 -1
  82. data/lib/chef/resource/hostname.rb +19 -18
  83. data/lib/chef/resource/launchd.rb +4 -4
  84. data/lib/chef/resource/lwrp_base.rb +7 -0
  85. data/lib/chef/resource/macos_userdefaults.rb +3 -3
  86. data/lib/chef/resource/msu_package.rb +5 -0
  87. data/lib/chef/resource/ssh_known_hosts_entry.rb +1 -1
  88. data/lib/chef/resource/sudo.rb +2 -2
  89. data/lib/chef/resource/windows_feature_powershell.rb +6 -2
  90. data/lib/chef/resource/windows_firewall_rule.rb +8 -4
  91. data/lib/chef/resource/windows_font.rb +2 -1
  92. data/lib/chef/resource/windows_share.rb +4 -4
  93. data/lib/chef/resource/windows_task.rb +13 -13
  94. data/lib/chef/resource_inspector.rb +4 -3
  95. data/lib/chef/role.rb +2 -2
  96. data/lib/chef/shell.rb +1 -1
  97. data/lib/chef/shell/shell_session.rb +2 -0
  98. data/lib/chef/util/diff.rb +1 -1
  99. data/lib/chef/util/dsc/lcm_output_parser.rb +3 -3
  100. data/lib/chef/util/powershell/cmdlet.rb +1 -1
  101. data/lib/chef/version.rb +2 -2
  102. data/lib/chef/win32/api/command_line_helper.rb +89 -0
  103. data/lib/chef/win32/api/file.rb +18 -18
  104. data/lib/chef/win32/file.rb +3 -3
  105. data/lib/chef/win32/process.rb +2 -2
  106. data/spec/functional/knife/ssh_spec.rb +4 -4
  107. data/spec/functional/resource/aix_service_spec.rb +0 -1
  108. data/spec/functional/resource/aixinit_service_spec.rb +7 -8
  109. data/spec/functional/resource/apt_package_spec.rb +0 -1
  110. data/spec/functional/resource/bff_spec.rb +2 -2
  111. data/spec/functional/resource/chocolatey_package_spec.rb +29 -0
  112. data/spec/functional/resource/cookbook_file_spec.rb +1 -1
  113. data/spec/functional/resource/cron_spec.rb +0 -1
  114. data/spec/functional/resource/dsc_resource_spec.rb +1 -1
  115. data/spec/functional/resource/insserv_spec.rb +4 -5
  116. data/spec/functional/resource/link_spec.rb +17 -17
  117. data/spec/functional/resource/msu_package_spec.rb +5 -2
  118. data/spec/functional/resource/rpm_spec.rb +2 -2
  119. data/spec/functional/resource/user/dscl_spec.rb +2 -2
  120. data/spec/functional/resource/user/mac_user_spec.rb +2 -2
  121. data/spec/functional/resource/windows_certificate_spec.rb +3 -3
  122. data/spec/functional/resource/windows_font_spec.rb +49 -0
  123. data/spec/functional/resource/windows_task_spec.rb +8 -8
  124. data/spec/functional/run_lock_spec.rb +2 -1
  125. data/spec/functional/util/powershell/cmdlet_spec.rb +1 -1
  126. data/spec/functional/version_spec.rb +1 -1
  127. data/spec/functional/win32/service_manager_spec.rb +1 -1
  128. data/spec/integration/recipes/accumulator_spec.rb +1 -1
  129. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +2 -2
  130. data/spec/integration/recipes/lwrp_spec.rb +1 -1
  131. data/spec/integration/recipes/notifies_spec.rb +1 -1
  132. data/spec/integration/recipes/notifying_block_spec.rb +1 -1
  133. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  134. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +2 -0
  135. data/spec/integration/recipes/resource_load_spec.rb +1 -0
  136. data/spec/integration/recipes/unified_mode_spec.rb +1 -1
  137. data/spec/scripts/ssl-serve.rb +1 -1
  138. data/spec/spec_helper.rb +26 -19
  139. data/spec/support/chef_helpers.rb +1 -1
  140. data/spec/support/platform_helpers.rb +12 -42
  141. data/spec/support/platforms/win32/spec_service.rb +1 -1
  142. data/spec/support/shared/functional/directory_resource.rb +1 -1
  143. data/spec/support/shared/functional/execute_resource.rb +1 -1
  144. data/spec/support/shared/functional/file_resource.rb +3 -3
  145. data/spec/support/shared/functional/win32_service.rb +1 -1
  146. data/spec/support/shared/functional/windows_script.rb +3 -3
  147. data/spec/support/shared/integration/knife_support.rb +2 -5
  148. data/spec/unit/application_spec.rb +7 -0
  149. data/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb +2 -4
  150. data/spec/unit/cookbook/gem_installer_spec.rb +2 -1
  151. data/spec/unit/data_bag_spec.rb +1 -1
  152. data/spec/unit/data_collector_spec.rb +1 -1
  153. data/spec/unit/dsl/platform_introspection_spec.rb +1 -0
  154. data/spec/unit/environment_spec.rb +7 -7
  155. data/spec/unit/event_dispatch/dispatcher_spec.rb +3 -0
  156. data/spec/unit/file_access_control_spec.rb +1 -1
  157. data/spec/unit/json_compat_spec.rb +1 -1
  158. data/spec/unit/knife/bootstrap_spec.rb +26 -29
  159. data/spec/unit/knife/cookbook_download_spec.rb +4 -4
  160. data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +1 -1
  161. data/spec/unit/knife/cookbook_upload_spec.rb +5 -6
  162. data/spec/unit/knife/core/hashed_command_loader_spec.rb +3 -3
  163. data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +6 -0
  164. data/spec/unit/knife/role_env_run_list_add_spec.rb +6 -6
  165. data/spec/unit/knife/role_env_run_list_clear_spec.rb +4 -4
  166. data/spec/unit/knife/role_env_run_list_remove_spec.rb +4 -4
  167. data/spec/unit/knife/role_env_run_list_replace_spec.rb +4 -4
  168. data/spec/unit/knife/role_env_run_list_set_spec.rb +4 -4
  169. data/spec/unit/knife/role_run_list_add_spec.rb +6 -6
  170. data/spec/unit/knife/role_run_list_clear_spec.rb +4 -4
  171. data/spec/unit/knife/role_run_list_remove_spec.rb +4 -4
  172. data/spec/unit/knife/role_run_list_replace_spec.rb +4 -4
  173. data/spec/unit/knife/role_run_list_set_spec.rb +4 -4
  174. data/spec/unit/knife/ssh_spec.rb +2 -2
  175. data/spec/unit/knife/supermarket_share_spec.rb +1 -1
  176. data/spec/unit/lwrp_spec.rb +4 -4
  177. data/spec/unit/mixin/securable_spec.rb +0 -1
  178. data/spec/unit/mixin/user_context_spec.rb +1 -9
  179. data/spec/unit/property_spec.rb +6 -6
  180. data/spec/unit/provider/apt_repository_spec.rb +2 -2
  181. data/spec/unit/provider/git_spec.rb +3 -3
  182. data/spec/unit/provider/osx_profile_spec.rb +2 -2
  183. data/spec/unit/provider/package/chocolatey_spec.rb +1 -1
  184. data/spec/unit/provider/package/dnf/python_helper_spec.rb +1 -1
  185. data/spec/unit/provider/package/msu_spec.rb +3 -3
  186. data/spec/unit/provider/package/powershell_spec.rb +95 -86
  187. data/spec/unit/provider/package/rubygems_spec.rb +5 -10
  188. data/spec/unit/provider/package/snap_spec.rb +1 -1
  189. data/spec/unit/provider/package/windows_spec.rb +30 -53
  190. data/spec/unit/provider/service/arch_service_spec.rb +3 -2
  191. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  192. data/spec/unit/provider/service/gentoo_service_spec.rb +8 -8
  193. data/spec/unit/provider/service/macosx_spec.rb +3 -3
  194. data/spec/unit/provider/service/redhat_spec.rb +2 -2
  195. data/spec/unit/provider/service/upstart_service_spec.rb +3 -3
  196. data/spec/unit/provider/service/windows_spec.rb +2 -6
  197. data/spec/unit/provider/systemd_unit_spec.rb +28 -24
  198. data/spec/unit/provider/zypper_repository_spec.rb +75 -25
  199. data/spec/unit/provider_resolver_spec.rb +9 -9
  200. data/spec/unit/provider_spec.rb +1 -0
  201. data/spec/unit/resource/archive_file_spec.rb +11 -2
  202. data/spec/unit/resource/msu_package_spec.rb +4 -0
  203. data/spec/unit/resource/windows_dns_record_spec.rb +3 -3
  204. data/spec/unit/resource/windows_dns_zone_spec.rb +2 -2
  205. data/spec/unit/resource/windows_feature_powershell_spec.rb +30 -4
  206. data/spec/unit/resource/windows_package_spec.rb +1 -0
  207. data/spec/unit/resource/windows_task_spec.rb +1 -1
  208. data/spec/unit/resource/windows_uac_spec.rb +2 -2
  209. data/spec/unit/resource/yum_repository_spec.rb +21 -21
  210. data/spec/unit/resource_reporter_spec.rb +1 -1
  211. data/spec/unit/resource_spec.rb +1 -1
  212. data/spec/unit/role_spec.rb +11 -11
  213. data/spec/unit/run_context/cookbook_compiler_spec.rb +1 -1
  214. data/spec/unit/run_context_spec.rb +1 -1
  215. data/spec/unit/run_lock_spec.rb +1 -1
  216. data/spec/unit/scan_access_control_spec.rb +1 -1
  217. data/spec/unit/util/threaded_job_queue_spec.rb +9 -0
  218. data/spec/unit/win32/security_spec.rb +4 -3
  219. data/tasks/rspec.rb +5 -13
  220. metadata +32 -18
@@ -613,6 +613,7 @@ class Chef
613
613
  # Do NOT use this. It may be removed. It is for internal purposes only.
614
614
  # @api private
615
615
  attr_reader :resource_initializing
616
+
616
617
  def resource_initializing=(value)
617
618
  if value
618
619
  @resource_initializing = true
@@ -863,6 +864,7 @@ class Chef
863
864
  # have.
864
865
  #
865
866
  attr_writer :allowed_actions
867
+
866
868
  def allowed_actions(value = NOT_PASSED)
867
869
  if value != NOT_PASSED
868
870
  self.allowed_actions = value
@@ -19,6 +19,7 @@
19
19
  #
20
20
 
21
21
  require_relative "../resource"
22
+ require "fileutils" unless defined?(FileUtils)
22
23
 
23
24
  class Chef
24
25
  class Resource
@@ -38,6 +39,18 @@ class Chef
38
39
  destination '/srv/files'
39
40
  end
40
41
  ```
42
+
43
+ **Set specific permissions on the extracted files**:
44
+
45
+ ```ruby
46
+ archive_file 'Precompiled.zip' do
47
+ owner 'tsmith'
48
+ group 'staff'
49
+ mode '700'
50
+ path '/tmp/Precompiled.zip'
51
+ destination '/srv/files'
52
+ end
53
+ ```
41
54
  DOC
42
55
 
43
56
  property :path, String,
@@ -52,7 +65,7 @@ class Chef
52
65
  description: "The group of the extracted files."
53
66
 
54
67
  property :mode, [String, Integer],
55
- description: "The mode of the extracted files.",
68
+ description: "The mode of the extracted files. Integer values are deprecated as octal values (ex. 0755) would not be interpreted correctly.",
56
69
  default: "755"
57
70
 
58
71
  property :destination, String,
@@ -71,11 +84,11 @@ class Chef
71
84
  alias_method :extract_options, :options
72
85
  alias_method :extract_to, :destination
73
86
 
74
- require "fileutils" unless defined?(FileUtils)
75
-
76
87
  action :extract do
77
88
  description "Extract and archive file."
78
89
 
90
+ require_libarchive
91
+
79
92
  unless ::File.exist?(new_resource.path)
80
93
  raise Errno::ENOENT, "No archive found at #{new_resource.path}! Cannot continue."
81
94
  end
@@ -84,7 +97,8 @@ class Chef
84
97
  Chef::Log.trace("File or directory does not exist at destination path: #{new_resource.destination}")
85
98
 
86
99
  converge_by("create directory #{new_resource.destination}") do
87
- FileUtils.mkdir_p(new_resource.destination, mode: new_resource.mode.to_i)
100
+ # @todo when we remove the ability for mode to be an int we can remove the .to_s below
101
+ FileUtils.mkdir_p(new_resource.destination, mode: new_resource.mode.to_s.to_i(8))
88
102
  end
89
103
 
90
104
  extract(new_resource.path, new_resource.destination, Array(new_resource.options))
@@ -112,6 +126,16 @@ class Chef
112
126
  end
113
127
 
114
128
  action_class do
129
+ def require_libarchive
130
+ require "ffi-libarchive"
131
+ end
132
+
133
+ def define_resource_requirements
134
+ if new_resource.mode.is_a?(Integer)
135
+ Chef.deprecated(:archive_file_integer_file_mode, "The mode property should be passed to archive_file resources as a String and not an Integer to ensure the value is properly interpreted.")
136
+ end
137
+ end
138
+
115
139
  # This can't be a constant since we might not have required 'ffi-libarchive' yet.
116
140
  def extract_option_map
117
141
  {
@@ -135,8 +159,6 @@ class Chef
135
159
  #
136
160
  # @return [Boolean]
137
161
  def archive_differs_from_disk?(src, dest)
138
- require "ffi-libarchive"
139
-
140
162
  modified = false
141
163
  Dir.chdir(dest) do
142
164
  archive = Archive::Reader.open_filename(src)
@@ -163,8 +185,6 @@ class Chef
163
185
  #
164
186
  # @return [void]
165
187
  def extract(src, dest, options = [])
166
- require "ffi-libarchive"
167
-
168
188
  converge_by("extract #{src} to #{dest}") do
169
189
  flags = [options].flatten.map { |option| extract_option_map[option] }.compact.reduce(:|)
170
190
 
@@ -60,7 +60,7 @@ class Chef
60
60
  when fedora_derived?
61
61
  package %w{ autoconf bison flex gcc gcc-c++ gettext kernel-devel make m4 ncurses-devel patch }
62
62
 
63
- # Ensure GCC 4 is available on older pre-6 EL
63
+ # Ensure GCC 4 is available on older pre-6 EL
64
64
  package %w{ gcc44 gcc44-c++ } if platform_family?("rhel") && node["platform_version"].to_i < 6
65
65
  when freebsd?
66
66
  package "devel/gmake"
@@ -27,7 +27,7 @@ class Chef
27
27
  provides(:cron_manage) # legacy name @todo in Chef 15 we should { true } this so it wins over the cookbook
28
28
 
29
29
  introduced "14.4"
30
- description "Use the cron_access resource to manage the /etc/cron.allow and /etc/cron.deny files."
30
+ description "Use the **cron_access** resource to manage cron's cron.allow and cron.deny files. Note: This resource previously shipped in the `cron` cookbook as `cron_manage`, which it can still be used as for backwards compatibility with existing Chef Infra Client releases."
31
31
  examples <<~DOC
32
32
  Add the mike user to cron.allow
33
33
  ```ruby
@@ -54,12 +54,19 @@ class Chef
54
54
  description: "An optional property to set the user name if it differs from the resource block's name.",
55
55
  name_property: true
56
56
 
57
+ CRON_PATHS = {
58
+ "aix" => "/var/adm/cron",
59
+ "solaris" => "/etc/cron.d",
60
+ "default" => "/etc",
61
+ }.freeze
62
+
57
63
  action :allow do
58
64
  description "Add the user to the cron.allow file."
65
+ allow_path = ::File.join(value_for_platform_family(CRON_PATHS), "cron.allow")
59
66
 
60
67
  with_run_context :root do
61
- edit_resource(:template, "/etc/cron.allow") do |new_resource|
62
- source ::File.expand_path("../support/cron_access.erb", __FILE__)
68
+ edit_resource(:template, allow_path) do |new_resource|
69
+ source ::File.expand_path("support/cron_access.erb", __dir__)
63
70
  local true
64
71
  mode "0600"
65
72
  variables["users"] ||= []
@@ -72,10 +79,11 @@ class Chef
72
79
 
73
80
  action :deny do
74
81
  description "Add the user to the cron.deny file."
82
+ deny_path = ::File.join(value_for_platform_family(CRON_PATHS), "cron.deny")
75
83
 
76
84
  with_run_context :root do
77
- edit_resource(:template, "/etc/cron.deny") do |new_resource|
78
- source ::File.expand_path("../support/cron_access.erb", __FILE__)
85
+ edit_resource(:template, deny_path) do |new_resource|
86
+ source ::File.expand_path("support/cron_access.erb", __dir__)
79
87
  local true
80
88
  mode "0600"
81
89
  variables["users"] ||= []
@@ -289,7 +289,7 @@ class Chef
289
289
 
290
290
  # @todo this is Chef 12 era cleanup. Someday we should remove it all
291
291
  template "/etc/cron.d/#{sanitized_name}" do
292
- source ::File.expand_path("../support/cron.d.erb", __FILE__)
292
+ source ::File.expand_path("support/cron.d.erb", __dir__)
293
293
  local true
294
294
  mode new_resource.mode
295
295
  variables(
@@ -13,6 +13,7 @@
13
13
  #
14
14
 
15
15
  require_relative "../resource"
16
+ require_relative "../dist"
16
17
 
17
18
  class Chef
18
19
  class Resource
@@ -66,8 +67,7 @@ class Chef
66
67
  def updated_ec2_config_xml
67
68
  begin
68
69
  require "rexml/document" unless defined?(REXML::Document)
69
- config_file = 'C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml'
70
- config = REXML::Document.new(::File.read(config_file))
70
+ config = REXML::Document.new(::File.read(WINDOWS_EC2_CONFIG))
71
71
  # find an element named State with a sibling element whose value is Ec2SetComputerName
72
72
  REXML::XPath.each(config, "//Plugin/State[../Name/text() = 'Ec2SetComputerName']") do |element|
73
73
  element.text = "Disabled"
@@ -219,35 +219,36 @@ class Chef
219
219
  end
220
220
 
221
221
  else # windows
222
+ WINDOWS_EC2_CONFIG = 'C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml'.freeze
223
+
222
224
  raise "Windows hostnames cannot contain a period." if new_resource.hostname.match?(/\./)
223
225
 
224
226
  # suppress EC2 config service from setting our hostname
225
- if ::File.exist?('C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml')
227
+ if ::File.exist?(WINDOWS_EC2_CONFIG)
226
228
  xml_contents = updated_ec2_config_xml
227
229
  if xml_contents.empty?
228
230
  Chef::Log.warn('Unable to properly parse and update C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml contents. Skipping file update.')
229
231
  else
230
- declare_resource(:file, 'C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml') do
232
+ file WINDOWS_EC2_CONFIG do
231
233
  content xml_contents
232
234
  end
233
235
  end
234
236
  end
235
237
 
236
- # update via netdom
237
- declare_resource(:powershell_script, "set hostname") do
238
- code <<-EOH
239
- $sysInfo = Get-WmiObject -Class Win32_ComputerSystem
240
- $sysInfo.Rename("#{new_resource.hostname}")
241
- EOH
242
- notifies :request_reboot, "reboot[setting hostname]"
243
- not_if { Socket.gethostbyname(Socket.gethostname).first == new_resource.hostname }
244
- end
238
+ unless Socket.gethostbyname(Socket.gethostname).first == new_resource.hostname
239
+ converge_by "set hostname to #{new_resource.hostname}" do
240
+ powershell_out! <<~EOH
241
+ $sysInfo = Get-WmiObject -Class Win32_ComputerSystem
242
+ $sysInfo.Rename("#{new_resource.hostname}")
243
+ EOH
244
+ end
245
245
 
246
- # reboot because $windows
247
- declare_resource(:reboot, "setting hostname") do
248
- reason "chef setting hostname"
249
- action :nothing
250
- only_if { new_resource.windows_reboot }
246
+ # reboot because $windows
247
+ reboot "setting hostname" do
248
+ reason "#{Chef::Dist::PRODUCT} updated system hostname"
249
+ only_if { new_resource.windows_reboot }
250
+ action :request_reboot
251
+ end
251
252
  end
252
253
  end
253
254
  end
@@ -76,20 +76,20 @@ class Chef
76
76
  property :start_calendar_interval, [Hash, Array],
77
77
  description: "A Hash (similar to crontab) that defines the calendar frequency at which a job is started or an Array.",
78
78
  coerce: proc { |type|
79
- # Coerce into an array of hashes to make validation easier
79
+ # Coerce into an array of hashes to make validation easier
80
80
  array = if type.is_a?(Array)
81
81
  type
82
82
  else
83
83
  [type]
84
84
  end
85
85
 
86
- # Check to make sure that our array only has hashes
86
+ # Check to make sure that our array only has hashes
87
87
  unless array.all? { |obj| obj.is_a?(Hash) }
88
88
  error_msg = "start_calendar_interval must be a single hash or an array of hashes!"
89
89
  raise Chef::Exceptions::ValidationFailed, error_msg
90
90
  end
91
91
 
92
- # Make sure the hashes don't have any incorrect keys/values
92
+ # Make sure the hashes don't have any incorrect keys/values
93
93
  array.each do |entry|
94
94
  allowed_keys = %w{Minute Hour Day Weekday Month}
95
95
  unless entry.keys.all? { |key| allowed_keys.include?(key) }
@@ -105,7 +105,7 @@ class Chef
105
105
  end
106
106
  end
107
107
 
108
- # Don't return array if we only have one entry
108
+ # Don't return array if we only have one entry
109
109
  if array.size == 1
110
110
  array.first
111
111
  else
@@ -65,6 +65,12 @@ class Chef
65
65
 
66
66
  LWRPBase.loaded_lwrps[filename] = true
67
67
 
68
+ unless resource_class.resource_name.nil?
69
+ if Chef.resource_handler_map.get(node, resource_class.resource_name, canonical: true) == resource_class
70
+ Chef.deprecated(:resource_name_without_provides, "Resource #{resource_class.resource_name} needs `provides :#{resource_class.resource_name}` in addition to `resource_name :#{resource_class.resource_name}` declaration")
71
+ end
72
+ end
73
+
68
74
  # wire up the default resource name after the class is parsed only if we haven't declared one.
69
75
  # (this ordering is important for MapCollision deprecation warnings)
70
76
  resource_class.resource_name resource_name.to_sym if resource_class.resource_name.nil?
@@ -103,6 +109,7 @@ class Chef
103
109
  protected
104
110
 
105
111
  attr_writer :loaded_lwrps
112
+
106
113
  def loaded_lwrps
107
114
  @loaded_lwrps ||= {}
108
115
  end
@@ -61,9 +61,9 @@ class Chef
61
61
  desired_state: false,
62
62
  skip_docs: true
63
63
 
64
- # coerce various ways of representing a boolean into either 0 (false) or 1 (true)
65
- # which is what the defaults CLI expects. Why? Well defaults itself accepts a few
66
- # different formats, but when you do a read command it all comes back as 1 or 0.
64
+ # coerce various ways of representing a boolean into either 0 (false) or 1 (true)
65
+ # which is what the defaults CLI expects. Why? Well defaults itself accepts a few
66
+ # different formats, but when you do a read command it all comes back as 1 or 0.
67
67
  def coerce_booleans(val)
68
68
  return 1 if [true, "TRUE", "1", "true", "YES", "yes"].include?(val)
69
69
  return 0 if [false, "FALSE", "0", "false", "NO", "no"].include?(val)
@@ -44,6 +44,11 @@ class Chef
44
44
 
45
45
  property :checksum, String, desired_state: false,
46
46
  description: "SHA-256 digest used to verify the checksum of the downloaded MSU package."
47
+
48
+ property :timeout, [String, Integer],
49
+ default: 3600,
50
+ description: "The amount of time (in seconds) to wait before timing out.",
51
+ desired_state: false
47
52
  end
48
53
  end
49
54
  end
@@ -88,7 +88,7 @@ class Chef
88
88
 
89
89
  r = with_run_context :root do
90
90
  find_resource(:template, "update ssh known hosts file #{new_resource.file_location}") do
91
- source ::File.expand_path("../support/ssh_known_hosts.erb", __FILE__)
91
+ source ::File.expand_path("support/ssh_known_hosts.erb", __dir__)
92
92
  local true
93
93
  path new_resource.file_location
94
94
  owner new_resource.owner
@@ -172,7 +172,7 @@ class Chef
172
172
  end
173
173
  else
174
174
  declare_resource(:template, file_path) do
175
- source ::File.expand_path("../support/sudoer.erb", __FILE__)
175
+ source ::File.expand_path("support/sudoer.erb", __dir__)
176
176
  local true
177
177
  mode "0440"
178
178
  variables sudoer: (new_resource.groups + new_resource.users).join(","),
@@ -228,7 +228,7 @@ class Chef
228
228
  end
229
229
 
230
230
  def visudo_content(path)
231
- if ::File.exists?(path)
231
+ if ::File.exist?(path)
232
232
  "cat #{new_resource.config_prefix}/sudoers | #{new_resource.visudo_binary} -cf - && #{new_resource.visudo_binary} -cf %{path}"
233
233
  else
234
234
  "cat #{new_resource.config_prefix}/sudoers %{path} | #{new_resource.visudo_binary} -cf -"
@@ -163,8 +163,12 @@ class Chef
163
163
 
164
164
  # @return [Array] features the user has requested to install which need installation
165
165
  def features_to_install
166
- # the intersection of the features to install & disabled features are what needs installing
167
- @install ||= new_resource.feature_name & node["powershell_features_cache"]["disabled"]
166
+ # the intersection of the features to install & disabled/removed features are what needs installing
167
+ @features_to_install ||= begin
168
+ features = node["powershell_features_cache"]["disabled"]
169
+ features |= node["powershell_features_cache"]["removed"] if new_resource.source
170
+ new_resource.feature_name & features
171
+ end
168
172
  end
169
173
 
170
174
  # @return [Array] features the user has requested to remove which need removing
@@ -41,7 +41,7 @@ class Chef
41
41
  description: "The local address the firewall rule applies to."
42
42
 
43
43
  property :local_port, [String, Integer, Array],
44
- # split various formats of comma separated lists and provide a sorted array of strings to match PS output
44
+ # split various formats of comma separated lists and provide a sorted array of strings to match PS output
45
45
  coerce: proc { |d| d.is_a?(String) ? d.split(/\s*,\s*/).sort : Array(d).sort.map(&:to_s) },
46
46
  description: "The local port the firewall rule applies to."
47
47
 
@@ -49,7 +49,7 @@ class Chef
49
49
  description: "The remote address the firewall rule applies to."
50
50
 
51
51
  property :remote_port, [String, Integer, Array],
52
- # split various formats of comma separated lists and provide a sorted array of strings to match PS output
52
+ # split various formats of comma separated lists and provide a sorted array of strings to match PS output
53
53
  coerce: proc { |d| d.is_a?(String) ? d.split(/\s*,\s*/).sort : Array(d).sort.map(&:to_s) },
54
54
  description: "The remote port the firewall rule applies to."
55
55
 
@@ -72,7 +72,7 @@ class Chef
72
72
  description: "The profile the firewall rule applies to.",
73
73
  coerce: proc { |p| Array(p).map(&:downcase).map(&:to_sym).sort },
74
74
  callbacks: {
75
- "contains values not in :public, :private :domain, :any or :notapplicable" => lambda { |p|
75
+ "contains values not in :public, :private, :domain, :any or :notapplicable" => lambda { |p|
76
76
  p.all? { |e| %i{public private domain any notapplicable}.include?(e) }
77
77
  },
78
78
  }
@@ -106,6 +106,10 @@ class Chef
106
106
  else
107
107
  state = Chef::JSONCompat.from_json(output.stdout)
108
108
  end
109
+
110
+ # Need to reverse `$rule.Profile.ToString()` in powershell command
111
+ current_profiles = state["profile"].split(", ").map(&:to_sym)
112
+
109
113
  local_address state["local_address"]
110
114
  local_port Array(state["local_port"]).sort
111
115
  remote_address state["remote_address"]
@@ -113,7 +117,7 @@ class Chef
113
117
  direction state["direction"]
114
118
  protocol state["protocol"]
115
119
  firewall_action state["firewall_action"]
116
- profile state["profile"]
120
+ profile current_profiles
117
121
  program state["program"]
118
122
  service state["service"]
119
123
  interface_type state["interface_type"]
@@ -90,8 +90,9 @@ class Chef
90
90
  def font_exists?
91
91
  require "win32ole" if RUBY_PLATFORM =~ /mswin|mingw32|windows/
92
92
  fonts_dir = WIN32OLE.new("WScript.Shell").SpecialFolders("Fonts")
93
+ fonts_dir_local = Chef::Util::PathHelper.join(ENV["home"], "AppData/Local/Microsoft/Windows/fonts")
93
94
  logger.trace("Seeing if the font at #{Chef::Util::PathHelper.join(fonts_dir, new_resource.font_name)} exists")
94
- ::File.exist?(Chef::Util::PathHelper.join(fonts_dir, new_resource.font_name))
95
+ ::File.exist?(Chef::Util::PathHelper.join(fonts_dir, new_resource.font_name)) || ::File.exist?(Chef::Util::PathHelper.join(fonts_dir_local, new_resource.font_name))
95
96
  end
96
97
 
97
98
  # Parse out the schema provided to us to see if it's one we support via remote_file.
@@ -149,8 +149,8 @@ class Chef
149
149
  raise "The windows_share resource relies on PowerShell cmdlets not present in Windows releases prior to 8/2012. Cannot continue!" if node["platform_version"].to_f < 6.3
150
150
  end
151
151
 
152
- # given the string output of Get-SmbShareAccess parse out
153
- # arrays of full access users, change users, and read only users
152
+ # given the string output of Get-SmbShareAccess parse out
153
+ # arrays of full access users, change users, and read only users
154
154
  def parse_permissions(results_string)
155
155
  json_results = Chef::JSONCompat.from_json(results_string)
156
156
  json_results = [json_results] unless json_results.is_a?(Array) # single result is not an array
@@ -171,8 +171,8 @@ class Chef
171
171
  [f_users, c_users, r_users]
172
172
  end
173
173
 
174
- # local names are returned from Get-SmbShareAccess in the full format MACHINE\\NAME
175
- # but users of this resource would simply say NAME so we need to strip the values for comparison
174
+ # local names are returned from Get-SmbShareAccess in the full format MACHINE\\NAME
175
+ # but users of this resource would simply say NAME so we need to strip the values for comparison
176
176
  def stripped_account(name)
177
177
  name.slice!("#{node["hostname"]}\\")
178
178
  name
@@ -159,16 +159,16 @@ class Chef
159
159
 
160
160
  private
161
161
 
162
- ## Resource is not idempotent when day, start_day is not provided with frequency :weekly
163
- ## we set start_day when not given by user as current date based on which we set the day property for current current date day is monday ..
164
- ## we set the monday as the day so at next run when new_resource.day is nil and current_resource day is monday due to which udpate gets called
162
+ ## Resource is not idempotent when day, start_day is not provided with frequency :weekly
163
+ ## we set start_day when not given by user as current date based on which we set the day property for current current date day is monday ..
164
+ ## we set the monday as the day so at next run when new_resource.day is nil and current_resource day is monday due to which udpate gets called
165
165
  def idempotency_warning_for_frequency_weekly(day, start_day)
166
166
  if start_day.nil? && day.nil?
167
167
  logger.warn "To maintain idempotency for frequency :weekly provide start_day, start_time and day."
168
168
  end
169
169
  end
170
170
 
171
- # Validate the passed value is numeric values only if it is a string
171
+ # Validate the passed value is numeric values only if it is a string
172
172
  def numeric_value_in_string?(val)
173
173
  return true if Integer(val)
174
174
  rescue ArgumentError
@@ -194,7 +194,7 @@ class Chef
194
194
  end
195
195
  end
196
196
 
197
- # returns true if frequency_modifer has values First, second, third, fourth, last, lastday
197
+ # returns true if frequency_modifer has values First, second, third, fourth, last, lastday
198
198
  def frequency_modifier_includes_days_of_weeks?(frequency_modifier)
199
199
  frequency_modifier = frequency_modifier.to_s.split(",")
200
200
  frequency_modifier.map! { |value| value.strip.upcase }
@@ -209,7 +209,7 @@ class Chef
209
209
  raise ArgumentError, "Invalid value passed for `random_delay`. Please pass seconds as an Integer (e.g. 60) or a String with numeric values only (e.g. '60')." unless numeric_value_in_string?(random_delay)
210
210
  end
211
211
 
212
- # @todo when we drop ruby 2.3 support this should be converted to .match?() instead of =~f
212
+ # @todo when we drop ruby 2.3 support this should be converted to .match?() instead of =~f
213
213
  def validate_start_day(start_day, frequency)
214
214
  if start_day && frequency == :none
215
215
  raise ArgumentError, "`start_day` property is not supported with frequency: #{frequency}"
@@ -221,7 +221,7 @@ class Chef
221
221
  end
222
222
  end
223
223
 
224
- # @todo when we drop ruby 2.3 support this should be converted to .match?() instead of =~
224
+ # @todo when we drop ruby 2.3 support this should be converted to .match?() instead of =~
225
225
  def validate_start_time(start_time, frequency)
226
226
  if start_time
227
227
  raise ArgumentError, "`start_time` property is not supported with `frequency :none`" if frequency == :none
@@ -321,7 +321,7 @@ class Chef
321
321
  end
322
322
  end
323
323
 
324
- # This method returns true if day has values from 1-31 which is a days of moths and used with frequency :monthly
324
+ # This method returns true if day has values from 1-31 which is a days of moths and used with frequency :monthly
325
325
  def days_includes_days_of_months?(days)
326
326
  days.map! { |day| day.to_s.strip.downcase }
327
327
  (days - VALID_DAYS_OF_MONTH).empty?
@@ -339,11 +339,11 @@ class Chef
339
339
  end
340
340
  end
341
341
 
342
- # Converts the number of seconds to an ISO8601 duration format and returns it.
343
- # Ref : https://github.com/arnau/ISO8601/blob/master/lib/iso8601/duration.rb#L18-L23
344
- # e.g.
345
- # ISO8601::Duration.new(65707200).to_s
346
- # returns 'PT65707200S'
342
+ # Converts the number of seconds to an ISO8601 duration format and returns it.
343
+ # Ref : https://github.com/arnau/ISO8601/blob/master/lib/iso8601/duration.rb#L18-L23
344
+ # e.g.
345
+ # ISO8601::Duration.new(65707200).to_s
346
+ # returns 'PT65707200S'
347
347
  def sec_to_dur(seconds)
348
348
  ISO8601::Duration.new(seconds.to_i).to_s
349
349
  end