chef 17.8.25-universal-mingw32 → 17.9.46-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -3
  3. data/README.md +1 -1
  4. data/lib/chef/application/exit_code.rb +7 -21
  5. data/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb +1 -1
  6. data/lib/chef/chef_fs/file_system/repository/base_file.rb +1 -1
  7. data/lib/chef/chef_fs/file_system/repository/file_system_entry.rb +1 -1
  8. data/lib/chef/compliance/input_collection.rb +1 -1
  9. data/lib/chef/compliance/waiver_collection.rb +1 -1
  10. data/lib/chef/cookbook/syntax_check.rb +1 -1
  11. data/lib/chef/cookbook_uploader.rb +1 -1
  12. data/lib/chef/cookbook_version.rb +1 -1
  13. data/lib/chef/provider/cron.rb +2 -2
  14. data/lib/chef/provider/directory.rb +2 -2
  15. data/lib/chef/provider/ifconfig.rb +5 -5
  16. data/lib/chef/provider/package/yum/python_helper.rb +81 -25
  17. data/lib/chef/provider/package/yum.rb +39 -12
  18. data/lib/chef/provider/package.rb +5 -5
  19. data/lib/chef/provider/user/mac.rb +3 -3
  20. data/lib/chef/provider.rb +4 -1
  21. data/lib/chef/providers.rb +0 -1
  22. data/lib/chef/resource/apt_package.rb +2 -2
  23. data/lib/chef/resource/archive_file.rb +6 -6
  24. data/lib/chef/resource/chef_client_config.rb +2 -3
  25. data/lib/chef/resource/chocolatey_package.rb +3 -3
  26. data/lib/chef/resource/cron/cron.rb +75 -1
  27. data/lib/chef/resource/cron/cron_d.rb +2 -1
  28. data/lib/chef/resource/habitat/habitat_sup.rb +1 -1
  29. data/lib/chef/resource/habitat/habitat_sup_windows.rb +1 -1
  30. data/lib/chef/resource/homebrew_tap.rb +1 -5
  31. data/lib/chef/resource/inspec_waiver_file_entry.rb +1 -1
  32. data/lib/chef/resource/launchd.rb +2 -2
  33. data/lib/chef/resource/lwrp_base.rb +1 -1
  34. data/lib/chef/resource/powershell_package_source.rb +8 -8
  35. data/lib/chef/resource/remote_file.rb +1 -1
  36. data/lib/chef/resource/rhsm_register.rb +3 -3
  37. data/lib/chef/resource/windows_feature_powershell.rb +1 -2
  38. data/lib/chef/resource/windows_task.rb +25 -10
  39. data/lib/chef/resource.rb +2 -2
  40. data/lib/chef/resource_reporter.rb +1 -1
  41. data/lib/chef/run_lock.rb +1 -1
  42. data/lib/chef/secret_fetcher/azure_key_vault.rb +4 -2
  43. data/lib/chef/secret_fetcher/hashi_vault.rb +37 -3
  44. data/lib/chef/util/dsc/configuration_generator.rb +1 -1
  45. data/lib/chef/version.rb +1 -1
  46. data/spec/functional/resource/archive_file_spec.rb +3 -2
  47. data/spec/functional/resource/cookbook_file_spec.rb +1 -1
  48. data/spec/functional/resource/dnf_package_spec.rb +107 -107
  49. data/spec/functional/resource/dsc_script_spec.rb +2 -2
  50. data/spec/functional/resource/template_spec.rb +1 -1
  51. data/spec/functional/resource/yum_package_spec.rb +789 -129
  52. data/spec/integration/client/client_spec.rb +1 -1
  53. data/spec/spec_helper.rb +3 -5
  54. data/spec/support/platform_helpers.rb +1 -1
  55. data/spec/support/ruby_installer.rb +1 -1
  56. data/spec/support/shared/functional/file_resource.rb +2 -2
  57. data/spec/support/shared/functional/http.rb +9 -9
  58. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +1 -1
  59. data/spec/unit/dsl/registry_helper_spec.rb +6 -6
  60. data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +1 -1
  61. data/spec/unit/lwrp_spec.rb +2 -2
  62. data/spec/unit/provider/dsc_script_spec.rb +8 -8
  63. data/spec/unit/provider/group/usermod_spec.rb +2 -2
  64. data/spec/unit/provider/ifconfig/aix_spec.rb +14 -14
  65. data/spec/unit/provider/ifconfig/debian_spec.rb +1 -1
  66. data/spec/unit/provider/ifconfig/redhat_spec.rb +1 -1
  67. data/spec/unit/provider/ifconfig_spec.rb +3 -3
  68. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +3 -3
  69. data/spec/unit/provider/service/gentoo_service_spec.rb +2 -2
  70. data/spec/unit/provider/service/upstart_service_spec.rb +3 -3
  71. data/spec/unit/provider/user/solaris_spec.rb +1 -1
  72. data/spec/unit/resource/archive_file_spec.rb +1 -2
  73. data/spec/unit/resource/conditional_spec.rb +4 -4
  74. data/spec/unit/resource_spec.rb +2 -2
  75. data/spec/unit/secret_fetcher/hashi_vault_spec.rb +46 -0
  76. metadata +6 -8
  77. data/lib/chef/provider/group/suse.rb +0 -82
  78. data/spec/unit/provider/group/suse_spec.rb +0 -90
@@ -97,7 +97,6 @@ class Chef
97
97
  data_collector_token 'TEST_TOKEN_TEST'
98
98
  end
99
99
  ```
100
-
101
100
  DOC
102
101
 
103
102
  # @todo policy_file or policy_group being set requires the other to be set so enforce that.
@@ -243,11 +242,11 @@ class Chef
243
242
  description: "Additional text to add at the bottom of the client.rb config. This can be used to run custom Ruby or to add less common config options"
244
243
 
245
244
  property :data_collector_server_url, String,
246
- description: "The data collector url (typically automate) to send node, converge and compliance data. Note: Data collection reporting to Automate should be performed directly by Chef Infra Server if possible, as this removes the need to distribute tokens to individual nodes.",
245
+ description: "The data collector URL (typically automate) to send node, converge, and compliance data. Note: If possible, use Chef Infra Server to do all data collection reporting, as this removes the need to distribute tokens to individual nodes.",
247
246
  introduced: "17.8"
248
247
 
249
248
  property :data_collector_token, String,
250
- description: "The data collector token to interact with the data collector server url (Automate). Note: Data collection reporting to Automate should be performed directly by Chef Infra Server if possible, as this removes the need to distribute tokens to individual nodes.",
249
+ description: "The data collector token to interact with the data collector server URL (Automate). Note: If possible, use Chef Infra Server to do all data collection reporting, as this removes the need to distribute tokens to individual nodes.",
251
250
  introduced: "17.8"
252
251
 
253
252
  action :create, description: "Create a client.rb config file for configuring #{ChefUtils::Dist::Infra::PRODUCT}." do
@@ -25,7 +25,7 @@ class Chef
25
25
 
26
26
  provides :chocolatey_package
27
27
 
28
- description "Use the **chocolatey_package** resource to manage packages using Chocolatey on the Microsoft Windows platform. Note: The Chocolatey package manager is not installed on Windows by default. You will need to install it prior to using this resource by adding the [Chocolatey cookbook](https://supermarket.chef.io/cookbooks/chocolatey/) to your node's run list."
28
+ description "Use the **chocolatey_package** resource to manage packages using the Chocolatey package manager on the Microsoft Windows platform. Note: The Chocolatey package manager is not installed on Windows by default. You will need to install it prior to using this resource by adding the [chocolatey cookbook](https://supermarket.chef.io/cookbooks/chocolatey/) to your node's run list. Warning: The **chocolatey_package** resource must be specified as `chocolatey_package` and cannot be shortened to `package` in a recipe."
29
29
  introduced "12.7"
30
30
  examples <<~DOC
31
31
  **Install a Chocolatey package**:
@@ -73,9 +73,9 @@ class Chef
73
73
  coerce: proc { |x| [x].flatten }
74
74
 
75
75
  # In the choco if we have the feature useEnhancedExitCodes turned on, then choco will provide enhanced exit codes(2: no results).
76
- # Choco exit codes https://chocolatey.org/docs/commandsinfo#exit-codes
76
+ # Choco exit codes https://docs.chocolatey.org/en-us/choco/commands/info#exit-codes
77
77
  property :returns, [Integer, Array],
78
- description: "The exit code(s) returned a chocolatey package that indicate success.",
78
+ description: "The exit code(s) returned by the `choco` command that indicate a successful action. See [Chocolatey Exit Codes](https://docs.chocolatey.org/en-us/choco/commands/info#exit-codes) for a complete list of exit codes used by Chocolatey.",
79
79
  default: [ 0, 2 ], desired_state: false,
80
80
  introduced: "12.18"
81
81
  end
@@ -20,6 +20,7 @@
20
20
  require_relative "../../resource"
21
21
  require_relative "../helpers/cron_validations"
22
22
  require_relative "../../provider/cron" # do not remove. we actually need this below
23
+ require "chef-utils/dist" unless defined?(ChefUtils::Dist)
23
24
 
24
25
  class Chef
25
26
  class Resource
@@ -30,7 +31,80 @@ class Chef
30
31
 
31
32
  provides :cron
32
33
 
33
- description "Use the **cron** resource to manage cron entries for time-based job scheduling. Properties for a schedule will default to * if not provided. The cron resource requires access to a crontab program, typically cron."
34
+ description "Use the **cron** resource to manage cron entries for time-based job scheduling. Properties for a schedule will default to * if not provided. The cron resource requires access to a crontab program, typically cron. Warning: The cron resource should only be used to modify an entry in a crontab file. The `cron_d` resource directly manages `cron.d` files. This resource ships in #{ChefUtils::Dist::Infra::PRODUCT} 14.4 or later and can also be found in the [cron](https://github.com/chef-cookbooks/cron) cookbook) for previous #{ChefUtils::Dist::Infra::PRODUCT} releases."
35
+
36
+ examples <<~'DOC'
37
+ **Run a program at a specified interval**
38
+
39
+ ```ruby
40
+ cron 'noop' do
41
+ hour '5'
42
+ minute '0'
43
+ command '/bin/true'
44
+ end
45
+ ```
46
+
47
+ **Run an entry if a folder exists**
48
+
49
+ ```ruby
50
+ cron 'ganglia_tomcat_thread_max' do
51
+ command "/usr/bin/gmetric
52
+ -n 'tomcat threads max'
53
+ -t uint32
54
+ -v '/usr/local/bin/tomcat-stat --thread-max'"
55
+ only_if { ::File.exist?('/home/jboss') }
56
+ end
57
+ ```
58
+
59
+ **Run every Saturday, 8:00 AM**
60
+
61
+ The following example shows a schedule that will run every hour at 8:00 each Saturday morning, and will then send an email to “admin@example.com” after each run.
62
+
63
+ ```ruby
64
+ cron 'name_of_cron_entry' do
65
+ minute '0'
66
+ hour '8'
67
+ weekday '6'
68
+ mailto 'admin@example.com'
69
+ action :create
70
+ end
71
+ ```
72
+
73
+ **Run once a week**
74
+
75
+ ```ruby
76
+ cron 'cookbooks_report' do
77
+ minute '0'
78
+ hour '0'
79
+ weekday '1'
80
+ user 'chefio'
81
+ mailto 'sysadmin@example.com'
82
+ home '/srv/supermarket/shared/system'
83
+ command %W{
84
+ cd /srv/supermarket/current &&
85
+ env RUBYLIB="/srv/supermarket/current/lib"
86
+ RAILS_ASSET_ID=`git rev-parse HEAD` RAILS_ENV="#{rails_env}"
87
+ bundle exec rake cookbooks_report
88
+ }.join(' ')
89
+ action :create
90
+ end
91
+ ```
92
+
93
+ **Run only in November**
94
+
95
+ The following example shows a schedule that will run at 8:00 PM, every weekday (Monday through Friday), but only in November:
96
+
97
+ ```ruby
98
+ cron 'name_of_cron_entry' do
99
+ minute '0'
100
+ hour '20'
101
+ day '*'
102
+ month '11'
103
+ weekday '1-5'
104
+ action :create
105
+ end
106
+ ```
107
+ DOC
34
108
 
35
109
  state_attrs :minute, :hour, :day, :month, :weekday, :user
36
110
 
@@ -18,6 +18,7 @@
18
18
  require_relative "../../resource"
19
19
  require_relative "../helpers/cron_validations"
20
20
  require "shellwords" unless defined?(Shellwords)
21
+ require "chef-utils/dist" unless defined?(ChefUtils::Dist)
21
22
 
22
23
  class Chef
23
24
  class Resource
@@ -29,7 +30,7 @@ class Chef
29
30
  provides :cron_d
30
31
 
31
32
  introduced "14.4"
32
- description "Use the **cron_d** resource to manage cron job files in the `/etc/cron.d` directory. This is similar to the 'cron' resource, but it does not use the monolithic /etc/crontab file."
33
+ description "Use the **cron_d** resource to manage cron job files in the `/etc/cron.d` directory. Warning: #{ChefUtils::Dist::Infra::PRODUCT} also ships with the **cron** resource for managing the monolithic `/etc/crontab` file on platforms that lack cron.d support. See the [cron resource](/resources/cron/) for information on using that resource."
33
34
  examples <<~DOC
34
35
  **Run a program on the fifth hour of the day**
35
36
 
@@ -284,7 +284,7 @@ class Chef
284
284
  if new_resource.peer
285
285
  peer_list = []
286
286
  new_resource.peer.each do |p|
287
- peer_list << if p !~ /.*:.*/
287
+ peer_list << if !/.*:.*/.match?(p)
288
288
  p + ":9632"
289
289
  else
290
290
  p
@@ -15,7 +15,7 @@
15
15
  # limitations under the License.
16
16
  #
17
17
 
18
- require "win32/service" if RUBY_PLATFORM =~ /mswin|mingw32|windows/
18
+ require "win32/service" if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
19
19
  require_relative "habitat_sup"
20
20
 
21
21
  class Chef
@@ -41,10 +41,6 @@ class Chef
41
41
  property :url, String,
42
42
  description: "The URL of the tap."
43
43
 
44
- property :full, [TrueClass, FalseClass],
45
- description: "Perform a full clone on the tap, as opposed to a shallow clone.",
46
- default: false
47
-
48
44
  property :homebrew_path, String,
49
45
  description: "The path to the Homebrew binary.",
50
46
  default: "/usr/local/bin/brew"
@@ -57,7 +53,7 @@ class Chef
57
53
  action :tap, description: "Add a Homebrew tap." do
58
54
  unless tapped?(new_resource.tap_name)
59
55
  converge_by("tap #{new_resource.tap_name}") do
60
- shell_out!("#{new_resource.homebrew_path} tap #{new_resource.full ? "--full" : ""} #{new_resource.tap_name} #{new_resource.url || ""}",
56
+ shell_out!("#{new_resource.homebrew_path} tap #{new_resource.tap_name} #{new_resource.url || ""}",
61
57
  user: new_resource.owner,
62
58
  env: { "HOME" => ::Dir.home(new_resource.owner), "USER" => new_resource.owner },
63
59
  cwd: ::Dir.home(new_resource.owner))
@@ -135,7 +135,7 @@ class Chef
135
135
 
136
136
  action_class do
137
137
  def load_waiver_file_to_hash(file_name)
138
- if file_name =~ %r{(/|C:\\).*(.yaml|.yml)}i
138
+ if %r{(/|C:\\).*(.yaml|.yml)}i.match?(file_name)
139
139
  if ::File.exist?(file_name)
140
140
  hash = ::YAML.load_file(file_name)
141
141
  if hash == false || hash.nil? || hash == ""
@@ -84,7 +84,7 @@ class Chef
84
84
  end
85
85
 
86
86
  # Check to make sure that our array only has hashes
87
- unless array.all? { |obj| obj.is_a?(Hash) }
87
+ unless array.all?(Hash)
88
88
  error_msg = "start_calendar_interval must be a single hash or an array of hashes!"
89
89
  raise Chef::Exceptions::ValidationFailed, error_msg
90
90
  end
@@ -98,7 +98,7 @@ class Chef
98
98
  raise Chef::Exceptions::ValidationFailed, error_msg
99
99
  end
100
100
 
101
- unless entry.values.all? { |val| val.is_a?(Integer) }
101
+ unless entry.values.all?(Integer)
102
102
  failed_values = entry.values.reject { |val| val.is_a?(Integer) }.join(", ")
103
103
  error_msg = "Invalid value(s) (#{failed_values}) for start_calendar_interval item. Values must be integers!"
104
104
  raise Chef::Exceptions::ValidationFailed, error_msg
@@ -54,7 +54,7 @@ class Chef
54
54
  resource_class.run_context = run_context
55
55
  resource_class.class_from_file(filename)
56
56
 
57
- if !resource_class.unified_mode && !deprecated_class(resource_class)
57
+ if !resource_class.unified_mode && !deprecated_class(resource_class) && cookbook_name.to_s != "chef_client_updater"
58
58
  Chef.deprecated :unified_mode, "The #{resource_class.resource_name} resource in the #{cookbook_name} cookbook should declare `unified_mode true`", filename
59
59
  end
60
60
 
@@ -25,10 +25,10 @@ class Chef
25
25
 
26
26
  provides :powershell_package_source
27
27
 
28
- description "Use the **powershell_package_source** resource to register a PowerShell package source and a Powershell package provider. There are 2 distinct objects we care about here. The first is a Package Source like a PowerShell Repository or a Nuget Source. The second object is a provider that PowerShell uses to get to that source with, like PowerShellGet, Nuget, Chocolatey, etc. "
28
+ description "Use the **powershell_package_source** resource to register a PowerShell package source and a Powershell package provider. There are two distinct objects we care about here. The first is a package source like a PowerShell repository or a NuGet Source. The second object is a provider that PowerShell uses to get to that source with, like PowerShellGet, NuGet, Chocolatey, etc."
29
29
  introduced "14.3"
30
30
  examples <<~DOC
31
- **Add a new PSRepository that is not trusted and which requires credentials to connect to**:
31
+ **Add a new PowerShell repository that is not trusted and which requires credentials to connect to**:
32
32
 
33
33
  ```ruby
34
34
  powershell_package_source 'PowerShellModules' do
@@ -43,7 +43,7 @@ class Chef
43
43
  end
44
44
  ```
45
45
 
46
- **Add a new Package Source that uses Chocolatey as the Package Provider**:
46
+ **Add a new package source that uses Chocolatey as the package provider**:
47
47
 
48
48
  ```ruby
49
49
  powershell_package_source 'PowerShellModules' do
@@ -56,7 +56,7 @@ class Chef
56
56
  end
57
57
  ```
58
58
 
59
- **Add a new PowerShell Script source that is trusted**:
59
+ **Add a new PowerShell script source that is trusted**:
60
60
 
61
61
  ```ruby
62
62
  powershell_package_source 'MyDodgyScript' do
@@ -68,7 +68,7 @@ class Chef
68
68
  end
69
69
  ```
70
70
 
71
- **Update my existing PSRepository to make it Trusted after all**:
71
+ **Update an existing PowerShell repository to make it trusted**:
72
72
 
73
73
  ```ruby
74
74
  powershell_package_source 'MyPSModule' do
@@ -137,7 +137,7 @@ class Chef
137
137
  description: "The location where scripts will be published to for this source. Only valid if the provider is `PowerShellGet`."
138
138
 
139
139
  property :trusted, [TrueClass, FalseClass],
140
- description: "Whether or not to trust packages from this source. Used when creating a NON-PSRepository Package Source",
140
+ description: "Whether or not to trust packages from this source. Used when creating a non-PowerShell repository package source.",
141
141
  default: false
142
142
 
143
143
  property :user, String,
@@ -151,7 +151,7 @@ class Chef
151
151
  property :provider_name, String,
152
152
  equal_to: %w{ Programs msi NuGet msu PowerShellGet psl chocolatey winget },
153
153
  validation_message: "The following providers are supported: 'Programs', 'msi', 'NuGet', 'msu', 'PowerShellGet', 'psl', 'chocolatey' or 'winget'",
154
- description: "The package management provider for the package source. The default is PowerShellGet and this option need only be set otherwise in specific use cases.",
154
+ description: "The package management provider for the package source. The default is `PowerShellGet`. Only change this option in specific use cases.",
155
155
  default: "NuGet"
156
156
 
157
157
  load_current_value do
@@ -202,7 +202,7 @@ class Chef
202
202
  end
203
203
  end
204
204
 
205
- action :set, description: "Updates an existing PSRepository or Package Source" do
205
+ action :set, description: "Updates an existing PowerShell repository or package source." do
206
206
  package_details = get_package_source_details
207
207
  output = package_details.result
208
208
  if output == "PSRepository"
@@ -138,7 +138,7 @@ class Chef
138
138
  nil
139
139
  elsif args[0].is_a?(Chef::DelayedEvaluator) && args.count == 1
140
140
  args[0]
141
- elsif args.any? { |a| a.is_a?(Chef::DelayedEvaluator) } && args.count > 1
141
+ elsif args.any?(Chef::DelayedEvaluator) && args.count > 1
142
142
  raise Exceptions::InvalidRemoteFileURI, "Only 1 source argument allowed when using a lazy evaluator"
143
143
  else
144
144
  Array(args).flatten
@@ -80,7 +80,7 @@ class Chef
80
80
  introduced: "15.9"
81
81
 
82
82
  property :server_url, String,
83
- description: "The hostname of the subscription service to use. The default is for Customer Portal Subscription Management, subscription.rhn.redhat.com. If this option is not used, the system is registered with Customer Portal Subscription Management.",
83
+ description: "The hostname of the subscription service to use. The default is Customer Portal Subscription Management, subscription.rhn.redhat.com. If you do not use this option, the system registers with Customer Portal Subscription Management.",
84
84
  introduced: "17.8"
85
85
 
86
86
  property :base_url, String,
@@ -88,12 +88,12 @@ class Chef
88
88
  introduced: "17.8"
89
89
 
90
90
  property :service_level, String,
91
- description: "Sets the service level to use for subscriptions on the registering machine. This is only used with the auto_attach option.",
91
+ description: "Sets the service level to use for subscriptions on the registering machine. This is only used with the `auto_attach` option.",
92
92
  introduced: "17.8"
93
93
 
94
94
  property :release,
95
95
  [Float, String],
96
- description: "Sets the operating system minor release to use for subscriptions for the system. Products and updates are limited to the specified minor release version. This is used only used with the auto_attach option. For example, `release '6.4'` will append `--release=6.4` to the register command.",
96
+ description: "Sets the operating system minor release to use for subscriptions for the system. Products and updates are limited to the specified minor release version. This is used only used with the `auto_attach` option. For example, `release '6.4'` will append `--release=6.4` to the register command.",
97
97
  introduced: "17.8"
98
98
 
99
99
  action :register, description: "Register the node with RHSM." do
@@ -216,8 +216,7 @@ class Chef
216
216
  def parsed_feature_list
217
217
  # Grab raw feature information from WindowsFeature
218
218
  raw_list_of_features = powershell_exec!("Get-WindowsFeature | Select-Object -Property Name,InstallState", timeout: new_resource.timeout).result
219
-
220
- Chef::JSONCompat.from_json(raw_list_of_features)
219
+ raw_list_of_features || []
221
220
  end
222
221
 
223
222
  # add the features values to the appropriate array
@@ -149,7 +149,6 @@ class Chef
149
149
  DOC
150
150
 
151
151
  allowed_actions :create, :delete, :run, :end, :enable, :disable, :change
152
- default_action :create
153
152
 
154
153
  property :task_name, String, regex: [%r{\A[^/\:\*\?\<\>\|]+\z}],
155
154
  description: "An optional property to set the task name if it differs from the resource block's name. Example: `Task Name` or `/Task Name`",
@@ -182,10 +181,19 @@ class Chef
182
181
  default: false
183
182
 
184
183
  property :frequency_modifier, [Integer, String],
185
- default: 1
184
+ default: 1,
185
+ description: <<~DOCS
186
+ * For frequency `:minute` valid values are 1 to 1439
187
+ * For frequency `:hourly` valid values are 1 to 23
188
+ * For frequency `:daily` valid values are 1 to 365
189
+ * For frequency `:weekly` valid values are 1 to 52
190
+ * For frequency `:monthly` valid values are `('FIRST', 'SECOND', 'THIRD', 'FOURTH', 'LAST')` OR `1-12`.
191
+ * e.g. If user want to run the task on `second week of the month` use `frequency_modifier` value as `SECOND`. Multiple values for weeks of the month should be comma separated e.g. `"FIRST, THIRD, LAST"`.
192
+ * To run task every (n) months use values 1 to 12.
193
+ DOCS
186
194
 
187
195
  property :frequency, Symbol, equal_to: %i{minute hourly daily weekly monthly once on_logon onstart on_idle none},
188
- description: "The frequency with which to run the task."
196
+ description: "The frequency with which to run the task. Note: This property is required in Chef Infra Client 14.1 or later. Note: The `:once` value requires the `start_time` property to be set."
189
197
 
190
198
  property :start_day, String,
191
199
  description: "Specifies the first date on which the task runs in **MM/DD/YYYY** format.",
@@ -195,7 +203,14 @@ class Chef
195
203
  description: "Specifies the start time to run the task, in **HH:mm** format."
196
204
 
197
205
  property :day, [String, Integer],
198
- description: "The day(s) on which the task runs."
206
+ description: <<~DOCS
207
+ The day(s) on which the task runs.
208
+ * Use this property when setting `frequency` to `:monthly` or `:weekly`.
209
+ * Valid values with frequency `:weekly` are `MON`-`SUN` or `*`.
210
+ * Valid values with frequency `:monthly` are `1-31`, `MON`-`SUN`, and `LASTDAY`.
211
+ * Use `MON`-`SUN` or `LASTDAY` if you are setting `frequency_modifier` as "FIRST, SECOND, THIRD etc." else use 1-31.
212
+ * Multiple days should be comma separated. e.g `1, 2, 3` or `MON, WED, FRI`.
213
+ DOCS
199
214
 
200
215
  property :months, String,
201
216
  description: "The Months of the year on which the task runs, such as: `JAN, FEB` or `*`. Multiple months should be comma delimited. e.g. `Jan, Feb, Mar, Dec`."
@@ -961,7 +976,7 @@ class Chef
961
976
  end
962
977
  end
963
978
 
964
- action :create do
979
+ action :create, description: "Creates a scheduled task, or updates an existing task if any property has changed." do
965
980
  set_command_and_arguments if new_resource.command
966
981
 
967
982
  if current_resource.exists
@@ -998,7 +1013,7 @@ class Chef
998
1013
  end
999
1014
  end
1000
1015
 
1001
- action :run do
1016
+ action :run, description: "Runs a scheduled task." do
1002
1017
  if current_resource.exists
1003
1018
  logger.trace "#{new_resource} task exists"
1004
1019
  if current_resource.task.status == "running"
@@ -1013,7 +1028,7 @@ class Chef
1013
1028
  end
1014
1029
  end
1015
1030
 
1016
- action :delete do
1031
+ action :delete, description: "Deletes a scheduled task." do
1017
1032
  if current_resource.exists
1018
1033
  logger.trace "#{new_resource} task exists"
1019
1034
  converge_by("delete scheduled task #{new_resource}") do
@@ -1026,7 +1041,7 @@ class Chef
1026
1041
  end
1027
1042
  end
1028
1043
 
1029
- action :end do
1044
+ action :end, description: "Ends a scheduled task." do
1030
1045
  if current_resource.exists
1031
1046
  logger.trace "#{new_resource} task exists"
1032
1047
  if current_resource.task.status != "running"
@@ -1041,7 +1056,7 @@ class Chef
1041
1056
  end
1042
1057
  end
1043
1058
 
1044
- action :enable do
1059
+ action :enable, description: "Enables a scheduled task." do
1045
1060
  if current_resource.exists
1046
1061
  logger.trace "#{new_resource} task exists"
1047
1062
  if current_resource.task.status == "not scheduled"
@@ -1058,7 +1073,7 @@ class Chef
1058
1073
  end
1059
1074
  end
1060
1075
 
1061
- action :disable do
1076
+ action :disable, description: "Disables a scheduled task." do
1062
1077
  if current_resource.exists
1063
1078
  logger.info "#{new_resource} task exists"
1064
1079
  if %w{ready running}.include?(current_resource.task.status)
data/lib/chef/resource.rb CHANGED
@@ -311,7 +311,7 @@ class Chef
311
311
  # file '/foo.txt' do
312
312
  # content 'hi'
313
313
  # action :nothing
314
- # subscribes :create, '/bar.txt'
314
+ # subscribes :create, bar
315
315
  # end
316
316
  # @example Multiple resources by string
317
317
  # file '/foo.txt' do
@@ -1096,7 +1096,7 @@ class Chef
1096
1096
  rescue NameError => e
1097
1097
  # This can happen when attempting to load a provider in a platform-specific
1098
1098
  # environment where we have not required the necessary files yet
1099
- raise unless e.message =~ /uninitialized constant/
1099
+ raise unless /uninitialized constant/.match?(e.message)
1100
1100
  end
1101
1101
 
1102
1102
  # Define a method to load up this resource's properties with the current
@@ -34,7 +34,7 @@ class Chef
34
34
  as_hash["after"] = new_resource.state_for_resource_reporter
35
35
  as_hash["before"] = current_resource ? current_resource.state_for_resource_reporter : {}
36
36
  as_hash["duration"] = ( action_record.elapsed_time * 1000 ).to_i.to_s
37
- as_hash["delta"] = new_resource.diff if new_resource.respond_to?("diff")
37
+ as_hash["delta"] = new_resource.diff if new_resource.respond_to?(:diff)
38
38
  as_hash["delta"] = "" if as_hash["delta"].nil?
39
39
 
40
40
  # TODO: rename as "action"
data/lib/chef/run_lock.rb CHANGED
@@ -144,7 +144,7 @@ class Chef
144
144
  # If we support FD_CLOEXEC, then use it.
145
145
  # NB: ruby-2.0.0-p195 sets FD_CLOEXEC by default, but not
146
146
  # ruby-1.8.7/1.9.3
147
- if Fcntl.const_defined?("F_SETFD") && Fcntl.const_defined?("FD_CLOEXEC")
147
+ if Fcntl.const_defined?(:F_SETFD) && Fcntl.const_defined?(:FD_CLOEXEC)
148
148
  runlock.fcntl(Fcntl::F_SETFD, runlock.fcntl(Fcntl::F_GETFD, 0) | Fcntl::FD_CLOEXEC)
149
149
  end
150
150
  # Flock will return 0 if it can acquire the lock otherwise it
@@ -1,5 +1,7 @@
1
1
  require_relative "base"
2
2
  require_relative "../exceptions"
3
+ require "json" unless defined?(JSON)
4
+ require "net/http" unless defined?(Net::HTTP)
3
5
  require "uri" unless defined?(URI)
4
6
 
5
7
  class Chef
@@ -57,7 +59,7 @@ class Chef
57
59
  end
58
60
 
59
61
  def validate!
60
- raise Chef::Exceptions::Secret::ConfigurationInvalid, "You may only specify one (these are mutually exclusive): :object_id, :client_id, or :mi_res_id" if [object_id, client_id, mi_res_id].select { |x| !x.nil? }.length > 1
62
+ raise Chef::Exceptions::Secret::ConfigurationInvalid, "You may only specify one (these are mutually exclusive): :object_id, :client_id, or :mi_res_id" if [object_id, client_id, mi_res_id].count { |x| !x.nil? } > 1
61
63
  end
62
64
 
63
65
  private
@@ -121,7 +123,7 @@ class Chef
121
123
  body["access_token"]
122
124
  when Net::HTTPBadRequest
123
125
  body = JSON.parse(response.body)
124
- raise Chef::Exceptions::Secret::Azure::IdentityNotFound if body["error_description"] =~ /identity not found/i
126
+ raise Chef::Exceptions::Secret::Azure::IdentityNotFound if /identity not found/i.match?(body["error_description"])
125
127
  else
126
128
  body = JSON.parse(response.body)
127
129
  body["access_token"]
@@ -31,6 +31,10 @@ class Chef
31
31
  # :auth_method - one of :iam_role, :token. default: :iam_role
32
32
  # :vault_addr - the address of a running Vault instance, eg https://vault.example.com:8200
33
33
  #
34
+ # For `:approle`: one of `:approle_name` or `:approle_id`
35
+ # `:approle_name`: The name of the approle to use for authentication. When specified, associated `:approle_id` will be found via query to Vault instance.
36
+ # `:approle_id`: The ID of the approle to use for authentication, requires `:approle_secret_id`
37
+ # `:approle_secret_id`: The Vault `secret_id` associated with the provided `:approle_name` or `:approle_id`. When specified, prevents need to create `:secret_id` with `:approle_name`.
34
38
  # For `:token` auth: `:token` - a Vault token valid for authentication.
35
39
  #
36
40
  # For `:iam_role`: `:role_name` - the name of the role in Vault that was created
@@ -47,14 +51,25 @@ class Chef
47
51
  #
48
52
  # @example
49
53
  #
50
- # fetcher = SecretFetcher.for_service(:hashi_vault, { role_name: "testing-role", vault_addr: https://localhost:8200}, run_context )
54
+ # fetcher = SecretFetcher.for_service(:hashi_vault, { auth_method: :iam_role, role_name: "testing-role", vault_addr: https://localhost:8200}, run_context )
51
55
  # fetcher.fetch("secretkey1")
52
56
  #
53
57
  # @example
54
58
  #
55
- # fetcher = SecretFetcher.for_service(:hashi_vault, { auth_method: :token, token: "s.1234abcdef", vault_addr: https://localhost:8200}, run_context )
59
+ # fetcher = SecretFetcher.for_service(:hashi_vault, { auth_method: :token, token: "s.1234abcdef", vault_addr: https://localhost:8200}, approle: 'approle_name', run_context )
56
60
  # fetcher.fetch("secretkey1")
57
- SUPPORTED_AUTH_TYPES = %i{iam_role token}.freeze
61
+ #
62
+ # @example
63
+ #
64
+ # fetcher = SecretFetcher.for_service(:hashi_vault, { auth_method: :approle, approle_id: "11111111-abcd-1111-abcd-111111111111", approle_secret_id: "22222222-abcd-2222-abcd-222222222222", vault_addr: https://localhost:8200}, run_context )
65
+ # fetcher.fetch("secretkey1")
66
+ #
67
+ # @example
68
+ #
69
+ # fetcher = SecretFetcher.for_service(:hashi_vault, { auth_method: :approle, approle_name: "testing-role", token: "s.1234abcdef", vault_addr: https://localhost:8200}, run_context )
70
+ # fetcher.fetch("secretkey1")
71
+ #
72
+ SUPPORTED_AUTH_TYPES = %i{approle iam_role token}.freeze
58
73
  class HashiVault < Base
59
74
 
60
75
  # Validate and authenticate the current session using the configured auth strategy and parameters
@@ -67,6 +82,25 @@ class Chef
67
82
  Vault.namespace = config[:namespace] unless config[:namespace].nil?
68
83
 
69
84
  case config[:auth_method]
85
+ when :approle
86
+ unless config[:approle_name] || config[:approle_id]
87
+ raise Chef::Exceptions::Secret::ConfigurationInvalid.new("You must provide the :approle_name or :approle_id in the configuration with :auth_method set to :approle")
88
+ end
89
+
90
+ # When :approle_id and :approle_secret_id are both specified, all pieces are present which are needed to authenticate using an approle.
91
+ # If either is missing, we need to authenticate to Vault to get the missing pieces with the :approle_name and optionally :token.
92
+ unless config[:approle_id] && config[:approle_secret_id]
93
+ if config[:approle_name].nil?
94
+ raise Chef::Exceptions::Secret::ConfigurationInvalid.new("You must provide the :approle_name in the configuration when :approle_id and :approle_secret_id are not both present with :auth_method set to :approle")
95
+ end
96
+
97
+ Vault.token = config[:token] unless config[:token].nil?
98
+ end
99
+
100
+ approle_id = config[:approle_id] || Vault.approle.role_id(config[:approle_name])
101
+ approle_secret_id = config[:approle_secret_id] || Vault.approle.create_secret_id(config[:approle_name]).data[:secret_id]
102
+
103
+ Vault.auth.approle(approle_id, approle_secret_id)
70
104
  when :token
71
105
  if config[:token].nil?
72
106
  raise Chef::Exceptions::Secret::ConfigurationInvalid.new("You must provide the token in the configuration as :token")
@@ -175,7 +175,7 @@ class Chef::Util::DSC
175
175
  end
176
176
 
177
177
  def get_configuration_document(document_path)
178
- ::File.open(document_path, "rb", &:read)
178
+ ::File.binread(document_path)
179
179
  end
180
180
  end
181
181
  end
data/lib/chef/version.rb CHANGED
@@ -23,7 +23,7 @@ require_relative "version_string"
23
23
 
24
24
  class Chef
25
25
  CHEF_ROOT = File.expand_path("..", __dir__)
26
- VERSION = Chef::VersionString.new("17.8.25")
26
+ VERSION = Chef::VersionString.new("17.9.46")
27
27
  end
28
28
 
29
29
  #
@@ -18,8 +18,9 @@
18
18
  require "spec_helper"
19
19
  require "tmpdir"
20
20
 
21
- # Exclude this test on platforms where ffi-libarchive loading is broken
22
- describe Chef::Resource::ArchiveFile, :libarchive_loading_broken do
21
+ # AIX is broken, see https://github.com/chef/omnibus-software/issues/1566
22
+ # Windows tests are disbled since we'd need libarchive on windows testers in buildkite for PRs
23
+ describe Chef::Resource::ArchiveFile, :not_supported_on_aix, :not_supported_on_windows do
23
24
  include RecipeDSLHelper
24
25
 
25
26
  let(:tmp_path) { Dir.mktmpdir }
@@ -25,7 +25,7 @@ describe Chef::Resource::CookbookFile do
25
25
  let(:source) { "java.response" }
26
26
  let(:cookbook_name) { "java" }
27
27
  let(:expected_content) do
28
- content = File.open(File.join(CHEF_SPEC_DATA, "cookbooks", "java", "files", "default", "java.response"), "rb", &:read)
28
+ content = File.binread(File.join(CHEF_SPEC_DATA, "cookbooks", "java", "files", "default", "java.response"))
29
29
  content.force_encoding(Encoding::BINARY) if content.respond_to?(:force_encoding)
30
30
  content
31
31
  end