/usr/lib/ruby/vendor_ruby/octocatalog-diff/facts/yaml.rb is in octocatalog-diff 1.5.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | # frozen_string_literal: true
require_relative '../facts'
require 'yaml'
module OctocatalogDiff
class Facts
# Deal with facts in YAML files
class Yaml
# Manipulate a YAML file so it can be parsed and return the facts as a hash.
# If we leave it as Puppet::Node::Facts then it will require us to load puppet
# gems in order to parse it, and that's too heavy for simple fact retrieval.
# @param options [Hash] Options hash specifically for this fact type.
# - :fact_file_string [String] => Fact data as a string
# @param node [String] Node name (overrides node name from fact data)
# @return [Hash] Facts
def self.fact_retriever(options = {}, node = '')
fact_file_string = options.fetch(:fact_file_string)
# Touch up the first line before parsing.
fact_file_data = fact_file_string.split(/\n/)
fact_file_data[0] = '---' if fact_file_data[0] =~ /^---/
# Load the parsed fact file.
parsed = YAML.load(fact_file_data.join("\n"))
# This is a handler for a YAML file that has just the facts and none of the
# structure. For example if you saved the output of `facter -y` to a file and
# are passing that in, this will work.
result = if parsed.key?('name') && parsed.key?('values')
parsed
else
{ 'name' => node || parsed['fqdn'] || '', 'values' => parsed }
end
result['name'] = node unless node == ''
result
end
end
end
end
|