class InspecPlugins::FlexReporter::Reporter
Constants
- ENV_PREFIX
Attributes
config[W]
env[W]
inspec_config[W]
logger[W]
template_contents[W]
Public Class Methods
run_data_schema_constraints()
click to toggle source
Return Constraints.
@return [String] Always “~> 0.0”
# File lib/inspec-reporter-flex/reporter.rb, line 50 def self.run_data_schema_constraints "~> 0.0" end
Public Instance Methods
render()
click to toggle source
Render report
# File lib/inspec-reporter-flex/reporter.rb, line 16 def render template = ERB.new(template_contents) # 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
Private Instance Methods
config()
click to toggle source
Initialize configuration with defaults and Plugin
config.
@return [Hash] Configuration data after merge
# File lib/inspec-reporter-flex/reporter.rb, line 67 def config @config unless @config.nil? # Defaults @config = { "template_file" => "templates/flex.erb", } @config.merge! inspec_config.fetch_plugin_config("inspec-reporter-flex") @config.merge! config_environment logger.debug format("Configuration: %<config>s", config: @config) @config end
config_environment()
click to toggle source
Allow (top-level) setting overrides from environment.
@return [Hash] Configuration data from environment
# File lib/inspec-reporter-flex/reporter.rb, line 86 def config_environment env_reporter = env.select { |var, _| var.start_with?(ENV_PREFIX) } env_reporter.transform_keys { |key| key.delete_prefix(ENV_PREFIX).downcase } end
env()
click to toggle source
Return environment variables.
@return [Hash] Mapping of environment variables
# File lib/inspec-reporter-flex/reporter.rb, line 94 def env @env ||= ENV end
inspec_config()
click to toggle source
Return InSpec Config object.
@return [Inspec::Config] The InSpec config object
# File lib/inspec-reporter-flex/reporter.rb, line 101 def inspec_config @inspec_config ||= Inspec::Config.cached end
logger()
click to toggle source
Return InSpec logger.
@return [Inspec:Log] The Logger object
# File lib/inspec-reporter-flex/reporter.rb, line 108 def logger @logger ||= Inspec::Log end
runner()
click to toggle source
Return InSpec Runner for further inspection.
@return [Inspec::Runner] Runner instance
# File lib/inspec-reporter-flex/reporter.rb, line 115 def runner require "binding_of_caller" binding.callers.find { |b| b.frame_description == "run_tests" }.receiver end
template_contents()
click to toggle source
Read contents of requested template.
@return [String] ERB Template @raise [IOError]
# File lib/inspec-reporter-flex/reporter.rb, line 60 def template_contents @template_contents ||= File.read full_path(config["template_file"]) end