module InspecPlugins::FlexReporter::ErbHelpers
Public Instance Methods
Return if all results of a control have passed/skipped/waived.
@param [Hash] control Data of a control run @return [Boolean] If all passed checks
# File lib/inspec-reporter-flex/mixin/erb_helpers.rb, line 55 def control_passed?(control) control[:results].any? { |result| result[:status] == "failed" } end
Map InSpec severity (0..1) to CVSS scale (none-low-medium-high-critical)
@param [Float] inspec_severity Severity from the profile @return [String] One of the scale values @see www.first.org/cvss/specification-document#Qualitative-Severity-Rating-Scale
# File lib/inspec-reporter-flex/mixin/erb_helpers.rb, line 77 def impact_to_severity(inspec_severity) case inspec_severity when 0.0...0.1 "none" when 0.1...0.4 "low" when 0.4...0.7 "medium" when 0.7...0.9 "high" when 0.9..1.0 "critical" else "unknown" end end
Allow access to all InSpec resources from the report.
@return [Inspec::Backend] The InSpec backend
# File lib/inspec-reporter-flex/mixin/erb_helpers.rb, line 31 def inspec_resource runner.backend end
Return InSpec OS resource results.
@return [Class] Look into documentation for properties (.arch/.family/.name/…) @see github.com/inspec/inspec/blob/master/lib/inspec/resources/os.rb
# File lib/inspec-reporter-flex/mixin/erb_helpers.rb, line 39 def os runner.backend.os end
Execute a remote command.
@param [String] cmd Command to execute @return [Train::Extras::CommandResult] Command result (.stdout/.stderr/.exit_status)
# File lib/inspec-reporter-flex/mixin/erb_helpers.rb, line 16 def remote_command(cmd) runner.backend.backend.run_command(cmd) end
Retrieve remote file contents.
@param [String] remote_file Path to the remote file @return [String] Contents of the file
# File lib/inspec-reporter-flex/mixin/erb_helpers.rb, line 24 def remote_file_content(remote_file) runner.backend.backend.file(remote_file).content end
Return approximate time of the scan
@return [DateTime] Timestamp of the first scan in the profile
# File lib/inspec-reporter-flex/mixin/erb_helpers.rb, line 6 def scan_time scan_time = report[:profiles].detect { |p| p[:controls].detect { |c| c[:results].detect { |r| !r.empty? } } }.dig(:controls, 0, :results, 0, :start_time) DateTime.strptime(scan_time) end
Map InSpec status to cleartext
@param [String] inspec_status One of the valid InSpec result status. @return [Strint] “ok”/“not ok” depending on status
# File lib/inspec-reporter-flex/mixin/erb_helpers.rb, line 63 def status_to_pass(inspec_status) case inspec_status when "passed", "skipped", "waived" "ok" else "not ok" end end
Return InSpec SysInfo resource results.
@return [Class] Look into documentation for properteis (.domain/.fqdn/.hostname/.ip_address/.model/…) @see github.com/inspec/inspec/blob/master/lib/inspec/resources/sys_info.rb
# File lib/inspec-reporter-flex/mixin/erb_helpers.rb, line 47 def sys_info runner.backend.sys_info end