aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBobosila Victor <victor.bobosila@puppet.com>2021-10-04 11:06:38 +0300
committerGitHub <noreply@github.com>2021-10-04 11:06:38 +0300
commit74e9d916d182df8a6594403582a8cc9e19dd55c0 (patch)
treec3070ac7809f3cf0ea04ce83622ae438efbd8203 /lib
parent4c72fb204bfc98e5d9dd4bff210c9be8178f1258 (diff)
parentdd42efd5323314047d2c44e02f2f7e3472954697 (diff)
downloadpuppet-cron_core-74e9d916d182df8a6594403582a8cc9e19dd55c0.tar.gz
puppet-cron_core-74e9d916d182df8a6594403582a8cc9e19dd55c0.tar.bz2
Merge pull request #44 from joshcooper/bump_json
(maint) Bump templates to 2.2.0
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/provider/cron/crontab.rb3
-rw-r--r--lib/puppet/provider/cron/filetype.rb16
-rw-r--r--lib/puppet/type/cron.rb30
3 files changed, 24 insertions, 25 deletions
diff --git a/lib/puppet/provider/cron/crontab.rb b/lib/puppet/provider/cron/crontab.rb
index 9144725..e07a669 100644
--- a/lib/puppet/provider/cron/crontab.rb
+++ b/lib/puppet/provider/cron/crontab.rb
@@ -32,7 +32,6 @@ Puppet::Type.type(:cron).provide(:crontab, parent: Puppet::Provider::ParsedFile,
match: %r{^\s*(@\w+|\S+\s+\S+\s+\S+\s+\S+\s+\S+)\s+(.+)$},
absent: '*',
block_eval: :instance do
-
def post_parse(record)
time = record.delete(:time)
match = %r{@(\S+)}.match(time)
@@ -207,7 +206,7 @@ Puppet::Type.type(:cron).provide(:crontab, parent: Puppet::Provider::ParsedFile,
envs << record[:line]
record[:skip] = true
end
- when :blank # rubocop: disable Lint/EmptyWhen
+ when :blank
# nothing
else
if name
diff --git a/lib/puppet/provider/cron/filetype.rb b/lib/puppet/provider/cron/filetype.rb
index c381afa..455ec07 100644
--- a/lib/puppet/provider/cron/filetype.rb
+++ b/lib/puppet/provider/cron/filetype.rb
@@ -12,7 +12,7 @@ class Puppet::Provider::Cron
# autoloader meaning that, without this wrapper, the crontab filetypes
# would be re-defined, causing Puppet to raise an exception.
def newfiletype(name, &block)
- return if @filetypes && @filetypes.key?(name)
+ return if @filetypes&.key?(name)
base_newfiletype(name, &block)
end
@@ -26,7 +26,7 @@ class Puppet::Provider::Cron
# implementation in the future. This way, we can refactor all three of
# our cron file types into a common crontab file type.
newfiletype(:crontab) do
- def initialize(user)
+ def initialize(user) # rubocop:disable Lint/MissingSuper
self.path = user
end
@@ -54,11 +54,11 @@ class Puppet::Provider::Cron
rescue => detail
case detail.to_s
when %r{no crontab for}
- return ''
+ ''
when %r{are not allowed to}
Puppet.debug _('The %{path} user is not authorized to use cron. Their crontab file is treated as empty in case Puppet authorizes them in the middle of the run (by, for example, modifying the cron.deny or cron.allow files).') % { path: @path }
- return ''
+ ''
else
raise FileReadError, _('Could not read crontab for %{path}: %{detail}') % { path: @path, detail: detail }, detail.backtrace
end
@@ -117,11 +117,11 @@ class Puppet::Provider::Cron
rescue => detail
case detail.to_s
when %r{can't open your crontab}
- return ''
+ ''
when %r{you are not authorized to use cron}
Puppet.debug _('The %{path} user is not authorized to use cron. Their crontab file is treated as empty in case Puppet authorizes them in the middle of the run (by, for example, modifying the cron.deny or cron.allow files).') % { path: @path }
- return ''
+ ''
else
raise FileReadError, _('Could not read crontab for %{path}: %{detail}') % { path: @path, detail: detail }, detail.backtrace
end
@@ -168,11 +168,11 @@ class Puppet::Provider::Cron
rescue => detail
case detail.to_s
when %r{open.*in.*directory}
- return ''
+ ''
when %r{not.*authorized.*cron}
Puppet.debug _('The %{path} user is not authorized to use cron. Their crontab file is treated as empty in case Puppet authorizes them in the middle of the run (by, for example, modifying the cron.deny or cron.allow files).') % { path: @path }
- return ''
+ ''
else
raise FileReadError, _('Could not read crontab for %{path}: %{detail}') % { path: @path, detail: detail }, detail.backtrace
end
diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb
index a536410..53bb6fd 100644
--- a/lib/puppet/type/cron.rb
+++ b/lib/puppet/type/cron.rb
@@ -4,19 +4,20 @@ require 'puppet/util/filetype'
Puppet::Type.newtype(:cron) do
@doc = <<-'EOT'
- Installs and manages cron jobs. Every cron resource created by Puppet
- requires a command and at least one periodic attribute (hour, minute,
- month, monthday, weekday, or special). While the name of the cron job is
- not part of the actual job, the name is stored in a comment beginning with
- `# Puppet Name: `. These comments are used to match crontab entries created
- by Puppet with cron resources.
+ @summary Installs and manages cron jobs.
+
+ Every cron resource created by Puppet requires a command and at least one
+ periodic attribute (hour, minute, month, monthday, weekday, or special). While
+ the name of the cron job is not part of the actual job, the name is stored in a
+ comment beginning with `# Puppet Name: `. These comments are used to match
+ crontab entries created by Puppet with cron resources.
If an existing crontab entry happens to match the scheduling and command of a
cron resource that has never been synced, Puppet defers to the existing
crontab entry and does not create a new entry tagged with the `# Puppet Name: `
comment.
- Example:
+ @example
cron { 'logrotate':
command => '/usr/sbin/logrotate',
@@ -25,7 +26,7 @@ Puppet::Type.newtype(:cron) do
minute => 0,
}
- Note that all periodic attributes can be specified as an array of values:
+ @example Note that all periodic attributes can be specified as an array of values:
cron { 'logrotate':
command => '/usr/sbin/logrotate',
@@ -33,8 +34,7 @@ Puppet::Type.newtype(:cron) do
hour => [2, 4],
}
- ...or using ranges or the step syntax `*/2` (although there's no guarantee
- that your `cron` daemon supports these):
+ @example ...or using ranges or the step syntax `*/2` (although there's no guarantee that your `cron` daemon supports these):
cron { 'logrotate':
command => '/usr/sbin/logrotate',
@@ -118,7 +118,7 @@ Puppet::Type.newtype(:cron) do
end
end
- def is_to_s(value = @is) # rubocop: disable Style/PredicateName
+ def is_to_s(value = @is) # rubocop: disable Naming/PredicateName
if value
if value.is_a?(Array) && (name == :command || value[0].is_a?(Symbol))
value = value[0]
@@ -155,17 +155,17 @@ Puppet::Type.newtype(:cron) do
end
# Allow step syntax
- if value.to_s =~ %r{^\*/[0-9]+$}
+ if %r{^\*/[0-9]+$}.match?(value.to_s)
return value
end
# Allow ranges
- if value.to_s =~ %r{^[0-9]+-[0-9]+$}
+ if %r{^[0-9]+-[0-9]+$}.match?(value.to_s)
return value
end
# Allow ranges with step
- if value.to_s =~ %r{^[0-9]+-[0-9]+/[0-9]+$}
+ if %r{^[0-9]+-[0-9]+/[0-9]+$}.match?(value.to_s)
return value
end
@@ -210,7 +210,7 @@ Puppet::Type.newtype(:cron) do
def retrieve
return_value = super
- return_value = return_value[0] if return_value && return_value.is_a?(Array)
+ return_value = return_value[0] if return_value&.is_a?(Array)
return_value
end