diff options
author | Tim Smith <tsmith@chef.io> | 2020-01-16 16:45:31 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-16 16:45:31 -0800 |
commit | ba622694f7560b6db5fea85acdcf2bf7c67a39d5 (patch) | |
tree | 3b9bdb134510c6566df8729eb8f295164867587c /lib/chef/resource | |
parent | d6eaffdda28698d66a22082ddbe97d2b62d54b53 (diff) | |
parent | d14964ac121b7b06a78719538d1fadd9c1d7d1b7 (diff) | |
download | chef-ba622694f7560b6db5fea85acdcf2bf7c67a39d5.tar.gz |
Merge pull request #9153 from MsysTechnologiesllc/Nimesh/MSYS-1178_cron_resource_add_timeout
Add time_out property in cron resource
Diffstat (limited to 'lib/chef/resource')
-rw-r--r-- | lib/chef/resource/cron.rb | 28 | ||||
-rw-r--r-- | lib/chef/resource/cron_d.rb | 28 |
2 files changed, 56 insertions, 0 deletions
diff --git a/lib/chef/resource/cron.rb b/lib/chef/resource/cron.rb index dbc6a998cc..cb3f7f4dcd 100644 --- a/lib/chef/resource/cron.rb +++ b/lib/chef/resource/cron.rb @@ -162,6 +162,34 @@ class Chef description: "A Hash of environment variables in the form of ({'ENV_VARIABLE' => 'VALUE'}).", default: lazy { {} } + TIMEOUT_OPTS = %w{duration preserve-status foreground kill-after signal}.freeze + TIMEOUT_REGEX = /\A\S+/.freeze + + property :time_out, Hash, + description: "A Hash of timeouts in the form of ({'OPTION' => 'VALUE'}). + Accepted valid options are: + preserve-status (BOOL, default: 'false'), + foreground (BOOL, default: 'false'), + kill-after (in seconds), + signal (a name like 'HUP' or a number)", + default: lazy { {} }, + coerce: proc { |h| + if h.is_a?(Hash) + invalid_keys = h.keys - TIMEOUT_OPTS + unless invalid_keys.empty? + error_msg = "Key of option time_out must be equal to one of: \"#{TIMEOUT_OPTS.join('", "')}\"! You passed \"#{invalid_keys.join(", ")}\"." + raise Chef::Exceptions::ValidationFailed, error_msg + end + unless h.values.all? { |x| x =~ TIMEOUT_REGEX } + error_msg = "Values of option time_out should be non-empty string without any leading whitespaces." + raise Chef::Exceptions::ValidationFailed, error_msg + end + h + elsif h.is_a?(Integer) || h.is_a?(String) + { "duration" => h } + end + } + private def integerize(integerish) diff --git a/lib/chef/resource/cron_d.rb b/lib/chef/resource/cron_d.rb index ca3b91a4b2..6cc2ea77b3 100644 --- a/lib/chef/resource/cron_d.rb +++ b/lib/chef/resource/cron_d.rb @@ -206,6 +206,34 @@ class Chef description: "A Hash containing additional arbitrary environment variables under which the cron job will be run in the form of ``({'ENV_VARIABLE' => 'VALUE'})``.", default: lazy { {} } + TIMEOUT_OPTS = %w{duration preserve-status foreground kill-after signal}.freeze + TIMEOUT_REGEX = /\A\S+/.freeze + + property :time_out, Hash, + description: "A Hash of timeouts in the form of ({'OPTION' => 'VALUE'}). + Accepted valid options are: + preserve-status (BOOL, default: 'false'), + foreground (BOOL, default: 'false'), + kill-after (in seconds), + signal (a name like 'HUP' or a number)", + default: lazy { {} }, + coerce: proc { |h| + if h.is_a?(Hash) + invalid_keys = h.keys - TIMEOUT_OPTS + unless invalid_keys.empty? + error_msg = "Key of option time_out must be equal to one of: \"#{TIMEOUT_OPTS.join('", "')}\"! You passed \"#{invalid_keys.join(", ")}\"." + raise Chef::Exceptions::ValidationFailed, error_msg + end + unless h.values.all? { |x| x =~ TIMEOUT_REGEX } + error_msg = "Values of option time_out should be non-empty string without any leading whitespaces." + raise Chef::Exceptions::ValidationFailed, error_msg + end + h + elsif h.is_a?(Integer) || h.is_a?(String) + { "duration" => h } + end + } + property :mode, [String, Integer], description: "The octal mode of the generated crontab file.", default: "0600" |