Class: Inspec::Resources::Cron
Instance Attribute Summary
Attributes inherited from Crontab
#params
Instance Method Summary
collapse
Methods inherited from Crontab
#crontab_cmd, #parse_crontab_line, #read_crontab
#parse_comment_line
Constructor Details
#initialize(opts = nil) ⇒ Cron
Returns a new instance of Cron.
18
19
20
21
|
# File 'lib/inspec/resources/cron.rb', line 18
def initialize(opts = nil)
super
@params = read_cron_contents
end
|
Instance Method Details
#has_entry?(rule) ⇒ Boolean
37
38
39
|
# File 'lib/inspec/resources/cron.rb', line 37
def has_entry?(rule)
@params.include?(rule)
end
|
#read_cron_contents ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/inspec/resources/cron.rb', line 23
def read_cron_contents
result = inspec.command(crontab_cmd)
if result.exit_status == 0
result.stdout.lines.map { |l| (l, comment_char: "#", standalone_comments: false)[0].strip }
else
error = result.stdout + "\n" + result.stderr
raise Inspec::Exceptions::ResourceFailed, "Error while executing #{crontab_cmd} command: #{error}"
end
end
|
#resource_id ⇒ Object
41
42
43
44
|
# File 'lib/inspec/resources/cron.rb', line 41
def resource_id
user = @user || "current user"
"cron #{user}"
end
|
#table ⇒ Object
33
34
35
|
# File 'lib/inspec/resources/cron.rb', line 33
def table
@params.reject(&:empty?).join("\n")
end
|
#to_s ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/inspec/resources/cron.rb', line 46
def to_s
if is_user_crontab?
"cron for user #{@user}"
else
"cron for current user"
end
end
|