class Kafo::PuppetReport

An abstraction over the Puppet report format

@see puppet.com/docs/puppet/8/format_report.html

Public Class Methods

load_report_file(path) click to toggle source

Load a Puppet report from a path

Both YAML and JSON are supported.

@param [String] path

The path to Puppet report

@return [PuppetReport] The report from the path

# File lib/kafo/puppet_report.rb, line 14
def self.load_report_file(path)
  raise ArgumentError, 'No path given' unless path || path.empty?
  raise ArgumentError, "#{path} is not a readable file" unless File.file?(path) && File.readable?(path)

  data = case File.extname(path)
         when '.yaml'
           require 'yaml'
           content = File.read(path).gsub(%r{!ruby/object.*$}, '')
           YAML.safe_load(content, permitted_classes: [Time, Symbol])
         when '.json'
           require 'json'
           JSON.parse(File.read(path))
         else
           raise ArgumentError, "Unsupported file extension for #{path}"
         end

  PuppetReport.new(data)
end
new(report) click to toggle source

@param [Hash] report

The Puppet report
# File lib/kafo/puppet_report.rb, line 35
def initialize(report)
  @report = report
end

Public Instance Methods

failed_resources() click to toggle source

@return [Array] The failed resources and their status

# File lib/kafo/puppet_report.rb, line 50
def failed_resources
  statuses = @report['resource_statuses']

  raise PuppetReportError, "No resource statuses found in report" unless statuses

  statuses.select { |_title, status| status['failed'] }.map do |title, status|
    # TODO: There's also a message with source Puppet
    # Executing with uid=USER: '/tmp/failing-command'
    # This shows up after Executing '/tmp/failing-command'
    related_logs = logs.select { |log| log['source'].include?(title) }
    PuppetFailedResource.new(status, related_logs)
  end
end
logs() click to toggle source

@return [Array] The Puppet logs

# File lib/kafo/puppet_report.rb, line 45
def logs
  @report['logs']
end
report_format() click to toggle source

@return [Integer] The report format

# File lib/kafo/puppet_report.rb, line 40
def report_format
  @report['report_format']
end