lib/puppet/node/facts.rb in puppet-3.2.4 vs lib/puppet/node/facts.rb in puppet-3.3.0.rc2

- old
+ new

@@ -26,10 +26,11 @@ attr_accessor :name, :values def add_local_facts values["clientcert"] = Puppet.settings[:certname] values["clientversion"] = Puppet.version.to_s + values["clientnoop"] = Puppet.settings[:noop] end def initialize(name, values = {}) @name = name @values = values @@ -62,10 +63,18 @@ values.each do |fact, value| values[fact] = value.to_s end end + # Sanitize fact values by converting everything not a string, boolean + # numeric, array or hash into strings. + def sanitize + values.each do |fact, value| + values[fact] = sanitize_fact value + end + end + def ==(other) return false unless self.name == other.name strip_internal == other.send(:strip_internal) end @@ -91,21 +100,38 @@ def add_timestamp self.timestamp = Time.now end def timestamp=(time) - self.values[:_timestamp] = time + self.values['_timestamp'] = time end def timestamp - self.values[:_timestamp] + self.values['_timestamp'] end private # Strip out that internal data. def strip_internal newvals = values.dup newvals.find_all { |name, value| name.to_s =~ /^_/ }.each { |name, value| newvals.delete(name) } newvals + end + + def sanitize_fact(fact) + if fact.is_a? Hash then + ret = {} + fact.each_pair { |k,v| ret[sanitize_fact k]=sanitize_fact v } + ret + elsif fact.is_a? Array then + fact.collect { |i| sanitize_fact i } + elsif fact.is_a? Numeric \ + or fact.is_a? TrueClass \ + or fact.is_a? FalseClass \ + or fact.is_a? String + fact + else + fact.to_s + end end end