class OctocatalogDiff::Catalog::JSON
Represents a Puppet catalog that is read in directly from a JSON
file.
Public Class Methods
new(options)
click to toggle source
Constructor @param :json [String] REQUIRED: Content of catalog, will be parsed as JSON
@param :node [String] Node name (if not supplied, will be determined from catalog)
Calls superclass method
OctocatalogDiff::Catalog::new
# 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
Public Instance Methods
convert_file_resources(dry_run = false)
click to toggle source
Convert file resources source => “puppet:///…” to content => “actual content of file”.
# 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