Convert minutes to seconds for consistent interface

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
Clinton Wolfe 2021-03-17 13:41:52 -04:00
parent 9cc9090225
commit 6d7f5a240b
3 changed files with 9 additions and 16 deletions

View file

@ -166,9 +166,9 @@ module Inspec
desc: "After normal execution order, results are sorted by control ID, or by file (default), or randomly. None uses legacy unsorted mode."
option :filter_empty_profiles, type: :boolean, default: false,
desc: "Filter empty profiles (profiles without controls) from the report."
option :command_timeout, type: :numeric, default: 60,
desc: "Maximum minutes to allow commands to run during execution. Default 60.",
long_desc: "Maximum minutes to allow commands to run during execution. Default 60. A timed out command is considered an error."
option :command_timeout, type: :numeric, default: 3600,
desc: "Maximum seconds to allow commands to run during execution. Default 3600.",
long_desc: "Maximum seconds to allow commands to run during execution. Default 3600. A timed out command is considered an error."
end
def self.help(*args)

View file

@ -321,9 +321,9 @@ class Inspec::InspecCLI < Inspec::BaseCLI
desc: "A space-delimited list of local folders containing profiles whose libraries and resources will be loaded into the new shell"
option :distinct_exit, type: :boolean, default: true,
desc: "Exit with code 100 if any tests fail, and 101 if any are skipped but none failed (default). If disabled, exit 0 on skips and 1 for failures."
option :command_timeout, type: :numeric, default: 60,
desc: "Maximum minutes to allow a command to run. Default 60.",
long_desc: "Maximum minutes to allow commands to run. Default 60. A timed out command is considered an error."
option :command_timeout, type: :numeric, default: 3600,
desc: "Maximum seconds to allow a command to run. Default 3600.",
long_desc: "Maximum seconds to allow commands to run. Default 3600. A timed out command is considered an error."
option :inspect, type: :boolean, default: false, desc: "Use verbose/debugging output for resources."
def shell_func
o = config

View file

@ -32,14 +32,7 @@ module Inspec::Resources
@command = cmd
@timeout = options[:timeout]&.to_i || Inspec::Config.cached.final_options['command_timeout']&.to_i
if @timeout
# train uses seconds but inspec advertises minutes
@timeout = @timeout * 60
else
warn "InSpec config is missing value for command_timeout. Defaulting to 60m"
@timeout = 3600
end
@timeout = options[:timeout]&.to_i || Inspec::Config.cached.final_options['command_timeout']&.to_i || 3600
if options[:redact_regex]
unless options[:redact_regex].is_a?(Regexp)
@ -53,11 +46,11 @@ module Inspec::Resources
end
def result
@result ||= begin
@result ||= begin
inspec.backend.run_command(@command, timeout: @timeout)
rescue Train::CommandTimeoutReached
raise Inspec::Exceptions::ResourceFailed,
"Command `#{@command}` timed out after #{@timeout / 60} minute(s)"
"Command `#{@command}` timed out after #{@timeout} seconds"
end
end