module InspecPlugins::FlexReporter::ErbHelpers

Public Instance Methods

control_passed?(control) click to toggle source

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
impact_to_severity(inspec_severity) click to toggle source

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
inspec_resource() click to toggle source

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
os() click to toggle source

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
remote_command(cmd) click to toggle source

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
remote_file_content(remote_file) click to toggle source

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
scan_time() click to toggle source

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
status_to_pass(inspec_status) click to toggle source

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
sys_info() click to toggle source

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