Module: Inspec::Utils::JsonProfileSummary

Defined in:
lib/inspec/utils/json_profile_summary.rb

Overview

Inspec::Utils::JsonProfileSummary takes in certain information to identify a profile and then produces a JSON-formatted summary of that profile. It can return the results to STDOUT or a file. It is currently used in several places in the CLI such as ‘json`, `archive` and `artifact`.

Class Method Summary collapse

Class Method Details

.produce_json(info:, write_path: "", suppress_output: false) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/inspec/utils/json_profile_summary.rb', line 13

def self.produce_json(info:, write_path: "", suppress_output: false)
  # add in inspec version
  info[:generator] = {
    name: "inspec",
    version: Inspec::VERSION,
  }
  if write_path.empty?
    puts JSON.dump(info)
  else
    unless suppress_output
      if File.exist? write_path
        Inspec::Log.info "----> updating #{write_path}"
      else
        Inspec::Log.info "----> creating #{write_path}"
      end
    end
    full_write_path = File.expand_path(write_path)
    File.write(full_write_path, JSON.dump(info))
  end
end