chef 15.11.8-universal-mingw32 → 15.16.2-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +12 -13
  3. data/README.md +3 -3
  4. data/Rakefile +11 -17
  5. data/chef-universal-mingw32.gemspec +4 -4
  6. data/chef.gemspec +25 -7
  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 +1 -1
  11. data/lib/chef/chef_fs/file_system/repository/base_file.rb +1 -0
  12. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +2 -2
  13. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +1 -1
  14. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +2 -2
  15. data/lib/chef/chef_fs/file_system/repository/directory.rb +1 -1
  16. data/lib/chef/chef_fs/file_system/repository/file_system_entry.rb +1 -1
  17. data/lib/chef/chef_fs/path_utils.rb +3 -3
  18. data/lib/chef/cookbook/file_system_file_vendor.rb +1 -1
  19. data/lib/chef/data_bag.rb +2 -2
  20. data/lib/chef/data_collector/error_handlers.rb +1 -1
  21. data/lib/chef/deprecated.rb +12 -0
  22. data/lib/chef/dsl/declare_resource.rb +1 -1
  23. data/lib/chef/dsl/platform_introspection.rb +2 -0
  24. data/lib/chef/environment.rb +2 -2
  25. data/lib/chef/exceptions.rb +3 -0
  26. data/lib/chef/http.rb +2 -1
  27. data/lib/chef/knife/bootstrap.rb +6 -9
  28. data/lib/chef/knife/bootstrap/templates/chef-full.erb +9 -9
  29. data/lib/chef/knife/bootstrap/train_connector.rb +1 -0
  30. data/lib/chef/knife/cookbook_download.rb +1 -1
  31. data/lib/chef/knife/cookbook_metadata.rb +1 -1
  32. data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
  33. data/lib/chef/knife/core/hashed_command_loader.rb +3 -2
  34. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  35. data/lib/chef/knife/exec.rb +2 -2
  36. data/lib/chef/knife/ssh.rb +20 -1
  37. data/lib/chef/log.rb +1 -1
  38. data/lib/chef/mixin/openssl_helper.rb +26 -3
  39. data/lib/chef/mixin/template.rb +1 -0
  40. data/lib/chef/node_map.rb +5 -2
  41. data/lib/chef/provider/mount/solaris.rb +0 -1
  42. data/lib/chef/provider/package/cab.rb +1 -1
  43. data/lib/chef/provider/package/chocolatey.rb +1 -1
  44. data/lib/chef/provider/package/dnf/dnf_helper.py +5 -0
  45. data/lib/chef/provider/package/freebsd/pkgng.rb +3 -1
  46. data/lib/chef/provider/package/msu.rb +1 -0
  47. data/lib/chef/provider/package/powershell.rb +5 -1
  48. data/lib/chef/provider/package/snap.rb +96 -27
  49. data/lib/chef/provider/package/yum/yum_helper.py +4 -0
  50. data/lib/chef/provider/package/zypper.rb +0 -1
  51. data/lib/chef/provider/service/arch.rb +2 -2
  52. data/lib/chef/provider/service/debian.rb +1 -1
  53. data/lib/chef/provider/service/gentoo.rb +2 -2
  54. data/lib/chef/provider/service/macosx.rb +2 -2
  55. data/lib/chef/provider/service/openbsd.rb +1 -1
  56. data/lib/chef/provider/service/redhat.rb +2 -2
  57. data/lib/chef/provider/service/upstart.rb +1 -1
  58. data/lib/chef/provider/yum_repository.rb +1 -1
  59. data/lib/chef/provider/zypper_repository.rb +31 -11
  60. data/lib/chef/resource.rb +2 -0
  61. data/lib/chef/resource/archive_file.rb +28 -8
  62. data/lib/chef/resource/cron_access.rb +13 -5
  63. data/lib/chef/resource/cron_d.rb +2 -1
  64. data/lib/chef/resource/homebrew_cask.rb +3 -3
  65. data/lib/chef/resource/hostname.rb +19 -18
  66. data/lib/chef/resource/locale.rb +1 -1
  67. data/lib/chef/resource/lwrp_base.rb +7 -0
  68. data/lib/chef/resource/msu_package.rb +5 -0
  69. data/lib/chef/resource/ssh_known_hosts_entry.rb +1 -1
  70. data/lib/chef/resource/sudo.rb +2 -2
  71. data/lib/chef/resource/windows_feature_powershell.rb +6 -2
  72. data/lib/chef/resource/windows_font.rb +2 -1
  73. data/lib/chef/role.rb +2 -2
  74. data/lib/chef/shell.rb +32 -1
  75. data/lib/chef/shell/shell_session.rb +2 -0
  76. data/lib/chef/util/diff.rb +1 -1
  77. data/lib/chef/util/dsc/configuration_generator.rb +1 -1
  78. data/lib/chef/util/powershell/cmdlet.rb +1 -1
  79. data/lib/chef/version.rb +2 -2
  80. data/lib/chef/version_string.rb +1 -1
  81. data/lib/chef/win32/file.rb +2 -2
  82. data/spec/functional/knife/ssh_spec.rb +4 -4
  83. data/spec/functional/resource/aix_service_spec.rb +0 -1
  84. data/spec/functional/resource/aixinit_service_spec.rb +7 -8
  85. data/spec/functional/resource/apt_package_spec.rb +0 -1
  86. data/spec/functional/resource/bff_spec.rb +2 -2
  87. data/spec/functional/resource/cookbook_file_spec.rb +1 -1
  88. data/spec/functional/resource/cron_spec.rb +0 -1
  89. data/spec/functional/resource/dsc_resource_spec.rb +1 -1
  90. data/spec/functional/resource/insserv_spec.rb +4 -5
  91. data/spec/functional/resource/link_spec.rb +17 -17
  92. data/spec/functional/resource/msu_package_spec.rb +5 -2
  93. data/spec/functional/resource/rpm_spec.rb +2 -2
  94. data/spec/functional/resource/user/dscl_spec.rb +1 -1
  95. data/spec/functional/resource/user/mac_user_spec.rb +1 -1
  96. data/spec/functional/resource/windows_certificate_spec.rb +3 -3
  97. data/spec/functional/resource/windows_font_spec.rb +49 -0
  98. data/spec/functional/resource/windows_task_spec.rb +8 -8
  99. data/spec/functional/run_lock_spec.rb +2 -1
  100. data/spec/functional/shell_spec.rb +5 -5
  101. data/spec/functional/util/powershell/cmdlet_spec.rb +1 -1
  102. data/spec/functional/version_spec.rb +1 -1
  103. data/spec/functional/win32/service_manager_spec.rb +1 -1
  104. data/spec/integration/recipes/accumulator_spec.rb +1 -1
  105. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +2 -2
  106. data/spec/integration/recipes/lwrp_spec.rb +1 -1
  107. data/spec/integration/recipes/notifies_spec.rb +1 -1
  108. data/spec/integration/recipes/notifying_block_spec.rb +1 -1
  109. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  110. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +2 -0
  111. data/spec/integration/recipes/resource_load_spec.rb +1 -0
  112. data/spec/integration/recipes/unified_mode_spec.rb +1 -1
  113. data/spec/scripts/ssl-serve.rb +1 -1
  114. data/spec/spec_helper.rb +10 -8
  115. data/spec/support/platform_helpers.rb +12 -42
  116. data/spec/support/platforms/win32/spec_service.rb +1 -1
  117. data/spec/support/shared/functional/directory_resource.rb +1 -1
  118. data/spec/support/shared/functional/execute_resource.rb +1 -1
  119. data/spec/support/shared/functional/file_resource.rb +2 -2
  120. data/spec/support/shared/functional/win32_service.rb +1 -1
  121. data/spec/support/shared/functional/windows_script.rb +3 -3
  122. data/spec/support/shared/integration/knife_support.rb +2 -5
  123. data/spec/unit/application_spec.rb +7 -0
  124. data/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb +2 -4
  125. data/spec/unit/cookbook/gem_installer_spec.rb +2 -1
  126. data/spec/unit/data_bag_spec.rb +1 -1
  127. data/spec/unit/dsl/platform_introspection_spec.rb +1 -0
  128. data/spec/unit/environment_spec.rb +7 -7
  129. data/spec/unit/event_dispatch/dispatcher_spec.rb +3 -0
  130. data/spec/unit/knife/bootstrap_spec.rb +16 -16
  131. data/spec/unit/knife/cookbook_download_spec.rb +4 -4
  132. data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +1 -1
  133. data/spec/unit/knife/cookbook_upload_spec.rb +5 -6
  134. data/spec/unit/knife/core/hashed_command_loader_spec.rb +3 -3
  135. data/spec/unit/knife/ssh_spec.rb +2 -2
  136. data/spec/unit/knife/supermarket_share_spec.rb +5 -3
  137. data/spec/unit/lwrp_spec.rb +4 -4
  138. data/spec/unit/mixin/securable_spec.rb +0 -1
  139. data/spec/unit/mixin/user_context_spec.rb +1 -9
  140. data/spec/unit/property_spec.rb +6 -6
  141. data/spec/unit/provider/package/dnf/python_helper_spec.rb +1 -1
  142. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +1 -1
  143. data/spec/unit/provider/package/powershell_spec.rb +95 -86
  144. data/spec/unit/provider/package/rubygems_spec.rb +5 -10
  145. data/spec/unit/provider/package/snap_spec.rb +1 -1
  146. data/spec/unit/provider/package/windows_spec.rb +30 -53
  147. data/spec/unit/provider/service/arch_service_spec.rb +3 -2
  148. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  149. data/spec/unit/provider/service/gentoo_service_spec.rb +7 -7
  150. data/spec/unit/provider/service/macosx_spec.rb +3 -3
  151. data/spec/unit/provider/service/redhat_spec.rb +2 -2
  152. data/spec/unit/provider/service/upstart_service_spec.rb +3 -3
  153. data/spec/unit/provider/service/windows_spec.rb +2 -6
  154. data/spec/unit/provider/systemd_unit_spec.rb +28 -24
  155. data/spec/unit/provider/zypper_repository_spec.rb +75 -25
  156. data/spec/unit/provider_spec.rb +1 -0
  157. data/spec/unit/resource/archive_file_spec.rb +11 -2
  158. data/spec/unit/resource/msu_package_spec.rb +4 -0
  159. data/spec/unit/resource/windows_dns_record_spec.rb +3 -3
  160. data/spec/unit/resource/windows_dns_zone_spec.rb +2 -2
  161. data/spec/unit/resource/windows_feature_powershell_spec.rb +30 -4
  162. data/spec/unit/resource/windows_package_spec.rb +1 -0
  163. data/spec/unit/resource/windows_task_spec.rb +1 -1
  164. data/spec/unit/resource/windows_uac_spec.rb +2 -2
  165. data/spec/unit/resource/yum_repository_spec.rb +21 -21
  166. data/spec/unit/resource_spec.rb +1 -1
  167. data/spec/unit/role_spec.rb +11 -11
  168. data/spec/unit/run_context/cookbook_compiler_spec.rb +1 -1
  169. data/spec/unit/util/threaded_job_queue_spec.rb +9 -0
  170. data/spec/unit/win32/security_spec.rb +4 -3
  171. metadata +64 -39
@@ -1,4 +1,3 @@
1
- # Encoding: utf-8
2
1
  # Author:: Hugo Fichter
3
2
  # Author:: Lamont Granquist (<lamont@chef.io>)
4
3
  # Author:: Joshua Timberman (<joshua@chef.io>)
@@ -94,7 +94,7 @@ class Chef
94
94
  split_package_identity(p["package_identity"])
95
95
  end
96
96
  found_packages = existing_package_identities.select do |existing_package_ident|
97
- existing_package_ident["name"] == package["name"]
97
+ existing_package_ident["version"] == package["version"].chomp && existing_package_ident["name"] == package["name"]
98
98
  end
99
99
  if found_packages.empty?
100
100
  nil
@@ -251,7 +251,7 @@ class Chef
251
251
  end
252
252
 
253
253
  # Helper to convert choco.exe list output to a Hash
254
- # (names are downcased for case-insenstive matching)
254
+ # (names are downcased for case-insensitive matching)
255
255
  #
256
256
  # @param cmd [String] command to run
257
257
  # @return [Hash] list output converted to ruby Hash
@@ -101,6 +101,11 @@ while 1:
101
101
  if ppid == 1:
102
102
  sys.exit(0)
103
103
  line = sys.stdin.readline()
104
+
105
+ # only way to detect EOF in python
106
+ if line == "":
107
+ break
108
+
104
109
  command = json.loads(line)
105
110
  if command['action'] == "whatinstalled":
106
111
  query(command)
@@ -42,7 +42,9 @@ class Chef
42
42
  end
43
43
 
44
44
  def current_installed_version
45
- pkg_info = shell_out!("pkg", "info", new_resource.package_name, env: nil, returns: [0, 70])
45
+ # pkgng up to version 1.15.99.7 returns 70 for pkg not found,
46
+ # later versions return 1
47
+ pkg_info = shell_out!("pkg", "info", new_resource.package_name, env: nil, returns: [0, 1, 70])
46
48
  pkg_info.stdout[/^Version +: (.+)$/, 1]
47
49
  end
48
50
 
@@ -109,6 +109,7 @@ class Chef
109
109
  @cab_files.each do |cab_file|
110
110
  declare_resource(:cab_package, new_resource.name) do
111
111
  source cab_file
112
+ timeout new_resource.timeout
112
113
  action :install
113
114
  end
114
115
  end
@@ -53,6 +53,9 @@ class Chef
53
53
 
54
54
  # Installs the package specified with the version passed else latest version will be installed
55
55
  def install_package(names, versions)
56
+ # To enable tls 1.2, which is disabled by default in some OS
57
+ powershell_out("[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12")
58
+
56
59
  names.each_with_index do |name, index|
57
60
  cmd = powershell_out(build_powershell_package_command("Install-Package '#{name}'", versions[index]), timeout: new_resource.timeout)
58
61
  next if cmd.nil?
@@ -115,7 +118,8 @@ class Chef
115
118
  command = [command] unless command.is_a?(Array)
116
119
  cmdlet_name = command.first
117
120
  command.unshift("(")
118
- %w{-Force -ForceBootstrap}.each do |arg|
121
+ # -WarningAction SilentlyContinue is used to suppress the warnings from stdout
122
+ %w{-Force -ForceBootstrap -WarningAction SilentlyContinue}.each do |arg|
119
123
  command.push(arg)
120
124
  end
121
125
  command.push("-RequiredVersion #{version}") if version
@@ -59,15 +59,14 @@ class Chef
59
59
  def get_current_versions
60
60
  package_name_array.each_with_index.map do |pkg, i|
61
61
  installed_version(i)
62
- end
62
+ end.compact
63
63
  end
64
64
 
65
65
  def install_package(names, versions)
66
66
  if new_resource.source
67
67
  install_snap_from_source(names, new_resource.source)
68
68
  else
69
- resolved_names = names.each_with_index.map { |name, i| available_version(i).to_s unless name.nil? }
70
- install_snaps(resolved_names)
69
+ install_snaps(names)
71
70
  end
72
71
  end
73
72
 
@@ -75,14 +74,16 @@ class Chef
75
74
  if new_resource.source
76
75
  install_snap_from_source(names, new_resource.source)
77
76
  else
78
- resolved_names = names.each_with_index.map { |name, i| available_version(i).to_s unless name.nil? }
79
- update_snaps(resolved_names)
77
+ if get_current_versions.empty?
78
+ install_snaps(names, versions)
79
+ else
80
+ update_snaps(names)
81
+ end
80
82
  end
81
83
  end
82
84
 
83
85
  def remove_package(names, versions)
84
- resolved_names = names.each_with_index.map { |name, i| installed_version(i).to_s unless name.nil? }
85
- uninstall_snaps(resolved_names)
86
+ uninstall_snaps(names)
86
87
  end
87
88
 
88
89
  alias purge_package remove_package
@@ -129,19 +130,73 @@ class Chef
129
130
  "Accept: application/json\r\n" +
130
131
  "Content-Type: application/json\r\n"
131
132
  if method == "POST"
132
- request.concat("Content-Length: #{post_data.bytesize}\r\n\r\n#{post_data}")
133
+ pdata = post_data.to_json.to_s
134
+ request.concat("Content-Length: #{pdata.bytesize}\r\n\r\n#{pdata}")
133
135
  end
134
136
  request.concat("\r\n")
135
- # While it is expected to allow clients to connect using HTTPS over a TCP socket,
136
- # at this point only a UNIX socket is supported. The socket is /run/snapd.socket
137
- # Note - UNIXSocket is not defined on windows systems
137
+
138
+ # while it is expected to allow clients to connect using https over
139
+ # a tcp socket, at this point only a unix socket is supported. the
140
+ # socket is /run/snapd.socket note - unixsocket is not defined on
141
+ # windows systems
138
142
  if defined?(::UNIXSocket)
139
143
  UNIXSocket.open("/run/snapd.socket") do |socket|
140
- # Send request, read the response, split the response and parse the body
141
- socket.print(request)
142
- response = socket.read
143
- headers, body = response.split("\r\n\r\n", 2)
144
- JSON.parse(body)
144
+ # send request, read the response, split the response and parse
145
+ # the body
146
+ socket.write(request)
147
+
148
+ # WARNING!!! HERE BE DRAGONs
149
+ #
150
+ # So snapd doesn't return an EOF at the end of its body, so
151
+ # doing a normal read will just hang forever.
152
+ #
153
+ # Well, sort of. if, after it writes everything, you then send
154
+ # yet-another newline, it'll then send its EOF and promptly
155
+ # disconnect closing the pipe and preventing reading. so, you
156
+ # have to read first, and therein lies the EOF problem.
157
+ #
158
+ # So you can do non-blocking reads with selects, but it
159
+ # makes every read take about 5 seconds. If, instead, we
160
+ # read the last line char-by-char, it's about half a second.
161
+ #
162
+ # Reading a character at a time isn't efficient, and since we
163
+ # know that http headers always have a blank line after them,
164
+ # we can read lines until we find a blank line and *then* read
165
+ # a character at a time. snap returns all the json on a single
166
+ # line, so once you pass headers you must read a character a
167
+ # time.
168
+ #
169
+ # - jaymzh
170
+
171
+ Chef::Log.trace(
172
+ "snap_package[#{new_resource.package_name}]: reading headers"
173
+ )
174
+ loop do
175
+ response = socket.readline
176
+ break if response.strip.empty? # finished headers
177
+ end
178
+ Chef::Log.trace(
179
+ "snap_package[#{new_resource.package_name}]: past headers, " +
180
+ "onto the body..."
181
+ )
182
+ result = nil
183
+ body = ""
184
+ socket.each_char do |c|
185
+ body << c
186
+ # we know we're not done if we don't have a char that
187
+ # can end JSON
188
+ next unless ["}", "]"].include?(c)
189
+
190
+ begin
191
+ result = JSON.parse(body)
192
+ # if we get here, we were able to parse the json so we
193
+ # are done reading
194
+ break
195
+ rescue JSON::ParserError
196
+ next
197
+ end
198
+ end
199
+ result
145
200
  end
146
201
  end
147
202
  end
@@ -211,20 +266,22 @@ class Chef
211
266
  response.error!
212
267
  end
213
268
 
214
- def install_snaps(snap_names)
215
- response = post_snaps(snap_names, "install", new_resource.channel, new_resource.options)
216
- id = get_id_from_async_response(response)
217
- wait_for_completion(id)
269
+ def install_snaps(snap_names, versions)
270
+ snap_names.each do |snap|
271
+ response = post_snap(snap, "install", new_resource.channel, new_resource.options)
272
+ id = get_id_from_async_response(response)
273
+ wait_for_completion(id)
274
+ end
218
275
  end
219
276
 
220
277
  def update_snaps(snap_names)
221
- response = post_snaps(snap_names, "refresh", new_resource.channel, new_resource.options)
278
+ response = post_snaps(snap_names, "refresh", nil, new_resource.options)
222
279
  id = get_id_from_async_response(response)
223
280
  wait_for_completion(id)
224
281
  end
225
282
 
226
283
  def uninstall_snaps(snap_names)
227
- response = post_snaps(snap_names, "remove", new_resource.channel, new_resource.options)
284
+ response = post_snaps(snap_names, "remove", nil, new_resource.options)
228
285
  id = get_id_from_async_response(response)
229
286
  wait_for_completion(id)
230
287
  end
@@ -278,18 +335,20 @@ class Chef
278
335
  "action" => action,
279
336
  "snaps" => snap_names,
280
337
  }
281
- if %w{install refresh switch}.include?(action)
338
+ if %w{install refresh switch}.include?(action) && channel
282
339
  request["channel"] = channel
283
340
  end
284
341
 
285
342
  # No defensive handling of params
286
343
  # Snap will throw the proper exception if called improperly
287
344
  # And we can provide that exception to the end user
288
- request["classic"] = true if options["classic"]
289
- request["devmode"] = true if options["devmode"]
290
- request["jailmode"] = true if options["jailmode"]
345
+ if options
346
+ request["classic"] = true if options.include?("classic")
347
+ request["devmode"] = true if options.include?("devmode")
348
+ request["jailmode"] = true if options.include?("jailmode")
349
+ request["ignore_validation"] = true if options.include?("ignore-validation")
350
+ end
291
351
  request["revision"] = revision unless revision.nil?
292
- request["ignore_validation"] = true if options["ignore-validation"]
293
352
  request
294
353
  end
295
354
 
@@ -305,12 +364,22 @@ class Chef
305
364
  call_snap_api("POST", "/v2/snaps", json)
306
365
  end
307
366
 
367
+ def post_snap(snap_name, action, channel, options, revision = nil)
368
+ json = generate_snap_json(snap_name, action, channel, options, revision = nil)
369
+ json.delete("snaps")
370
+ call_snap_api("POST", "/v2/snaps/#{snap_name}", json)
371
+ end
372
+
308
373
  def get_latest_package_version(name, channel)
309
374
  json = call_snap_api("GET", "/v2/find?name=#{name}")
310
375
  if json["status-code"] != 200
311
376
  raise Chef::Exceptions::Package, json["result"], caller
312
377
  end
313
378
 
379
+ unless json["result"][0]["channels"]["latest/#{channel}"]
380
+ raise Chef::Exceptions::Package, "No version of #{name} in channel #{channel}", caller
381
+ end
382
+
314
383
  # Return the version matching the channel
315
384
  json["result"][0]["channels"]["latest/#{channel}"]["version"]
316
385
  end
@@ -196,6 +196,10 @@ try:
196
196
  setup_exit_handler()
197
197
  line = inpipe.readline()
198
198
 
199
+ # only way to detect EOF in python
200
+ if line == "":
201
+ break
202
+
199
203
  try:
200
204
  command = json.loads(line)
201
205
  except ValueError, e:
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
  #
3
2
  # Authors:: Adam Jacob (<adam@chef.io>)
4
3
  # Ionuț Arțăriși (<iartarisi@suse.cz>)
@@ -32,8 +32,8 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init
32
32
  end
33
33
 
34
34
  def load_current_resource
35
- raise Chef::Exceptions::Service, "Could not find /etc/rc.conf" unless ::File.exists?("/etc/rc.conf")
36
- raise Chef::Exceptions::Service, "No DAEMONS found in /etc/rc.conf" unless ::File.read("/etc/rc.conf") =~ /DAEMONS=\((.*)\)/m
35
+ raise Chef::Exceptions::Service, "Could not find /etc/rc.conf" unless ::File.exist?("/etc/rc.conf")
36
+ raise Chef::Exceptions::Service, "No DAEMONS found in /etc/rc.conf" unless /DAEMONS=\((.*)\)/m.match?(::File.read("/etc/rc.conf"))
37
37
 
38
38
  super
39
39
 
@@ -45,7 +45,7 @@ class Chef
45
45
  shared_resource_requirements
46
46
  requirements.assert(:all_actions) do |a|
47
47
  update_rcd = "/usr/sbin/update-rc.d"
48
- a.assertion { ::File.exists? update_rcd }
48
+ a.assertion { ::File.exist? update_rcd }
49
49
  a.failure_message Chef::Exceptions::Service, "#{update_rcd} does not exist!"
50
50
  # no whyrun recovery - this is a base system component of debian
51
51
  # distros and must be present
@@ -34,7 +34,7 @@ class Chef::Provider::Service::Gentoo < Chef::Provider::Service::Init
34
34
  @current_resource.enabled(
35
35
  Dir.glob("/etc/runlevels/**/#{Chef::Util::PathHelper.escape_glob_dir(@current_resource.service_name)}").any? do |file|
36
36
  @found_script = true
37
- exists = ::File.exists? file
37
+ exists = ::File.exist? file
38
38
  readable = ::File.readable? file
39
39
  logger.trace "#{@new_resource} exists: #{exists}, readable: #{readable}"
40
40
  exists && readable
@@ -47,7 +47,7 @@ class Chef::Provider::Service::Gentoo < Chef::Provider::Service::Init
47
47
 
48
48
  def define_resource_requirements
49
49
  requirements.assert(:all_actions) do |a|
50
- a.assertion { ::File.exists?("/sbin/rc-update") }
50
+ a.assertion { ::File.exist?("/sbin/rc-update") }
51
51
  a.failure_message Chef::Exceptions::Service, "/sbin/rc-update does not exist"
52
52
  # no whyrun recovery -t his is a core component whose presence is
53
53
  # unlikely to be affected by what we do in the course of a chef run
@@ -84,7 +84,7 @@ class Chef
84
84
  end
85
85
 
86
86
  requirements.assert(:all_actions) do |a|
87
- a.assertion { ::File.exists?(@plist.to_s) }
87
+ a.assertion { ::File.exist?(@plist.to_s) }
88
88
  a.failure_message Chef::Exceptions::Service,
89
89
  "Could not find plist for #{@new_resource}"
90
90
  end
@@ -215,7 +215,7 @@ class Chef
215
215
  return nil if @plist.nil?
216
216
 
217
217
  # Plist must exist by this point
218
- raise Chef::Exceptions::FileNotFound, "Cannot find #{@plist}!" unless ::File.exists?(@plist)
218
+ raise Chef::Exceptions::FileNotFound, "Cannot find #{@plist}!" unless ::File.exist?(@plist)
219
219
 
220
220
  # Most services have the same internal label as the name of the
221
221
  # plist file. However, there is no rule saying that *has* to be
@@ -132,7 +132,7 @@ class Chef
132
132
  end
133
133
 
134
134
  def update_rcl(value)
135
- FileUtils.touch RC_CONF_LOCAL_PATH unless ::File.exists? RC_CONF_LOCAL_PATH
135
+ FileUtils.touch RC_CONF_LOCAL_PATH unless ::File.exist? RC_CONF_LOCAL_PATH
136
136
  ::File.write(RC_CONF_LOCAL_PATH, value)
137
137
  @rc_conf_local = value
138
138
  end
@@ -56,7 +56,7 @@ class Chef
56
56
 
57
57
  requirements.assert(:all_actions) do |a|
58
58
  chkconfig_file = "/sbin/chkconfig"
59
- a.assertion { ::File.exists? chkconfig_file }
59
+ a.assertion { ::File.exist? chkconfig_file }
60
60
  a.failure_message Chef::Exceptions::Service, "#{chkconfig_file} does not exist!"
61
61
  end
62
62
 
@@ -80,7 +80,7 @@ class Chef
80
80
 
81
81
  super
82
82
 
83
- if ::File.exists?("/sbin/chkconfig")
83
+ if ::File.exist?("/sbin/chkconfig")
84
84
  chkconfig = shell_out!("/sbin/chkconfig --list #{current_resource.service_name}", returns: [0, 1])
85
85
  unless run_levels.nil? || run_levels.empty?
86
86
  all_levels_match = true
@@ -135,7 +135,7 @@ class Chef
135
135
  end
136
136
  end
137
137
  # Get enabled/disabled state by reading job configuration file
138
- if ::File.exists?("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}")
138
+ if ::File.exist?("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}")
139
139
  logger.trace("#{@new_resource} found #{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}")
140
140
  ::File.open("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}", "r") do |file|
141
141
  while line = file.gets
@@ -37,7 +37,7 @@ class Chef
37
37
  if template_available?(new_resource.source)
38
38
  source new_resource.source
39
39
  else
40
- source ::File.expand_path("../support/yum_repo.erb", __FILE__)
40
+ source ::File.expand_path("support/yum_repo.erb", __dir__)
41
41
  local true
42
42
  end
43
43
  sensitive new_resource.sensitive
@@ -41,7 +41,7 @@ class Chef
41
41
  if template_available?(new_resource.source)
42
42
  source new_resource.source
43
43
  else
44
- source ::File.expand_path("../support/zypper_repo.erb", __FILE__)
44
+ source ::File.expand_path("support/zypper_repo.erb", __dir__)
45
45
  local true
46
46
  end
47
47
  sensitive new_resource.sensitive
@@ -115,28 +115,48 @@ class Chef
115
115
  end
116
116
  end
117
117
 
118
+ # the version of gpg installed on the system
119
+ #
120
+ # @return [Gem::Version] the version of GPG
121
+ def gpg_version
122
+ so = shell_out!("gpg --version")
123
+ # matches 2.0 and 2.2 versions from SLES 12 and 15: https://rubular.com/r/e6D0WfGK6SXvUp
124
+ version = /gpg \(GnuPG\)\s*(.*)/.match(so.stdout)[1]
125
+ logger.trace("GPG package version is #{version}")
126
+ Gem::Version.new(version)
127
+ end
128
+
118
129
  # is the provided key already installed
119
130
  # @param [String] key_path the path to the key on the local filesystem
120
131
  #
121
132
  # @return [boolean] is the key already known by rpm
122
133
  def key_installed?(key_path)
123
- so = shell_out("rpm -qa gpg-pubkey*")
134
+ so = shell_out("/bin/rpm -qa gpg-pubkey*")
124
135
  # expected output & match: http://rubular.com/r/RdF7EcXEtb
125
- status = /gpg-pubkey-#{key_fingerprint(key_path)}/.match(so.stdout)
136
+ status = /gpg-pubkey-#{short_key_id(key_path)}/.match(so.stdout)
126
137
  logger.trace("GPG key at #{key_path} is known by rpm? #{status ? "true" : "false"}")
127
138
  status
128
139
  end
129
140
 
130
- # extract the gpg key fingerprint from a local file
141
+ # extract the gpg key's short key id from a local file. Learning moment: This 8 hex value ID
142
+ # is sometimes incorrectly called the fingerprint. The fingerprint is the full length value
143
+ # and googling for that will just result in sad times.
144
+ #
131
145
  # @param [String] key_path the path to the key on the local filesystem
132
146
  #
133
- # @return [String] the fingerprint of the key
134
- def key_fingerprint(key_path)
135
- so = shell_out!("gpg --with-fingerprint #{key_path}")
136
- # expected output and match: http://rubular.com/r/BpfMjxySQM
137
- fingerprint = %r{pub\s*\S*/(\S*)}.match(so.stdout)[1].downcase
138
- logger.trace("GPG fingerprint of key at #{key_path} is #{fingerprint}")
139
- fingerprint
147
+ # @return [String] the short key id of the key
148
+ def short_key_id(key_path)
149
+ if gpg_version >= Gem::Version.new("2.2") # SLES 15+
150
+ so = shell_out!("gpg --import-options import-show --dry-run --import --with-colons #{key_path}")
151
+ # expected output and match: https://rubular.com/r/uXWJo3yfkli1qA
152
+ short_key_id = /fpr:*\h*(\h{8}):/.match(so.stdout)[1].downcase
153
+ else # SLES 12 and earlier
154
+ so = shell_out!("gpg --with-fingerprint #{key_path}")
155
+ # expected output and match: http://rubular.com/r/BpfMjxySQM
156
+ short_key_id = %r{pub\s*\S*/(\S*)}.match(so.stdout)[1].downcase
157
+ end
158
+ logger.trace("GPG short key ID of key at #{key_path} is #{short_key_id}")
159
+ short_key_id
140
160
  end
141
161
 
142
162
  # install the provided gpg key