Class: InspecPlugins::FlexReporter::Reporter

Inherits:
Inspec::Reporters::Json
  • Object
show all
Includes:
ErbHelpers, FileResolver
Defined in:
lib/inspec-reporter-flex/reporter.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FileResolver

#absolute_path?, #gem_path, #gem_path?, #relative_path, #relative_path?, #resolve_path

Methods included from ErbHelpers

#control_passed?, #impact_to_severity, #inspec_resource, #os, #remote_command, #remote_file_content, #scan_time, #status_to_pass, #sys_info

Class Method Details

.run_data_schema_constraintsString

Return Constraints.

Returns:

  • (String)

    Always “~> 0.0”



47
48
49
# File 'lib/inspec-reporter-flex/reporter.rb', line 47

def self.run_data_schema_constraints
  "~> 0.0"
end

Instance Method Details

#renderObject

Render report



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/inspec-reporter-flex/reporter.rb', line 12

def render
  template_file = resolve_path(config["template"])
  template = ERB.new(File.read(template_file))

  # Use JSON Reporter base's `report` to have pre-processed data
  mushy_report = Hashie::Mash.new(report)

  # Eeease of use here
  platform   = mushy_report.platform
  profiles   = mushy_report.profiles
  statistics = mushy_report.statistics
  version    = mushy_report.version

  # Some pass/fail information
  test_results = profiles.map(&:controls).flatten.map(&:results).flatten.map(&:status)
  passed_tests = test_results.select { |text| text == "passed" }.count
  failed_tests = test_results.count - passed_tests
  percent_pass = 100.0 * passed_tests / test_results.count
  percent_fail = 100.0 - percent_pass

  # Detailed OS
  platform_arch = runner.backend.backend.os.arch
  platform_name = runner.backend.backend.os.title

  # Allow template-based settings
  template_config = config.fetch("template_config", {})

  # ... also can use all InSpec resources via "inspec_resource.NAME.PROPERTY"

  output(template.result(binding))
end