Module: InspecPlugins::FlexReporter::ErbHelpers

Included in:
Reporter
Defined in:
lib/inspec-reporter-flex/mixin/erb_helpers.rb

Instance Method Summary collapse

Instance Method Details

#control_passed?(control) ⇒ Boolean

Return if all results of a control have passed/skipped/waived.

Parameters:

  • control (Hash)

    Data of a control run

Returns:

  • (Boolean)

    If all passed checks



53
54
55
# File 'lib/inspec-reporter-flex/mixin/erb_helpers.rb', line 53

def control_passed?(control)
  control[:results].any? { |result| result[:status] == "failed" }
end

#impact_to_severity(inspec_severity) ⇒ String

Map InSpec severity (0..1) to CVSS scale (none-low-medium-high-critical)

Parameters:

  • inspec_severity (Float)

    Severity from the profile

Returns:

  • (String)

    One of the scale values

See Also:



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/inspec-reporter-flex/mixin/erb_helpers.rb', line 75

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_resourceInspec::Backend

Allow access to all InSpec resources from the report.

Returns:

  • (Inspec::Backend)

    The InSpec backend



29
30
31
# File 'lib/inspec-reporter-flex/mixin/erb_helpers.rb', line 29

def inspec_resource
  runner.backend
end

#osClass

Return InSpec OS resource results.

Returns:

  • (Class)

    Look into documentation for properties (.arch/.family/.name/…)

See Also:



37
38
39
# File 'lib/inspec-reporter-flex/mixin/erb_helpers.rb', line 37

def os
  runner.backend.os
end

#remote_command(cmd) ⇒ Train::Extras::CommandResult

Execute a remote command.

Parameters:

  • cmd (String)

    Command to execute

Returns:

  • (Train::Extras::CommandResult)

    Command result (.stdout/.stderr/.exit_status)



14
15
16
# File 'lib/inspec-reporter-flex/mixin/erb_helpers.rb', line 14

def remote_command(cmd)
  runner.backend.backend.run_command(cmd)
end

#remote_file_content(remote_file) ⇒ String

Retrieve remote file contents.

Parameters:

  • remote_file (String)

    Path to the remote file

Returns:

  • (String)

    Contents of the file



22
23
24
# File 'lib/inspec-reporter-flex/mixin/erb_helpers.rb', line 22

def remote_file_content(remote_file)
  runner.backend.backend.file(remote_file).content
end

#scan_timeDateTime

Return latest start time of the scan

Returns:

  • (DateTime)

    Timestamp of the last scan in the profile



6
7
8
# File 'lib/inspec-reporter-flex/mixin/erb_helpers.rb', line 6

def scan_time
  DateTime.strptime(report[:profiles].last[:controls].last[:results].last[:start_time])
end

#status_to_pass(inspec_status) ⇒ Strint

Map InSpec status to cleartext

Parameters:

  • inspec_status (String)

    One of the valid InSpec result status.

Returns:

  • (Strint)

    “ok”/“not ok” depending on status



61
62
63
64
65
66
67
68
# File 'lib/inspec-reporter-flex/mixin/erb_helpers.rb', line 61

def status_to_pass(inspec_status)
  case inspec_status
  when "passed", "skipped", "waived"
    "ok"
  else
    "not ok"
  end
end

#sys_infoClass

Return InSpec SysInfo resource results.

Returns:

  • (Class)

    Look into documentation for properteis (.domain/.fqdn/.hostname/.ip_address/.model/…)

See Also:



45
46
47
# File 'lib/inspec-reporter-flex/mixin/erb_helpers.rb', line 45

def sys_info
  runner.backend.sys_info
end