Class: OctocatalogDiff::Catalog::JSON

Inherits:
OctocatalogDiff::Catalog show all
Defined in:
lib/octocatalog-diff/catalog/json.rb

Overview

Represents a Puppet catalog that is read in directly from a JSON file.

Instance Attribute Summary

Attributes inherited from OctocatalogDiff::Catalog

#built, #catalog, #catalog_json, #node, #options

Instance Method Summary collapse

Methods inherited from OctocatalogDiff::Catalog

#build, #build_catalog, #builder, #compilation_dir, #compilation_dir=, create, #environment, #error_message, #error_message=, #puppet_version, #resource, #resources, #retries, #valid?, #validate_references

Constructor Details

#initialize(options) ⇒ JSON

Constructor

Parameters:

  • :json (String)

    REQUIRED: Content of catalog, will be parsed as JSON

  • :node (String)

    Node name (if not supplied, will be determined from catalog)



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/octocatalog-diff/catalog/json.rb', line 15

def initialize(options)
  super

  unless options[:json].is_a?(String)
    raise ArgumentError, "Must supply :json as string in options: #{options[:json].class}"
  end

  @catalog_json = options.fetch(:json)
  begin
    @catalog = ::JSON.parse(@catalog_json)
    @error_message = nil
    @node ||= @catalog['name'] if @catalog.key?('name') # Puppet 4.x
    @node ||= @catalog['data']['name'] if @catalog.key?('data') && @catalog['data'].is_a?(Hash) # Puppet 3.x
  rescue ::JSON::ParserError => exc
    @error_message = "Catalog JSON input failed to parse: #{exc.message}"
    @catalog = nil
    @catalog_json = nil
  end
end

Instance Method Details

#convert_file_resources(dry_run = false) ⇒ Object

Convert file resources source => “puppet:///…” to content => “actual content of file”.



36
37
38
39
40
# File 'lib/octocatalog-diff/catalog/json.rb', line 36

def convert_file_resources(dry_run = false)
  return @options.key?(:basedir) if dry_run
  return false unless @options[:basedir]
  OctocatalogDiff::CatalogUtil::FileResources.convert_file_resources(self, environment)
end