chef 13.6.4-universal-mingw32 → 13.7.16-universal-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. checksums.yaml +5 -5
  2. data/VERSION +1 -1
  3. data/acceptance/Gemfile +2 -2
  4. data/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/libraries/top_cookbooks.rb +1 -6
  5. data/distro/powershell/chef/chef.psm1 +1 -5
  6. data/lib/chef/api_client.rb +5 -5
  7. data/lib/chef/api_client_v1.rb +6 -6
  8. data/lib/chef/application.rb +3 -2
  9. data/lib/chef/application/knife.rb +4 -0
  10. data/lib/chef/chef_class.rb +2 -2
  11. data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
  12. data/lib/chef/chef_fs/data_handler/data_handler_base.rb +2 -4
  13. data/lib/chef/client.rb +3 -3
  14. data/lib/chef/cookbook/chefignore.rb +4 -0
  15. data/lib/chef/cookbook/cookbook_collection.rb +2 -2
  16. data/lib/chef/cookbook/metadata.rb +2 -2
  17. data/lib/chef/data_bag.rb +1 -1
  18. data/lib/chef/deprecated.rb +10 -0
  19. data/lib/chef/event_dispatch/base.rb +2 -2
  20. data/lib/chef/http.rb +10 -10
  21. data/lib/chef/knife.rb +16 -15
  22. data/lib/chef/knife/configure.rb +12 -36
  23. data/lib/chef/knife/cookbook_upload.rb +4 -4
  24. data/lib/chef/knife/core/bootstrap_context.rb +1 -1
  25. data/lib/chef/knife/core/status_presenter.rb +6 -2
  26. data/lib/chef/knife/core/ui.rb +1 -1
  27. data/lib/chef/knife/data_bag_secret_options.rb +1 -1
  28. data/lib/chef/knife/data_bag_show.rb +1 -1
  29. data/lib/chef/knife/edit.rb +1 -1
  30. data/lib/chef/knife/ssh.rb +47 -35
  31. data/lib/chef/knife/user_create.rb +2 -0
  32. data/lib/chef/knife/user_delete.rb +2 -0
  33. data/lib/chef/knife/user_edit.rb +2 -0
  34. data/lib/chef/knife/user_reregister.rb +2 -0
  35. data/lib/chef/knife/user_show.rb +2 -0
  36. data/lib/chef/mixin/powershell_out.rb +1 -1
  37. data/lib/chef/node/attribute.rb +46 -70
  38. data/lib/chef/node/attribute_collections.rb +5 -5
  39. data/lib/chef/node/common_api.rb +1 -1
  40. data/lib/chef/node/immutable_collections.rb +180 -23
  41. data/lib/chef/node/mixin/state_tracking.rb +6 -6
  42. data/lib/chef/node_map.rb +63 -45
  43. data/lib/chef/property.rb +8 -8
  44. data/lib/chef/provider.rb +9 -3
  45. data/lib/chef/provider/apt_preference.rb +1 -1
  46. data/lib/chef/provider/apt_repository.rb +1 -1
  47. data/lib/chef/provider/apt_update.rb +1 -1
  48. data/lib/chef/provider/file.rb +1 -1
  49. data/lib/chef/provider/group/dscl.rb +6 -2
  50. data/lib/chef/provider/ifconfig.rb +96 -34
  51. data/lib/chef/provider/launchd.rb +0 -1
  52. data/lib/chef/provider/log.rb +3 -13
  53. data/lib/chef/provider/package/dnf.rb +1 -1
  54. data/lib/chef/provider/package/smartos.rb +2 -2
  55. data/lib/chef/provider/reboot.rb +12 -0
  56. data/lib/chef/provider/remote_directory.rb +1 -1
  57. data/lib/chef/provider/remote_file/http.rb +3 -2
  58. data/lib/chef/provider/service/solaris.rb +6 -2
  59. data/lib/chef/provider/systemd_unit.rb +34 -33
  60. data/lib/chef/provider/user/dscl.rb +1 -1
  61. data/lib/chef/provider/windows_path.rb +6 -7
  62. data/lib/chef/provider/windows_task.rb +89 -33
  63. data/lib/chef/provider/yum_repository.rb +24 -9
  64. data/lib/chef/resource/apt_package.rb +1 -0
  65. data/lib/chef/resource/apt_preference.rb +4 -0
  66. data/lib/chef/resource/apt_repository.rb +4 -0
  67. data/lib/chef/resource/apt_update.rb +3 -0
  68. data/lib/chef/resource/bash.rb +4 -0
  69. data/lib/chef/resource/batch.rb +5 -0
  70. data/lib/chef/resource/bff_package.rb +4 -0
  71. data/lib/chef/resource/breakpoint.rb +6 -0
  72. data/lib/chef/resource/cab_package.rb +6 -6
  73. data/lib/chef/resource/chef_gem.rb +13 -0
  74. data/lib/chef/resource/chocolatey_package.rb +4 -6
  75. data/lib/chef/resource/cookbook_file.rb +13 -15
  76. data/lib/chef/resource/cron.rb +2 -0
  77. data/lib/chef/resource/csh.rb +4 -0
  78. data/lib/chef/resource/directory.rb +8 -26
  79. data/lib/chef/resource/dnf_package.rb +5 -0
  80. data/lib/chef/resource/dpkg_package.rb +2 -0
  81. data/lib/chef/resource/dsc_resource.rb +5 -0
  82. data/lib/chef/resource/dsc_script.rb +6 -0
  83. data/lib/chef/resource/env.rb +3 -0
  84. data/lib/chef/resource/erl_call.rb +5 -0
  85. data/lib/chef/resource/execute.rb +5 -1
  86. data/lib/chef/resource/file.rb +2 -1
  87. data/lib/chef/resource/file/verification.rb +10 -0
  88. data/lib/chef/resource/freebsd_package.rb +10 -2
  89. data/lib/chef/resource/gem_package.rb +2 -0
  90. data/lib/chef/resource/git.rb +2 -0
  91. data/lib/chef/resource/group.rb +1 -0
  92. data/lib/chef/resource/homebrew_package.rb +3 -0
  93. data/lib/chef/resource/http_request.rb +2 -0
  94. data/lib/chef/resource/ifconfig.rb +23 -150
  95. data/lib/chef/resource/ips_package.rb +1 -0
  96. data/lib/chef/resource/ksh.rb +6 -0
  97. data/lib/chef/resource/launchd.rb +5 -4
  98. data/lib/chef/resource/link.rb +10 -0
  99. data/lib/chef/resource/log.rb +19 -46
  100. data/lib/chef/resource/macports_package.rb +1 -0
  101. data/lib/chef/resource/mdadm.rb +4 -0
  102. data/lib/chef/resource/mount.rb +1 -0
  103. data/lib/chef/resource/msu_package.rb +7 -8
  104. data/lib/chef/resource/ohai.rb +2 -0
  105. data/lib/chef/resource/openbsd_package.rb +3 -0
  106. data/lib/chef/resource/osx_profile.rb +10 -40
  107. data/lib/chef/resource/package.rb +6 -0
  108. data/lib/chef/resource/pacman_package.rb +1 -0
  109. data/lib/chef/resource/paludis_package.rb +3 -0
  110. data/lib/chef/resource/perl.rb +4 -0
  111. data/lib/chef/resource/portage_package.rb +1 -0
  112. data/lib/chef/resource/powershell_package.rb +5 -0
  113. data/lib/chef/resource/powershell_script.rb +8 -0
  114. data/lib/chef/resource/python.rb +4 -0
  115. data/lib/chef/resource/reboot.rb +14 -20
  116. data/lib/chef/resource/registry_key.rb +1 -0
  117. data/lib/chef/resource/remote_directory.rb +3 -0
  118. data/lib/chef/resource/remote_file.rb +2 -0
  119. data/lib/chef/resource/resource_notification.rb +17 -0
  120. data/lib/chef/resource/route.rb +1 -0
  121. data/lib/chef/resource/rpm_package.rb +1 -0
  122. data/lib/chef/resource/ruby.rb +4 -0
  123. data/lib/chef/resource/ruby_block.rb +3 -0
  124. data/lib/chef/resource/script.rb +4 -0
  125. data/lib/chef/resource/service.rb +1 -0
  126. data/lib/chef/resource/smartos_package.rb +1 -0
  127. data/lib/chef/resource/solaris_package.rb +1 -0
  128. data/lib/chef/resource/subversion.rb +1 -0
  129. data/lib/chef/resource/systemd_unit.rb +6 -0
  130. data/lib/chef/resource/template.rb +9 -0
  131. data/lib/chef/resource/user.rb +1 -0
  132. data/lib/chef/resource/windows_package.rb +2 -0
  133. data/lib/chef/resource/windows_path.rb +5 -10
  134. data/lib/chef/resource/windows_service.rb +3 -0
  135. data/lib/chef/resource/windows_task.rb +66 -87
  136. data/lib/chef/resource/yum_repository.rb +26 -22
  137. data/lib/chef/resource/zypper_package.rb +2 -0
  138. data/lib/chef/resource/zypper_repository.rb +6 -1
  139. data/lib/chef/run_context.rb +8 -2
  140. data/lib/chef/server_api.rb +1 -0
  141. data/lib/chef/util/selinux.rb +5 -4
  142. data/lib/chef/version.rb +1 -1
  143. data/lib/chef/version/platform.rb +18 -0
  144. data/lib/chef/version_constraint/platform.rb +2 -0
  145. data/spec/data/client.d_00/02-strings.rb +2 -0
  146. data/spec/functional/assets/chefinittest +6 -4
  147. data/spec/functional/knife/ssh_spec.rb +54 -7
  148. data/spec/functional/resource/bff_spec.rb +3 -3
  149. data/spec/functional/resource/ifconfig_spec.rb +1 -1
  150. data/spec/functional/resource/mount_spec.rb +7 -3
  151. data/spec/functional/resource/user/useradd_spec.rb +4 -4
  152. data/spec/functional/resource/windows_task_spec.rb +6 -6
  153. data/spec/functional/win32/security_spec.rb +7 -33
  154. data/spec/integration/knife/data_bag_show_spec.rb +1 -1
  155. data/spec/integration/recipes/noop_resource_spec.rb +1 -1
  156. data/spec/integration/recipes/recipe_dsl_spec.rb +30 -30
  157. data/spec/integration/recipes/resource_action_spec.rb +2 -2
  158. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +71 -15
  159. data/spec/spec_helper.rb +19 -0
  160. data/spec/support/shared/functional/execute_resource.rb +1 -1
  161. data/spec/support/shared/unit/application_dot_d.rb +2 -0
  162. data/spec/support/shared/unit/execute_resource.rb +8 -1
  163. data/spec/support/shared/unit/provider/file.rb +9 -1
  164. data/spec/unit/chef_fs/data_handler/data_bag_item_data_handler.rb +10 -7
  165. data/spec/unit/chef_fs/file_system/repository/directory_spec.rb +2 -2
  166. data/spec/unit/client_spec.rb +1 -1
  167. data/spec/unit/deprecated_spec.rb +4 -4
  168. data/spec/unit/http_spec.rb +9 -0
  169. data/spec/unit/knife/bootstrap_spec.rb +5 -0
  170. data/spec/unit/knife/configure_spec.rb +10 -60
  171. data/spec/unit/knife/data_bag_create_spec.rb +40 -2
  172. data/spec/unit/knife/data_bag_show_spec.rb +16 -2
  173. data/spec/unit/knife/ssh_spec.rb +85 -39
  174. data/spec/unit/knife_spec.rb +2 -0
  175. data/spec/unit/lwrp_spec.rb +5 -3
  176. data/spec/unit/mixin/powershell_type_coercions_spec.rb +7 -6
  177. data/spec/unit/node/attribute_spec.rb +55 -24
  178. data/spec/unit/node/immutable_collections_spec.rb +28 -14
  179. data/spec/unit/node/vivid_mash_spec.rb +27 -10
  180. data/spec/unit/node_map_spec.rb +34 -0
  181. data/spec/unit/property_spec.rb +13 -13
  182. data/spec/unit/provider/group/dscl_spec.rb +14 -5
  183. data/spec/unit/provider/ifconfig_spec.rb +10 -3
  184. data/spec/unit/provider/remote_file/http_spec.rb +23 -19
  185. data/spec/unit/provider/service/solaris_smf_service_spec.rb +6 -5
  186. data/spec/unit/provider/user/dscl_spec.rb +26 -0
  187. data/spec/unit/provider/windows_task_spec.rb +148 -4
  188. data/spec/unit/provider_spec.rb +1 -1
  189. data/spec/unit/resource/apt_package_spec.rb +1 -1
  190. data/spec/unit/resource/bash_spec.rb +8 -10
  191. data/spec/unit/resource/batch_spec.rb +1 -1
  192. data/spec/unit/resource/cab_package_spec.rb +19 -1
  193. data/spec/unit/resource/chef_gem_spec.rb +3 -3
  194. data/spec/unit/resource/chocolatey_package_spec.rb +10 -10
  195. data/spec/unit/resource/conditional_spec.rb +2 -2
  196. data/spec/unit/resource/cookbook_file_spec.rb +24 -30
  197. data/spec/unit/resource/cron_spec.rb +79 -82
  198. data/spec/unit/resource/csh_spec.rb +8 -10
  199. data/spec/unit/resource/deploy_spec.rb +1 -1
  200. data/spec/unit/resource/directory_spec.rb +28 -31
  201. data/spec/unit/resource/dnf_package_spec.rb +9 -9
  202. data/spec/unit/resource/env_spec.rb +7 -7
  203. data/spec/unit/resource/erl_call_spec.rb +9 -9
  204. data/spec/unit/resource/execute_spec.rb +6 -6
  205. data/spec/unit/resource/file/verification_spec.rb +18 -4
  206. data/spec/unit/resource/file_spec.rb +53 -56
  207. data/spec/unit/resource/freebsd_package_spec.rb +7 -7
  208. data/spec/unit/resource/gem_package_spec.rb +1 -1
  209. data/spec/unit/resource/git_spec.rb +7 -9
  210. data/spec/unit/resource/group_spec.rb +60 -70
  211. data/spec/unit/resource/http_request_spec.rb +16 -19
  212. data/spec/unit/resource/ifconfig_spec.rb +3 -3
  213. data/spec/unit/resource/ips_package_spec.rb +3 -5
  214. data/spec/unit/resource/ksh_spec.rb +8 -10
  215. data/spec/unit/resource/launchd_spec.rb +17 -10
  216. data/spec/unit/resource/link_spec.rb +53 -53
  217. data/spec/unit/resource/log_spec.rb +24 -28
  218. data/spec/unit/resource/mdadm_spec.rb +42 -44
  219. data/spec/unit/resource/mount_spec.rb +97 -99
  220. data/spec/unit/resource/msu_package_spec.rb +14 -8
  221. data/spec/unit/resource/ohai_spec.rb +15 -17
  222. data/spec/unit/resource/openbsd_package_spec.rb +3 -3
  223. data/spec/unit/resource/osx_profile_spec.rb +7 -7
  224. data/spec/unit/resource/package_spec.rb +36 -40
  225. data/spec/unit/resource/perl_spec.rb +8 -11
  226. data/spec/unit/resource/portage_package_spec.rb +8 -10
  227. data/spec/unit/resource/powershell_package_spec.rb +9 -9
  228. data/spec/unit/resource/python_spec.rb +8 -11
  229. data/spec/unit/resource/reboot_spec.rb +50 -0
  230. data/spec/unit/resource/registry_key_spec.rb +84 -98
  231. data/spec/unit/resource/remote_directory_spec.rb +40 -42
  232. data/spec/unit/resource/remote_file_spec.rb +78 -80
  233. data/spec/unit/resource/route_spec.rb +42 -44
  234. data/spec/unit/resource/rpm_package_spec.rb +5 -7
  235. data/spec/unit/resource/ruby_block_spec.rb +14 -16
  236. data/spec/unit/resource/ruby_spec.rb +8 -12
  237. data/spec/unit/resource/scm_spec.rb +66 -69
  238. data/spec/unit/resource/script_spec.rb +1 -1
  239. data/spec/unit/resource/service_spec.rb +80 -83
  240. data/spec/unit/resource/smartos_package_spec.rb +5 -0
  241. data/spec/unit/resource/solaris_package_spec.rb +3 -5
  242. data/spec/unit/resource/subversion_spec.rb +18 -16
  243. data/spec/unit/resource/systemd_unit_spec.rb +50 -54
  244. data/spec/unit/resource/template_spec.rb +56 -61
  245. data/spec/unit/resource/user_spec.rb +47 -53
  246. data/spec/unit/resource/windows_package_spec.rb +1 -1
  247. data/spec/unit/resource/windows_path_spec.rb +11 -8
  248. data/spec/unit/resource/windows_task_spec.rb +129 -33
  249. data/spec/unit/resource/yum_package_spec.rb +1 -1
  250. data/spec/unit/resource/yum_repository_spec.rb +61 -8
  251. data/spec/unit/resource/zypper_repository_spec.rb +17 -18
  252. data/spec/unit/util/selinux_spec.rb +3 -6
  253. data/tasks/dependencies.rb +0 -5
  254. data/tasks/rspec.rb +1 -1
  255. metadata +7 -19
  256. data/acceptance/.DS_Store +0 -0
  257. data/acceptance/.bundle/config +0 -2
  258. data/acceptance/top-cookbooks/.kitchen.docker.yml +0 -13
  259. data/acceptance/top-cookbooks/.kitchen.git.yml +0 -11
  260. data/distro/.DS_Store +0 -0
  261. data/lib/.DS_Store +0 -0
  262. data/lib/chef/.DS_Store +0 -0
  263. data/lib/chef/knife/.DS_Store +0 -0
  264. data/lib/chef/mixin/.DS_Store +0 -0
  265. data/spec/.DS_Store +0 -0
  266. data/spec/functional/.DS_Store +0 -0
  267. data/spec/support/.DS_Store +0 -0
  268. data/spec/unit/.DS_Store +0 -0
  269. data/tasks/.DS_Store +0 -0
@@ -20,6 +20,9 @@ require "chef/resource/service"
20
20
 
21
21
  class Chef
22
22
  class Resource
23
+ # Use the windows_service resource to manage a service on the Microsoft Windows platform.
24
+ #
25
+ # @since 12.0
23
26
  class WindowsService < Chef::Resource::Service
24
27
 
25
28
  # Until #1773 is resolved, you need to manually specify the windows_service resource
@@ -20,21 +20,18 @@ require "chef/resource"
20
20
 
21
21
  class Chef
22
22
  class Resource
23
+ # Use the windows_task resource to create, delete or run a Windows scheduled task. Requires Windows Server 2008
24
+ # or later due to API usage.
25
+ # @since 13.0
23
26
  class WindowsTask < Chef::Resource
24
27
 
28
+ resource_name :windows_task
25
29
  provides :windows_task, os: "windows"
26
30
 
27
31
  allowed_actions :create, :delete, :run, :end, :enable, :disable
28
32
  default_action :create
29
33
 
30
- def initialize(name, run_context = nil)
31
- super
32
- @resource_name = :windows_task
33
- @task_name = name
34
- @action = :create
35
- end
36
-
37
- property :task_name, String, regex: [/\A[^\/\:\*\?\<\>\|]+\z/]
34
+ property :task_name, String, regex: [/\A[^\/\:\*\?\<\>\|]+\z/], name_property: true
38
35
  property :command, String
39
36
  property :cwd, String
40
37
  property :user, String, default: "SYSTEM"
@@ -44,22 +41,22 @@ class Chef
44
41
  property :interactive_enabled, [TrueClass, FalseClass], default: false
45
42
  property :frequency_modifier, [Integer, String], default: 1
46
43
  property :frequency, equal_to: [:minute,
47
- :hourly,
48
- :daily,
49
- :weekly,
50
- :monthly,
51
- :once,
52
- :on_logon,
53
- :onstart,
54
- :on_idle,
55
- :none], default: :hourly
44
+ :hourly,
45
+ :daily,
46
+ :weekly,
47
+ :monthly,
48
+ :once,
49
+ :on_logon,
50
+ :onstart,
51
+ :on_idle,
52
+ :none], default: :hourly
56
53
  property :start_day, String
57
54
  property :start_time, String
58
55
  property :day, [String, Integer]
59
56
  property :months, String
60
57
  property :idle_time, Integer
61
- property :random_delay, String
62
- property :execution_time_limit, String
58
+ property :random_delay, [String, Integer]
59
+ property :execution_time_limit, [String, Integer], default: "PT72H" # 72 hours in ISO8601 duration format
63
60
 
64
61
  attr_accessor :exists, :status, :enabled
65
62
 
@@ -71,15 +68,11 @@ class Chef
71
68
  end
72
69
 
73
70
  if execution_time_limit
74
- raise ArgumentError, "Invalid value passed for `execution_time_limit`. Please pass seconds as a String e.g. '60'." if execution_time_limit.to_i == 0
75
- duration = sec_to_dur(execution_time_limit)
76
- execution_time_limit(duration)
77
- else
78
- # schtask sets execution_time_limit as PT72H by default
79
- # We are setting the default value here so that we can do idempotency check later
80
- # Note: We can't use `default` in the property
81
- # because it will raise error for Invalid values passed as "PT72H" is not in seconds
82
- execution_time_limit("PT72H")
71
+ unless execution_time_limit == "PT72H" # don't double convert an ISO8601 format duration
72
+ raise ArgumentError, "Invalid value passed for `execution_time_limit`. Please pass seconds as an Integer (e.g. 60) or a String with numeric values only (e.g. '60')." unless numeric_value_in_string?(execution_time_limit)
73
+ duration = sec_to_dur(execution_time_limit)
74
+ execution_time_limit(duration)
75
+ end
83
76
  end
84
77
 
85
78
  validate_start_time(start_time, frequency)
@@ -89,45 +82,57 @@ class Chef
89
82
  validate_create_frequency_modifier(frequency, frequency_modifier)
90
83
  validate_create_day(day, frequency) if day
91
84
  validate_create_months(months, frequency) if months
92
- validate_idle_time(idle_time, frequency) if idle_time
85
+ validate_idle_time(idle_time, frequency) if ( !idle_time.nil? && ([:minute, :hourly, :daily, :weekly, :monthly].include? frequency)) || (idle_time.nil? || !(idle_time > 0 && idle_time <= 999)) && !([:minute, :hourly, :daily, :weekly, :monthly].include? frequency)
93
86
  end
94
87
 
95
88
  private
96
89
 
90
+ # Validate the passed value is numeric values only if it is a string
91
+ def numeric_value_in_string?(val)
92
+ return true if Integer(val)
93
+ rescue ArgumentError
94
+ false
95
+ end
96
+
97
97
  def validate_random_delay(random_delay, frequency)
98
98
  if [:once, :on_logon, :onstart, :on_idle, :none].include? frequency
99
99
  raise ArgumentError, "`random_delay` property is supported only for frequency :minute, :hourly, :daily, :weekly and :monthly"
100
100
  end
101
101
 
102
- raise ArgumentError, "Invalid value passed for `random_delay`. Please pass seconds as a String e.g. '60'." if random_delay.to_i == 0
102
+ 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)
103
103
  end
104
104
 
105
+ # @todo when we drop ruby 2.3 support this should be converted to .match?() instead of =~f
105
106
  def validate_start_day(start_day, frequency)
106
107
  if [:once, :on_logon, :onstart, :on_idle, :none].include? frequency
107
108
  raise ArgumentError, "`start_day` property is not supported with frequency: #{frequency}"
108
109
  end
110
+
111
+ # make sure the start_day is in MM/DD/YYYY format: http://rubular.com/r/cgjHemtWl5
112
+ raise ArgumentError, "`start_day` property must be in the MM/DD/YYYY format." unless /^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d$/ =~ start_day
109
113
  end
110
114
 
115
+ # @todo when we drop ruby 2.3 support this should be converted to .match?() instead of =~
111
116
  def validate_start_time(start_time, frequency)
112
- if frequency == :once
113
- raise ArgumentError, "`start_time` needs to be provided with `frequency :once`" unless start_time
114
- elsif frequency == :none
115
- raise ArgumentError, "`start_time` property is not supported with `frequency :none`" if start_time
117
+ if start_time
118
+ raise ArgumentError, "`start_time` property is not supported with `frequency :none`" if frequency == :none
119
+ raise ArgumentError, "`start_time` property must be in the HH:mm format (e.g. 6:20pm -> 18:20)." unless /^[0-2][0-9]:[0-5][0-9]$/ =~ start_time
120
+ else
121
+ raise ArgumentError, "`start_time` needs to be provided with `frequency :once`" if frequency == :once
116
122
  end
117
123
  end
118
124
 
119
125
  SYSTEM_USERS = ['NT AUTHORITY\SYSTEM', "SYSTEM", 'NT AUTHORITY\LOCALSERVICE', 'NT AUTHORITY\NETWORKSERVICE', 'BUILTIN\USERS', "USERS"].freeze
120
126
 
121
127
  def validate_user_and_password(user, password)
122
- if user && use_password?(user)
123
- if password.nil?
124
- raise ArgumentError, "Can't specify a non-system user without a password!"
125
- end
128
+ if password_required?(user) && password.nil?
129
+ raise ArgumentError, %q{Cannot specify a user other than the system users without specifying a password!. Valid passwordless users: 'NT AUTHORITY\SYSTEM', 'SYSTEM', 'NT AUTHORITY\LOCALSERVICE', 'NT AUTHORITY\NETWORKSERVICE', 'BUILTIN\USERS', 'USERS'}
126
130
  end
127
131
  end
128
132
 
129
- def use_password?(user)
130
- @use_password ||= !SYSTEM_USERS.include?(user.upcase)
133
+ def password_required?(user)
134
+ return false if user.nil?
135
+ @password_required ||= !SYSTEM_USERS.include?(user.upcase)
131
136
  end
132
137
 
133
138
  def validate_interactive_setting(interactive_enabled, password)
@@ -143,23 +148,23 @@ class Chef
143
148
  case frequency
144
149
  when :minute
145
150
  unless frequency_modifier.to_i > 0 && frequency_modifier.to_i <= 1439
146
- raise ArgumentError, "frequency_modifier value #{frequency_modifier} is invalid. Valid values for :minute frequency are 1 - 1439."
151
+ raise ArgumentError, "frequency_modifier value #{frequency_modifier} is invalid. Valid values for :minute frequency are 1 - 1439."
147
152
  end
148
153
  when :hourly
149
154
  unless frequency_modifier.to_i > 0 && frequency_modifier.to_i <= 23
150
- raise ArgumentError, "frequency_modifier value #{frequency_modifier} is invalid. Valid values for :hourly frequency are 1 - 23."
155
+ raise ArgumentError, "frequency_modifier value #{frequency_modifier} is invalid. Valid values for :hourly frequency are 1 - 23."
151
156
  end
152
157
  when :daily
153
158
  unless frequency_modifier.to_i > 0 && frequency_modifier.to_i <= 365
154
- raise ArgumentError, "frequency_modifier value #{frequency_modifier} is invalid. Valid values for :daily frequency are 1 - 365."
159
+ raise ArgumentError, "frequency_modifier value #{frequency_modifier} is invalid. Valid values for :daily frequency are 1 - 365."
155
160
  end
156
161
  when :weekly
157
162
  unless frequency_modifier.to_i > 0 && frequency_modifier.to_i <= 52
158
- raise ArgumentError, "frequency_modifier value #{frequency_modifier} is invalid. Valid values for :weekly frequency are 1 - 52."
163
+ raise ArgumentError, "frequency_modifier value #{frequency_modifier} is invalid. Valid values for :weekly frequency are 1 - 52."
159
164
  end
160
165
  when :monthly
161
166
  unless ("1".."12").to_a.push("FIRST", "SECOND", "THIRD", "FOURTH", "LAST", "LASTDAY").include?(frequency_modifier.to_s.upcase)
162
- raise ArgumentError, "frequency_modifier value #{frequency_modifier} is invalid. Valid values for :monthly frequency are 1 - 12, 'FIRST', 'SECOND', 'THIRD', 'FOURTH', 'LAST', 'LASTDAY'."
167
+ raise ArgumentError, "frequency_modifier value #{frequency_modifier} is invalid. Valid values for :monthly frequency are 1 - 12, 'FIRST', 'SECOND', 'THIRD', 'FOURTH', 'LAST', 'LASTDAY'."
163
168
  end
164
169
  end
165
170
  end
@@ -167,26 +172,24 @@ class Chef
167
172
 
168
173
  def validate_create_day(day, frequency)
169
174
  unless [:weekly, :monthly].include?(frequency)
170
- raise "day attribute is only valid for tasks that run monthly or weekly"
175
+ raise "day property is only valid for tasks that run monthly or weekly"
171
176
  end
172
177
  if day.is_a?(String) && day.to_i.to_s != day
173
178
  days = day.split(",")
174
179
  days.each do |d|
175
180
  unless ["mon", "tue", "wed", "thu", "fri", "sat", "sun", "*"].include?(d.strip.downcase)
176
- raise "day attribute invalid. Only valid values are: MON, TUE, WED, THU, FRI, SAT, SUN and *. Multiple values must be separated by a comma."
181
+ raise ArgumentError, "day property invalid. Only valid values are: MON, TUE, WED, THU, FRI, SAT, SUN and *. Multiple values must be separated by a comma."
177
182
  end
178
183
  end
179
184
  end
180
185
  end
181
186
 
182
187
  def validate_create_months(months, frequency)
183
- unless [:monthly].include?(frequency)
184
- raise "months attribute is only valid for tasks that run monthly"
185
- end
188
+ raise ArgumentError, "months property is only valid for tasks that run monthly" unless frequency == :monthly
186
189
  if months.is_a? String
187
190
  months.split(",").each do |month|
188
191
  unless ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC", "*"].include?(month.strip.upcase)
189
- raise "months attribute invalid. Only valid values are: JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC and *. Multiple values must be separated by a comma."
192
+ raise ArgumentError, "months property invalid. Only valid values are: JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC and *. Multiple values must be separated by a comma."
190
193
  end
191
194
  end
192
195
  end
@@ -194,47 +197,23 @@ class Chef
194
197
 
195
198
  def validate_idle_time(idle_time, frequency)
196
199
  unless [:on_idle].include?(frequency)
197
- raise "idle_time attribute is only valid for tasks that run on_idle"
200
+ raise ArgumentError, "idle_time property is only valid for tasks that run on_idle"
198
201
  end
199
-
200
- unless idle_time.to_i > 0 && idle_time.to_i <= 999
201
- raise "idle_time value #{idle_time} is invalid. Valid values for :on_idle frequency are 1 - 999."
202
+ if idle_time.nil?
203
+ raise ArgumentError, "idle_time value should be set for :on_idle frequency."
204
+ end
205
+ unless idle_time > 0 && idle_time <= 999
206
+ raise ArgumentError, "idle_time value #{idle_time} is invalid. Valid values for :on_idle frequency are 1 - 999."
202
207
  end
203
208
  end
204
209
 
205
- # Convert the number of seconds to an ISO8601 duration format
206
- # @see http://tools.ietf.org/html/rfc2445#section-4.3.6
207
- # @param [Integer] seconds The amount of seconds for this duration
210
+ # Converts the number of seconds to an ISO8601 duration format and returns it.
211
+ # Ref : https://github.com/arnau/ISO8601/blob/master/lib/iso8601/duration.rb#L18-L23
212
+ # e.g.
213
+ # ISO8601::Duration.new(65707200)
214
+ # returns 'P65707200S'
208
215
  def sec_to_dur(seconds)
209
- seconds = seconds.to_i
210
- return if seconds == 0
211
- iso_str = "P"
212
- if seconds > 604_800 # more than a week
213
- weeks = seconds / 604_800
214
- seconds -= (604_800 * weeks)
215
- iso_str << "#{weeks}W"
216
- end
217
- if seconds > 86_400 # more than a day
218
- days = seconds / 86_400
219
- seconds -= (86_400 * days)
220
- iso_str << "#{days}D"
221
- end
222
- if seconds > 0
223
- iso_str << "T"
224
- if seconds > 3600 # more than an hour
225
- hours = seconds / 3600
226
- seconds -= (3600 * hours)
227
- iso_str << "#{hours}H"
228
- end
229
- if seconds > 60 # more than a minute
230
- minutes = seconds / 60
231
- seconds -= (60 * minutes)
232
- iso_str << "#{minutes}M"
233
- end
234
- iso_str << "#{seconds}S"
235
- end
236
-
237
- iso_str
216
+ ISO8601::Duration.new(seconds.to_i).to_s
238
217
  end
239
218
 
240
219
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Thom May (<thom@chef.io>)
3
- # Copyright:: Copyright (c) 2016 Chef Software, Inc.
3
+ # Copyright:: Copyright (c) 2016-2017 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,55 +20,59 @@ require "chef/resource"
20
20
 
21
21
  class Chef
22
22
  class Resource
23
+ # Use the yum_repository resource to manage a Yum repository configuration file located at /etc/yum.repos.d/repositoryid.repo
24
+ # on the local machine. This configuration file specifies which repositories to reference, how to handle cached data, etc.
25
+ #
26
+ # @since 12.14
23
27
  class YumRepository < Chef::Resource
24
28
  resource_name :yum_repository
25
29
  provides :yum_repository
26
30
 
27
31
  # http://linux.die.net/man/5/yum.conf as well as
28
32
  # http://dnf.readthedocs.io/en/latest/conf_ref.html
29
- property :baseurl, [String, Array], regex: /.*/
33
+ property :baseurl, [String, Array]
30
34
  property :clean_headers, [TrueClass, FalseClass], default: false # deprecated
31
35
  property :clean_metadata, [TrueClass, FalseClass], default: true
32
36
  property :cost, String, regex: /^\d+$/
33
- property :description, String, regex: /.*/, default: "Yum Repository"
37
+ property :description, String, default: "Yum Repository"
34
38
  property :enabled, [TrueClass, FalseClass], default: true
35
39
  property :enablegroups, [TrueClass, FalseClass]
36
- property :exclude, String, regex: /.*/
40
+ property :exclude, String
37
41
  property :failovermethod, String, equal_to: %w{priority roundrobin}
38
42
  property :fastestmirror_enabled, [TrueClass, FalseClass]
39
43
  property :gpgcheck, [TrueClass, FalseClass], default: true
40
- property :gpgkey, [String, Array], regex: /.*/
44
+ property :gpgkey, [String, Array]
41
45
  property :http_caching, String, equal_to: %w{packages all none}
42
- property :include_config, String, regex: /.*/
43
- property :includepkgs, String, regex: /.*/
46
+ property :include_config, String
47
+ property :includepkgs, String
44
48
  property :keepalive, [TrueClass, FalseClass]
45
49
  property :make_cache, [TrueClass, FalseClass], default: true
46
50
  property :max_retries, [String, Integer]
47
51
  property :metadata_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/, /never/]
48
- property :metalink, String, regex: /.*/
52
+ property :metalink, String
49
53
  property :mirror_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/]
50
- property :mirrorexpire, String, regex: /.*/
54
+ property :mirrorexpire, String
51
55
  property :mirrorlist_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/]
52
- property :mirrorlist, String, regex: /.*/
56
+ property :mirrorlist, String
53
57
  property :mode, default: "0644"
54
58
  property :options, Hash
55
- property :password, String, regex: /.*/
56
- property :priority, String, regex: /^(\d?[0-9]|[0-9][0-9])$/
57
- property :proxy_password, String, regex: /.*/
58
- property :proxy_username, String, regex: /.*/
59
- property :proxy, String, regex: /.*/
59
+ property :password, String
60
+ property :priority, String, regex: /^(\d?[1-9]|[0-9][0-9])$/
61
+ property :proxy_password, String
62
+ property :proxy_username, String
63
+ property :proxy, String
60
64
  property :repo_gpgcheck, [TrueClass, FalseClass]
61
65
  property :report_instanceid, [TrueClass, FalseClass]
62
- property :repositoryid, String, regex: /.*/, name_property: true
66
+ property :repositoryid, String, name_property: true
63
67
  property :skip_if_unavailable, [TrueClass, FalseClass]
64
- property :source, String, regex: /.*/
65
- property :sslcacert, String, regex: /.*/
66
- property :sslclientcert, String, regex: /.*/
67
- property :sslclientkey, String, regex: /.*/
68
+ property :source, String
69
+ property :sslcacert, String
70
+ property :sslclientcert, String
71
+ property :sslclientkey, String
68
72
  property :sslverify, [TrueClass, FalseClass]
69
- property :timeout, String, regex: /^\d+$/
70
73
  property :throttle, [String, Integer]
71
- property :username, String, regex: /.*/
74
+ property :timeout, String, regex: /^\d+$/
75
+ property :username, String
72
76
 
73
77
  default_action :create
74
78
  allowed_actions :create, :remove, :makecache, :add, :delete
@@ -20,6 +20,8 @@ require "chef/resource/package"
20
20
 
21
21
  class Chef
22
22
  class Resource
23
+ # Use the zypper_package resource to install, upgrade, and remove packages with Zypper for the SUSE Enterprise and
24
+ # OpenSUSE platforms.
23
25
  class ZypperPackage < Chef::Resource::Package
24
26
  resource_name :zypper_package
25
27
  provides :package, platform_family: "suse"
@@ -20,6 +20,11 @@ require "chef/resource"
20
20
 
21
21
  class Chef
22
22
  class Resource
23
+ # The zypper_repository resource allows for the creation of Zypper package repositories on SUSE Enterprise Linux and
24
+ # openSUSE systems. This resource maintains full compatibility with the zypper_repository resource in the existing
25
+ # zypper cookbook.
26
+ #
27
+ # @since 13.3
23
28
  class ZypperRepository < Chef::Resource
24
29
  resource_name :zypper_repository
25
30
  provides :zypper_repo
@@ -38,7 +43,7 @@ class Chef
38
43
  property :keeppackages, [true, false], default: false
39
44
  property :mode, default: "0644"
40
45
  property :refresh_cache, [true, false], default: true
41
- property :source, String, regex: /.*/
46
+ property :source, String
42
47
  property :cookbook, String
43
48
  property :gpgautoimportkeys, [true, false], default: true
44
49
 
@@ -29,7 +29,6 @@ require "forwardable"
29
29
 
30
30
  class Chef
31
31
 
32
- # == Chef::RunContext
33
32
  # Value object that loads and tracks the context of a Chef run
34
33
  class RunContext
35
34
  #
@@ -312,7 +311,7 @@ class Chef
312
311
  #
313
312
  # @param recipe_names [Array[String]] The recipe name (e.g 'my_cookbook' or
314
313
  # 'my_cookbook::my_resource').
315
- # @param current_cookbook The cookbook we are currently running in.
314
+ # @param current_cookbook [String] The cookbook we are currently running in.
316
315
  #
317
316
  # @return A truthy value if the load occurred; `false` if already loaded.
318
317
  #
@@ -556,11 +555,18 @@ ERROR_MESSAGE
556
555
  @reboot_info = reboot_info
557
556
  end
558
557
 
558
+ #
559
+ # Cancels a pending reboot
560
+ #
559
561
  def cancel_reboot
560
562
  Chef::Log.info "Changing reboot status from #{reboot_info.inspect} to {}"
561
563
  @reboot_info = {}
562
564
  end
563
565
 
566
+ #
567
+ # Checks to see if a reboot has been requested
568
+ # @return [Boolean]
569
+ #
564
570
  def reboot_requested?
565
571
  reboot_info.size > 0
566
572
  end
@@ -31,6 +31,7 @@ class Chef
31
31
 
32
32
  def initialize(url = Chef::Config[:chef_server_url], options = {})
33
33
  options[:client_name] ||= Chef::Config[:node_name]
34
+ options[:raw_key] ||= Chef::Config[:client_key_contents]
34
35
  options[:signing_key_filename] ||= Chef::Config[:client_key] unless options[:raw_key]
35
36
  options[:signing_key_filename] = nil if chef_zero_uri?(url)
36
37
  options[:inflate_json_class] = false
@@ -48,10 +48,11 @@ class Chef
48
48
 
49
49
  def restore_security_context(file_path, recursive = false)
50
50
  if restorecon_path
51
- restorecon_command = recursive ? "#{restorecon_path} -R -r" : "#{restorecon_path} -R"
52
- restorecon_command += " \"#{file_path}\""
53
- Chef::Log.debug("Restoring selinux security content with #{restorecon_command}")
54
- shell_out!(restorecon_command)
51
+ restorecon_flags = [ "-R" ]
52
+ restorecon_flags << "-r" if recursive
53
+ restorecon_flags << file_path
54
+ Chef::Log.debug("Restoring selinux security content with #{restorecon_path}")
55
+ shell_out_compact!(restorecon_path, restorecon_flags)
55
56
  else
56
57
  Chef::Log.warn "Can not find 'restorecon' on the system. Skipping selinux security context restore."
57
58
  end