Module: AbideDevUtils::Comply

Includes:
Errors::Comply
Defined in:
lib/abide_dev_utils/comply.rb

Overview

Holds module methods and a class for dealing with Puppet Comply

Defined Under Namespace

Classes: NodeScanReport, ReportScraper, ScanReport

Class Method Summary collapse

Class Method Details

.build_report(url, password, config = nil, **opts) ⇒ Object



17
18
19
# File 'lib/abide_dev_utils/comply.rb', line 17

def self.build_report(url, password, config = nil, **opts)
  ReportScraper.new(url, config, **opts).build_report(password)
end

.compare_reports(report_a, report_b, **opts) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/abide_dev_utils/comply.rb', line 21

def self.compare_reports(report_a, report_b, **opts)
  report_name = opts.fetch(:report_name, nil)
  current_report = ScanReport.new.from_yaml(report_a)
  last_report = if opts.fetch(:remote_storage, '') == 'gcloud'
                  report_name = report_b if report_name.nil?
                  ScanReport.new.from_yaml(ScanReport.fetch_report(name: report_b))
                else
                  report_name = File.basename(report_b) if report_name.nil?
                  ScanReport.new.from_yaml(File.read(report_b))
                end
  result, details = current_report.report_comparison(last_report, check_goodness: true)
  if result
    AbideDevUtils::Output.simple('No negative differences detected...')
    AbideDevUtils::Output.simple(JSON.pretty_generate(details))
  else
    AbideDevUtils::Output.simple('Negative differences detected!', stream: $stderr)
    AbideDevUtils::Output.simple(JSON.pretty_generate(details), stream: $stderr)
  end
  if opts.fetch(:upload, false) && !opts.fetch(:remote_storage, '').empty? && !report_name.nil?
    AbideDevUtils::Output.simple('Uploading current report...')
    ScanReport.upload_report(File.expand_path(report_a), name: report_name)
    AbideDevUtils::Output.simple('Successfully uploaded report.')
  end
  result
end