chef 15.4.45 → 15.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (244) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -3
  3. data/Rakefile +5 -3
  4. data/chef.gemspec +2 -1
  5. data/lib/chef/application.rb +2 -2
  6. data/lib/chef/application/client.rb +1 -1
  7. data/lib/chef/application/knife.rb +1 -0
  8. data/lib/chef/application/solo.rb +1 -1
  9. data/lib/chef/chef_class.rb +1 -6
  10. data/lib/chef/chef_fs.rb +1 -1
  11. data/lib/chef/chef_fs/file_pattern.rb +1 -1
  12. data/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb +2 -2
  13. data/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb +2 -2
  14. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_artifact_dir.rb +1 -1
  15. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +7 -1
  16. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +4 -3
  17. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +3 -3
  18. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_versioned_cookbook_dir.rb +1 -1
  19. data/lib/chef/chef_fs/file_system/repository/nodes_dir.rb +3 -3
  20. data/lib/chef/chef_fs/knife.rb +1 -1
  21. data/lib/chef/chef_fs/path_utils.rb +2 -2
  22. data/lib/chef/client.rb +4 -5
  23. data/lib/chef/config.rb +3 -2
  24. data/lib/chef/cookbook/chefignore.rb +16 -11
  25. data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
  26. data/lib/chef/cookbook/syntax_check.rb +5 -3
  27. data/lib/chef/cookbook_loader.rb +3 -3
  28. data/lib/chef/cookbook_uploader.rb +1 -1
  29. data/lib/chef/data_collector.rb +2 -2
  30. data/lib/chef/data_collector/run_end_message.rb +1 -0
  31. data/lib/chef/deprecated.rb +4 -0
  32. data/lib/chef/dsl/core.rb +1 -1
  33. data/lib/chef/dsl/platform_introspection.rb +9 -18
  34. data/lib/chef/event_loggers/windows_eventlog.rb +1 -1
  35. data/lib/chef/file_content_management/deploy.rb +3 -3
  36. data/lib/chef/file_content_management/deploy/mv_windows.rb +2 -2
  37. data/lib/chef/file_content_management/tempfile.rb +1 -1
  38. data/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +2 -2
  39. data/lib/chef/http.rb +1 -1
  40. data/lib/chef/http/socketless_chef_zero_client.rb +1 -1
  41. data/lib/chef/knife.rb +4 -3
  42. data/lib/chef/knife/config_get.rb +2 -1
  43. data/lib/chef/knife/configure.rb +1 -1
  44. data/lib/chef/knife/cookbook_metadata_from_file.rb +6 -0
  45. data/lib/chef/knife/core/generic_presenter.rb +1 -1
  46. data/lib/chef/knife/core/status_presenter.rb +1 -1
  47. data/lib/chef/knife/ssh.rb +6 -0
  48. data/lib/chef/local_mode.rb +1 -1
  49. data/lib/chef/mash.rb +21 -232
  50. data/lib/chef/mixin/file_class.rb +2 -2
  51. data/lib/chef/mixin/lazy_module_include.rb +1 -1
  52. data/lib/chef/mixin/path_sanity.rb +3 -39
  53. data/lib/chef/mixin/securable.rb +1 -1
  54. data/lib/chef/mixin/shell_out.rb +4 -5
  55. data/lib/chef/mixin/template.rb +1 -1
  56. data/lib/chef/mixin/user_context.rb +3 -3
  57. data/lib/chef/mixin/which.rb +10 -38
  58. data/lib/chef/mixin/windows_architecture_helper.rb +6 -6
  59. data/lib/chef/mixin/windows_env_helper.rb +5 -5
  60. data/lib/chef/node/attribute.rb +2 -2
  61. data/lib/chef/node_map.rb +17 -4
  62. data/lib/chef/platform/query_helpers.rb +4 -2
  63. data/lib/chef/platform/rebooter.rb +1 -1
  64. data/lib/chef/platform/service_helpers.rb +14 -85
  65. data/lib/chef/provider.rb +2 -0
  66. data/lib/chef/provider/file.rb +2 -2
  67. data/lib/chef/provider/ifconfig/redhat.rb +1 -1
  68. data/lib/chef/provider/link.rb +3 -3
  69. data/lib/chef/provider/mount/solaris.rb +1 -1
  70. data/lib/chef/provider/package/yum.rb +1 -1
  71. data/lib/chef/provider/registry_key.rb +1 -1
  72. data/lib/chef/provider/remote_directory.rb +3 -3
  73. data/lib/chef/provider/remote_file/fetcher.rb +2 -2
  74. data/lib/chef/provider/remote_file/local_file.rb +1 -1
  75. data/lib/chef/provider/script.rb +3 -3
  76. data/lib/chef/provider/service.rb +5 -2
  77. data/lib/chef/provider/service/arch.rb +1 -1
  78. data/lib/chef/provider/service/debian.rb +4 -4
  79. data/lib/chef/provider/service/init.rb +1 -1
  80. data/lib/chef/provider/service/insserv.rb +4 -4
  81. data/lib/chef/provider/service/invokercd.rb +4 -4
  82. data/lib/chef/provider/service/redhat.rb +4 -4
  83. data/lib/chef/provider/service/systemd.rb +19 -3
  84. data/lib/chef/provider/service/upstart.rb +3 -3
  85. data/lib/chef/provider/subversion.rb +1 -1
  86. data/lib/chef/provider/systemd_unit.rb +26 -2
  87. data/lib/chef/provider/windows_path.rb +3 -3
  88. data/lib/chef/provider/windows_task.rb +4 -4
  89. data/lib/chef/resource.rb +1 -0
  90. data/lib/chef/resource/bash.rb +2 -0
  91. data/lib/chef/resource/batch.rb +2 -0
  92. data/lib/chef/resource/breakpoint.rb +3 -1
  93. data/lib/chef/resource/build_essential.rb +3 -3
  94. data/lib/chef/resource/chef_sleep.rb +70 -0
  95. data/lib/chef/resource/cookbook_file.rb +2 -1
  96. data/lib/chef/resource/csh.rb +2 -0
  97. data/lib/chef/resource/directory.rb +2 -0
  98. data/lib/chef/resource/dmg_package.rb +1 -1
  99. data/lib/chef/resource/dnf_package.rb +1 -1
  100. data/lib/chef/resource/execute.rb +2 -0
  101. data/lib/chef/resource/file.rb +2 -1
  102. data/lib/chef/resource/git.rb +2 -0
  103. data/lib/chef/resource/group.rb +1 -1
  104. data/lib/chef/resource/homebrew_package.rb +1 -1
  105. data/lib/chef/resource/http_request.rb +2 -0
  106. data/lib/chef/resource/ifconfig.rb +3 -1
  107. data/lib/chef/resource/ksh.rb +2 -0
  108. data/lib/chef/resource/link.rb +4 -2
  109. data/lib/chef/resource/locale.rb +1 -1
  110. data/lib/chef/resource/log.rb +2 -0
  111. data/lib/chef/resource/ohai.rb +2 -0
  112. data/lib/chef/resource/perl.rb +2 -0
  113. data/lib/chef/resource/python.rb +2 -0
  114. data/lib/chef/resource/reboot.rb +2 -0
  115. data/lib/chef/resource/registry_key.rb +2 -0
  116. data/lib/chef/resource/remote_directory.rb +3 -2
  117. data/lib/chef/resource/remote_file.rb +1 -0
  118. data/lib/chef/resource/ruby.rb +2 -0
  119. data/lib/chef/resource/ruby_block.rb +2 -0
  120. data/lib/chef/resource/scm.rb +2 -0
  121. data/lib/chef/resource/script.rb +2 -0
  122. data/lib/chef/resource/service.rb +9 -1
  123. data/lib/chef/resource/solaris_package.rb +1 -1
  124. data/lib/chef/resource/subversion.rb +2 -0
  125. data/lib/chef/resource/sudo.rb +1 -1
  126. data/lib/chef/resource/systemd_unit.rb +1 -0
  127. data/lib/chef/resource/template.rb +2 -0
  128. data/lib/chef/resource/user.rb +2 -0
  129. data/lib/chef/resource/user/aix_user.rb +2 -0
  130. data/lib/chef/resource/user/linux_user.rb +2 -0
  131. data/lib/chef/resource/user/pw_user.rb +2 -0
  132. data/lib/chef/resource/user/solaris_user.rb +2 -0
  133. data/lib/chef/resource/user/windows_user.rb +2 -0
  134. data/lib/chef/resource/whyrun_safe_ruby_block.rb +1 -0
  135. data/lib/chef/resource/windows_ad_join.rb +1 -1
  136. data/lib/chef/resource/windows_env.rb +1 -1
  137. data/lib/chef/resource/windows_feature.rb +2 -2
  138. data/lib/chef/resource/windows_feature_powershell.rb +1 -1
  139. data/lib/chef/resource/windows_firewall_rule.rb +11 -6
  140. data/lib/chef/resource/windows_script.rb +3 -1
  141. data/lib/chef/resource/yum_package.rb +1 -1
  142. data/lib/chef/resource_reporter.rb +1 -1
  143. data/lib/chef/resources.rb +1 -0
  144. data/lib/chef/run_context.rb +1 -1
  145. data/lib/chef/run_lock.rb +5 -5
  146. data/lib/chef/search/query.rb +0 -3
  147. data/lib/chef/train_transport.rb +3 -1
  148. data/lib/chef/util/powershell/ps_credential.rb +2 -2
  149. data/lib/chef/util/selinux.rb +1 -1
  150. data/lib/chef/util/windows/logon_session.rb +2 -2
  151. data/lib/chef/version.rb +1 -1
  152. data/lib/chef/win32/eventlog.rb +2 -2
  153. data/spec/data/cookbooks/starter/chefignore +8 -0
  154. data/spec/data/cookbooks/starter/files/sample.txt +1 -0
  155. data/spec/data/cookbooks/starter/metadata.rb +2 -0
  156. data/spec/data/cookbooks/starter/recipes/default.rb +4 -0
  157. data/spec/functional/event_loggers/windows_eventlog_spec.rb +1 -1
  158. data/spec/functional/mixin/user_context_spec.rb +2 -2
  159. data/spec/functional/rebooter_spec.rb +1 -1
  160. data/spec/functional/resource/cookbook_file_spec.rb +2 -2
  161. data/spec/functional/resource/template_spec.rb +1 -1
  162. data/spec/functional/version_spec.rb +1 -1
  163. data/spec/functional/win32/crypto_spec.rb +1 -1
  164. data/spec/functional/win32/security_spec.rb +1 -1
  165. data/spec/functional/win32/service_manager_spec.rb +1 -1
  166. data/spec/functional/win32/sid_spec.rb +2 -2
  167. data/spec/functional/win32/version_info_spec.rb +1 -1
  168. data/spec/functional/win32/versions_spec.rb +1 -1
  169. data/spec/integration/knife/config_get_profile_spec.rb +2 -2
  170. data/spec/integration/knife/config_get_spec.rb +9 -2
  171. data/spec/integration/knife/config_list_profiles_spec.rb +2 -2
  172. data/spec/integration/knife/config_use_profile_spec.rb +2 -2
  173. data/spec/integration/knife/list_spec.rb +2 -2
  174. data/spec/integration/solo/solo_spec.rb +1 -1
  175. data/spec/support/matchers/leak.rb +1 -1
  176. data/spec/support/mock/platform.rb +1 -1
  177. data/spec/support/platform_helpers.rb +2 -0
  178. data/spec/support/shared/integration/integration_helper.rb +1 -1
  179. data/spec/support/shared/integration/knife_support.rb +1 -1
  180. data/spec/support/shared/unit/provider/file.rb +4 -4
  181. data/spec/unit/application/client_spec.rb +2 -2
  182. data/spec/unit/application/knife_spec.rb +17 -0
  183. data/spec/unit/application_spec.rb +1 -1
  184. data/spec/unit/chef_fs/file_pattern_spec.rb +2 -2
  185. data/spec/unit/chef_fs/path_util_spec.rb +3 -3
  186. data/spec/unit/client_spec.rb +2 -2
  187. data/spec/unit/cookbook/chefignore_spec.rb +31 -11
  188. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +1 -1
  189. data/spec/unit/cookbook/syntax_check_spec.rb +2 -2
  190. data/spec/unit/cookbook_loader_spec.rb +2 -2
  191. data/spec/unit/cookbook_uploader_spec.rb +6 -1
  192. data/spec/unit/data_bag_spec.rb +2 -2
  193. data/spec/unit/data_collector_spec.rb +7 -0
  194. data/spec/unit/dsl/platform_introspection_spec.rb +31 -1
  195. data/spec/unit/file_content_management/deploy/mv_windows_spec.rb +1 -1
  196. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +1 -1
  197. data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +7 -0
  198. data/spec/unit/knife/cookbook_show_spec.rb +1 -1
  199. data/spec/unit/knife/core/gem_glob_loader_spec.rb +1 -1
  200. data/spec/unit/knife/core/hashed_command_loader_spec.rb +1 -1
  201. data/spec/unit/knife/core/subcommand_loader_spec.rb +1 -1
  202. data/spec/unit/knife/core/ui_spec.rb +2 -2
  203. data/spec/unit/knife/data_bag_from_file_spec.rb +2 -2
  204. data/spec/unit/knife/environment_from_file_spec.rb +2 -2
  205. data/spec/unit/knife/ssh_spec.rb +27 -17
  206. data/spec/unit/knife/status_spec.rb +1 -1
  207. data/spec/unit/knife/supermarket_install_spec.rb +1 -1
  208. data/spec/unit/mixin/path_sanity_spec.rb +3 -3
  209. data/spec/unit/mixin/shell_out_spec.rb +2 -3
  210. data/spec/unit/mixin/template_spec.rb +4 -4
  211. data/spec/unit/mixin/user_context_spec.rb +3 -3
  212. data/spec/unit/node_map_spec.rb +12 -12
  213. data/spec/unit/platform/query_helpers_spec.rb +9 -9
  214. data/spec/unit/provider/execute_spec.rb +1 -1
  215. data/spec/unit/provider/link_spec.rb +5 -5
  216. data/spec/unit/provider/package/openbsd_spec.rb +1 -1
  217. data/spec/unit/provider/package/smartos_spec.rb +1 -1
  218. data/spec/unit/provider/package/windows/exe_spec.rb +1 -1
  219. data/spec/unit/provider/package/windows_spec.rb +2 -2
  220. data/spec/unit/provider/remote_file/fetcher_spec.rb +2 -2
  221. data/spec/unit/provider/remote_file/local_file_spec.rb +1 -1
  222. data/spec/unit/provider/remote_file/network_file_spec.rb +1 -1
  223. data/spec/unit/provider/script_spec.rb +2 -2
  224. data/spec/unit/provider/service/systemd_service_spec.rb +26 -2
  225. data/spec/unit/provider/subversion_spec.rb +3 -3
  226. data/spec/unit/provider/systemd_unit_spec.rb +53 -4
  227. data/spec/unit/provider/user/dscl_spec.rb +1 -1
  228. data/spec/unit/provider_resolver_spec.rb +41 -61
  229. data/spec/unit/resource/chef_sleep_spec.rb +30 -0
  230. data/spec/unit/resource/cookbook_file_spec.rb +3 -3
  231. data/spec/unit/resource/remote_file_spec.rb +3 -3
  232. data/spec/unit/resource/windows_firewall_rule_spec.rb +69 -12
  233. data/spec/unit/role_spec.rb +2 -2
  234. data/spec/unit/shell_spec.rb +1 -1
  235. data/spec/unit/util/selinux_spec.rb +2 -2
  236. data/spec/unit/win32/error_spec.rb +1 -1
  237. data/spec/unit/win32/link_spec.rb +1 -1
  238. data/spec/unit/win32/security_spec.rb +1 -1
  239. data/spec/unit/windows_service_spec.rb +1 -1
  240. data/tasks/docs.rb +10 -2
  241. data/tasks/rspec.rb +8 -6
  242. metadata +32 -8
  243. data/lib/chef/mixin/train_helpers.rb +0 -60
  244. data/spec/unit/mash_spec.rb +0 -51
@@ -2,7 +2,7 @@
2
2
  # Author:: Mark Mzyk <mmzyk@chef.io>
3
3
  # Author:: Seth Chisamore <schisamo@chef.io>
4
4
  # Author:: Bryan McLellan <btm@chef.io>
5
- # Copyright:: Copyright 2011-2016, Chef Software, Inc.
5
+ # Copyright:: Copyright 2011-2019, Chef Software Inc.
6
6
  # License:: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,7 +23,7 @@ class Chef
23
23
  module FileClass
24
24
 
25
25
  def file_class
26
- @host_os_file ||= if Chef::Platform.windows?
26
+ @host_os_file ||= if ChefUtils.windows?
27
27
  require_relative "../win32/file"
28
28
  Chef::ReservedNames::Win32::File
29
29
  else
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright 2011-2016, Chef Software Inc.
2
+ # Copyright:: Copyright 2011-2019, 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");
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Seth Chisamore (<schisamo@chef.io>)
3
- # Copyright:: Copyright 2011-2017, Chef Software Inc.
3
+ # Copyright:: Copyright 2011-2019, 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");
@@ -18,49 +18,13 @@
18
18
 
19
19
  class Chef
20
20
  module Mixin
21
+ # @ deprecated
21
22
  module PathSanity
22
-
23
23
  def enforce_path_sanity(env = ENV)
24
24
  if Chef::Config[:enforce_path_sanity]
25
- env["PATH"] = sanitized_path(env)
26
- end
27
- end
28
-
29
- def sanitized_path(env = ENV)
30
- env_path = env["PATH"].nil? ? "" : env["PATH"].dup
31
- path_separator = Chef::Platform.windows? ? ";" : ":"
32
- # ensure the Ruby and Gem bindirs are included
33
- # mainly for 'full-stack' Chef installs
34
- new_paths = env_path.split(path_separator)
35
- [ ruby_bindir, gem_bindir ].compact.each do |path|
36
- new_paths = [ path ] + new_paths unless new_paths.include?(path)
37
- end
38
- sane_paths.each do |path|
39
- new_paths << path unless new_paths.include?(path)
40
- end
41
- new_paths.join(path_separator).encode("utf-8", invalid: :replace, undef: :replace)
42
- end
43
-
44
- private
45
-
46
- def sane_paths
47
- @sane_paths ||= begin
48
- if Chef::Platform.windows?
49
- %w{}
50
- else
51
- %w{/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin}
52
- end
25
+ env["PATH"] = ChefUtils::DSL::PathSanity.sanitized_path(env)
53
26
  end
54
27
  end
55
-
56
- def ruby_bindir
57
- RbConfig::CONFIG["bindir"]
58
- end
59
-
60
- def gem_bindir
61
- Gem.bindir
62
- end
63
-
64
28
  end
65
29
  end
66
30
  end
@@ -49,7 +49,7 @@ class Chef
49
49
  end
50
50
 
51
51
  # Windows does not support the sticky or setuid bits
52
- if Chef::Platform.windows?
52
+ if ChefUtils.windows?
53
53
  Integer(m) <= 0777 && Integer(m) >= 0
54
54
  else
55
55
  Integer(m) <= 07777 && Integer(m) >= 0
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # Author:: Daniel DeLeo (<dan@chef.io>)
3
- # Copyright:: Copyright 2010-2018, Chef Software Inc.
3
+ # Copyright:: Copyright 2010-2019, 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");
@@ -16,12 +16,11 @@
16
16
  # limitations under the License.
17
17
 
18
18
  require "mixlib/shellout" unless defined?(Mixlib::ShellOut::DEFAULT_READ_TIMEOUT)
19
- require_relative "path_sanity"
19
+ require "chef-utils/dsl/path_sanity" unless defined?(ChefUtils::DSL::PathSanity)
20
20
 
21
21
  class Chef
22
22
  module Mixin
23
23
  module ShellOut
24
- extend Chef::Mixin::PathSanity
25
24
 
26
25
  # PREFERRED APIS:
27
26
  #
@@ -97,7 +96,7 @@ class Chef
97
96
  "LC_ALL" => Chef::Config[:internal_locale],
98
97
  "LANGUAGE" => Chef::Config[:internal_locale],
99
98
  "LANG" => Chef::Config[:internal_locale],
100
- env_path => sanitized_path,
99
+ env_path => ChefUtils::DSL::PathSanity.sanitized_path,
101
100
  }.update(options[env_key] || {})
102
101
  end
103
102
  options
@@ -182,7 +181,7 @@ class Chef
182
181
  end
183
182
 
184
183
  def self.env_path
185
- if Chef::Platform.windows?
184
+ if ChefUtils.windows?
186
185
  "Path"
187
186
  else
188
187
  "PATH"
@@ -175,7 +175,7 @@ class Chef
175
175
  # potential issues for the applications that will consume
176
176
  # this template.
177
177
 
178
- if Chef::Platform.windows?
178
+ if ChefUtils.windows?
179
179
  output = output.gsub(/\r?\n/, "\r\n")
180
180
  end
181
181
 
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Edwards (<adamed@chef.io>)
3
- # Copyright:: Copyright (c) 2016 Chef Software, Inc.
3
+ # Copyright:: Copyright (c) 2016-2019, 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");
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require_relative "../util/windows/logon_session" if Chef::Platform.windows?
19
+ require_relative "../util/windows/logon_session" if ChefUtils.windows?
20
20
 
21
21
  class Chef
22
22
  module Mixin
@@ -26,7 +26,7 @@ class Chef
26
26
  # When authentication = :local, we use the credentials to create a logon session against the local system, and then try to access the files.
27
27
  # When authentication = :remote, we continue with the current user but pass the provided credentials to the remote system.
28
28
  def with_user_context(user, password, domain = nil, authentication = :remote, &block)
29
- unless Chef::Platform.windows?
29
+ unless ChefUtils.windows?
30
30
  raise Exceptions::UnsupportedPlatform, "User context impersonation is supported only on the Windows platform"
31
31
  end
32
32
 
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # Author:: Lamont Granquist <lamont@chef.io>
3
- # Copyright:: Copyright 2010-2018, Chef Software Inc.
3
+ # Copyright:: Copyright 2010-2019, 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");
@@ -15,49 +15,21 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
+ require "chef-utils/dsl/which" unless defined?(ChefUtils::DSL::Which)
19
+ require "chef-utils/dsl/path_sanity" unless defined?(ChefUtils::DSL::PathSanity)
20
+
18
21
  class Chef
19
22
  module Mixin
20
23
  module Which
21
- require_relative "../chef_class"
22
-
23
- def which(*cmds, extra_path: nil, &block)
24
- where(*cmds, extra_path: extra_path, &block).first || false
25
- end
26
-
27
- def where(*cmds, extra_path: nil, &block)
28
- # NOTE: unnecessarily duplicates function of path_sanity
29
- extra_path ||= [ "/bin", "/usr/bin", "/sbin", "/usr/sbin" ]
30
- paths = env_path.split(File::PATH_SEPARATOR) + Array(extra_path)
31
- cmds.map do |cmd|
32
- paths.map do |path|
33
- filename = Chef.path_to(File.join(path, cmd))
34
- filename if valid_executable?(filename, &block)
35
- end.compact
36
- end.flatten
37
- end
24
+ include ChefUtils::DSL::Which
38
25
 
39
26
  private
40
27
 
41
- # for test stubbing
42
- def env_path
43
- if Chef::Config.target_mode?
44
- Chef.run_context.transport_connection.run_command("echo $PATH").stdout
45
- else
46
- ENV["PATH"]
47
- end
48
- end
49
-
50
- def valid_executable?(filename, &block)
51
- is_executable =
52
- if Chef::Config.target_mode?
53
- connection = Chef.run_context.transport_connection
54
- connection.file(filename).stat[:mode] & 1 && !connection.file(filename).directory?
55
- else
56
- File.executable?(filename) && !File.directory?(filename)
57
- end
58
- return false unless is_executable
59
-
60
- block ? yield(filename) : true
28
+ # we dep-inject path sanity into this API for historical reasons
29
+ #
30
+ # @api private
31
+ def __extra_path
32
+ ChefUtils::DSL::PathSanity.sane_paths
61
33
  end
62
34
  end
63
35
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Edwards (<adamed@chef.io>)
3
- # Copyright:: Copyright 2013-2016, Chef Software Inc.
3
+ # Copyright:: Copyright 2013-2019, 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");
@@ -18,8 +18,8 @@
18
18
 
19
19
  require_relative "../exceptions"
20
20
  require_relative "../platform/query_helpers"
21
- require_relative "../win32/process" if Chef::Platform.windows?
22
- require_relative "../win32/system" if Chef::Platform.windows?
21
+ require_relative "../win32/process" if ChefUtils.windows?
22
+ require_relative "../win32/system" if ChefUtils.windows?
23
23
 
24
24
  class Chef
25
25
  module Mixin
@@ -89,7 +89,7 @@ class Chef
89
89
  end
90
90
 
91
91
  def is_i386_process_on_x86_64_windows?
92
- if Chef::Platform.windows?
92
+ if ChefUtils.windows?
93
93
  Chef::ReservedNames::Win32::Process.is_wow64_process
94
94
  else
95
95
  false
@@ -97,13 +97,13 @@ class Chef
97
97
  end
98
98
 
99
99
  def disable_wow64_file_redirection( node )
100
- if ( node_windows_architecture(node) == :x86_64) && ::Chef::Platform.windows?
100
+ if ( node_windows_architecture(node) == :x86_64) && ::ChefUtils.windows?
101
101
  Chef::ReservedNames::Win32::System.wow64_disable_wow64_fs_redirection
102
102
  end
103
103
  end
104
104
 
105
105
  def restore_wow64_file_redirection( node, original_redirection_state )
106
- if (node_windows_architecture(node) == :x86_64) && ::Chef::Platform.windows?
106
+ if (node_windows_architecture(node) == :x86_64) && ::ChefUtils.windows?
107
107
  Chef::ReservedNames::Win32::System.wow64_revert_wow64_fs_redirection(original_redirection_state)
108
108
  end
109
109
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Edwards (<adamed@chef.io>)
3
- # Copyright:: Copyright 2013-2016, Chef Software Inc.
3
+ # Copyright:: Copyright 2013-2019, 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");
@@ -19,16 +19,16 @@
19
19
  require_relative "../exceptions"
20
20
  require_relative "wide_string"
21
21
  require_relative "../platform/query_helpers"
22
- require_relative "../win32/error" if Chef::Platform.windows?
23
- require_relative "../win32/api/system" if Chef::Platform.windows?
24
- require_relative "../win32/api/unicode" if Chef::Platform.windows?
22
+ require_relative "../win32/error" if ChefUtils.windows?
23
+ require_relative "../win32/api/system" if ChefUtils.windows?
24
+ require_relative "../win32/api/unicode" if ChefUtils.windows?
25
25
 
26
26
  class Chef
27
27
  module Mixin
28
28
  module WindowsEnvHelper
29
29
  include Chef::Mixin::WideString
30
30
 
31
- if Chef::Platform.windows?
31
+ if ChefUtils.windows?
32
32
  include Chef::ReservedNames::Win32::API::System
33
33
  end
34
34
 
@@ -199,14 +199,14 @@ class Chef
199
199
  @role_default = VividMash.new({}, self, node, :role_default)
200
200
  @force_default = VividMash.new({}, self, node, :force_default)
201
201
 
202
- @normal = VividMash.new(normal, self, node, :normal)
202
+ @normal = VividMash.new(normal, self, node, :normal)
203
203
 
204
204
  @override = VividMash.new(override, self, node, :override)
205
205
  @role_override = VividMash.new({}, self, node, :role_override)
206
206
  @env_override = VividMash.new({}, self, node, :env_override)
207
207
  @force_override = VividMash.new({}, self, node, :force_override)
208
208
 
209
- @automatic = VividMash.new(automatic, self, node, :automatic)
209
+ @automatic = VividMash.new(automatic, self, node, :automatic)
210
210
 
211
211
  super(nil, self, node, :merged)
212
212
  end
@@ -219,6 +219,11 @@ class Chef
219
219
 
220
220
  private
221
221
 
222
+ def platform_family_query_helper?(node, m)
223
+ method = "#{m}?".to_sym
224
+ ChefUtils::DSL::PlatformFamily.respond_to?(method) && ChefUtils::DSL::PlatformFamily.send(method, node)
225
+ end
226
+
222
227
  #
223
228
  # Succeeds if:
224
229
  # - no negative matches (!value)
@@ -235,11 +240,19 @@ class Chef
235
240
  # Split the blacklist and whitelist
236
241
  blacklist, whitelist = filter_values.partition { |v| v.is_a?(String) && v.start_with?("!") }
237
242
 
238
- # If any blacklist value matches, we don't match
239
- return false if blacklist.any? { |v| v[1..-1] == value }
243
+ if attribute == :platform_family
244
+ # If any blacklist value matches, we don't match
245
+ return false if blacklist.any? { |v| v[1..-1] == value || platform_family_query_helper?(node, v[1..-1]) }
240
246
 
241
- # If the whitelist is empty, or anything matches, we match.
242
- whitelist.empty? || whitelist.any? { |v| v == :all || v == value }
247
+ # If the whitelist is empty, or anything matches, we match.
248
+ whitelist.empty? || whitelist.any? { |v| v == :all || v == value || platform_family_query_helper?(node, v) }
249
+ else
250
+ # If any blacklist value matches, we don't match
251
+ return false if blacklist.any? { |v| v[1..-1] == value }
252
+
253
+ # If the whitelist is empty, or anything matches, we match.
254
+ whitelist.empty? || whitelist.any? { |v| v == :all || v == value }
255
+ end
243
256
  end
244
257
 
245
258
  def matches_version_list?(node, filters, attribute)
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@chef.io>)
3
- # Copyright:: Copyright 2008-2016, Chef Software Inc.
3
+ # Copyright:: Copyright 2008-2019, 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");
@@ -16,12 +16,14 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
+ require "chef-utils" unless defined?(ChefUtils::CANARY)
20
+
19
21
  class Chef
20
22
  class Platform
21
23
 
22
24
  class << self
23
25
  def windows?
24
- ChefConfig.windows?
26
+ ChefUtils.windows?
25
27
  end
26
28
 
27
29
  def windows_nano_server?
@@ -35,7 +35,7 @@ class Chef
35
35
  reboot_info = node.run_context.reboot_info
36
36
 
37
37
  cmd = case
38
- when Chef::Platform.windows?
38
+ when ChefUtils.windows?
39
39
  # should this do /f as well? do we then need a minimum delay to let apps quit?
40
40
  # Use explicit path to shutdown.exe, to protect against https://github.com/chef/chef/issues/5594
41
41
  windows_shutdown_path = "#{ENV["SYSTEMROOT"]}/System32/shutdown.exe"
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Lamont Granquist (<lamont@chef.io>)
3
- # Copyright:: Copyright 2014-2016, Chef Software, Inc.
3
+ # Copyright:: Copyright 2014-2019, 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");
@@ -17,53 +17,22 @@
17
17
  #
18
18
 
19
19
  require_relative "../chef_class"
20
- require_relative "../mixin/train_helpers"
20
+ require "chef-utils" if defined?(ChefUtils::CANARY)
21
21
 
22
22
  class Chef
23
23
  class Platform
24
+ # @deprecated, use ChefUtils::DSL::Service instead (via the ChefUtils Universal DSL)
24
25
  class ServiceHelpers
25
26
  class << self
26
- include Chef::Mixin::TrainHelpers
27
-
28
- # This helper is mostly used to sort out the mess of different
29
- # linux mechanisms that can be used to start services. It does
30
- # not necessarily need to linux-specific, but currently all our
31
- # other service providers are narrowly platform-specific with no
32
- # alternatives.
33
- #
34
- # NOTE: if a system has (for example) chkconfig installed then we
35
- # should report that chkconfig is installed. The fact that a system
36
- # may also have systemd installed does not mean that we do not
37
- # report that systemd is also installed. This module is purely for
38
- # discovery of all the alternatives, handling the priority of the
39
- # different services is NOT a design concern of this module.
40
- #
41
27
  def service_resource_providers
42
28
  providers = []
43
29
 
44
- if file_exist?(Chef.path_to("/usr/sbin/update-rc.d"))
45
- providers << :debian
46
- end
47
-
48
- if file_exist?(Chef.path_to("/usr/sbin/invoke-rc.d"))
49
- providers << :invokercd
50
- end
51
-
52
- if file_exist?(Chef.path_to("/sbin/initctl"))
53
- providers << :upstart
54
- end
55
-
56
- if file_exist?(Chef.path_to("/sbin/insserv"))
57
- providers << :insserv
58
- end
59
-
60
- if systemd_is_init?
61
- providers << :systemd
62
- end
63
-
64
- if file_exist?(Chef.path_to("/sbin/chkconfig"))
65
- providers << :redhat
66
- end
30
+ providers << :debian if ChefUtils::DSL::Service.debianrcd?
31
+ providers << :invokercd if ChefUtils::DSL::Service.invokercd?
32
+ providers << :upstart if ChefUtils::DSL::Service.upstart?
33
+ providers << :insserv if ChefUtils::DSL::Service.insserv?
34
+ providers << :systemd if ChefUtils.systemd?
35
+ providers << :redhat if ChefUtils::DSL::Service.redhatrcd?
67
36
 
68
37
  providers
69
38
  end
@@ -71,54 +40,14 @@ class Chef
71
40
  def config_for_service(service_name)
72
41
  configs = []
73
42
 
74
- if file_exist?(Chef.path_to("/etc/init.d/#{service_name}"))
75
- configs += %i{initd systemd}
76
- end
77
-
78
- if file_exist?(Chef.path_to("/etc/init/#{service_name}.conf"))
79
- configs << :upstart
80
- end
81
-
82
- if file_exist?(Chef.path_to("/etc/xinetd.d/#{service_name}"))
83
- configs << :xinetd
84
- end
85
-
86
- if file_exist?(Chef.path_to("/etc/rc.d/#{service_name}"))
87
- configs << :etc_rcd
88
- end
89
-
90
- if file_exist?(Chef.path_to("/usr/local/etc/rc.d/#{service_name}"))
91
- configs << :usr_local_etc_rcd
92
- end
93
-
94
- if has_systemd_service_unit?(service_name) || has_systemd_unit?(service_name)
95
- configs << :systemd
96
- end
43
+ configs << :initd if ChefUtils::DSL::Service.service_script_exist?(:initd, service_name)
44
+ configs << :upstart if ChefUtils::DSL::Service.service_script_exist?(:upstart, service_name)
45
+ configs << :xinetd if ChefUtils::DSL::Service.service_script_exist?(:xinetd, service_name)
46
+ configs << :systemd if ChefUtils::DSL::Service.service_script_exist?(:systemd, service_name)
47
+ configs << :etc_rcd if ChefUtils::DSL::Service.service_script_exist?(:etc_rcd, service_name)
97
48
 
98
49
  configs
99
50
  end
100
-
101
- private
102
-
103
- def systemd_is_init?
104
- file_exist?(Chef.path_to("/proc/1/comm")) &&
105
- file_open(Chef.path_to("/proc/1/comm")).gets.chomp == "systemd"
106
- end
107
-
108
- def has_systemd_service_unit?(svc_name)
109
- %w{ /etc /usr/lib /lib /run }.any? do |load_path|
110
- file_exist?(
111
- Chef.path_to("#{load_path}/systemd/system/#{svc_name.gsub(/@.*$/, "@")}.service")
112
- )
113
- end
114
- end
115
-
116
- def has_systemd_unit?(svc_name)
117
- # TODO: stop supporting non-service units with service resource
118
- %w{ /etc /usr/lib /lib /run }.any? do |load_path|
119
- file_exist?(Chef.path_to("#{load_path}/systemd/system/#{svc_name}"))
120
- end
121
- end
122
51
  end
123
52
  end
124
53
  end