summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@puppetlabs.com>2011-04-12 21:01:09 -0700
committerLuke Kanies <luke@puppetlabs.com>2011-04-14 17:07:08 -0700
commit07a7a68a25eb9b21189751c27f90f972224ea533 (patch)
tree6e322b248247d6e33e3d25007d79ec71e2de7f06 /lib
parentba9bd88b8b60ebe567a6d78d70782610cc281213 (diff)
downloadpuppet-07a7a68a25eb9b21189751c27f90f972224ea533.tar.gz
puppet-07a7a68a25eb9b21189751c27f90f972224ea533.tar.xz
puppet-07a7a68a25eb9b21189751c27f90f972224ea533.zip
Fixing Facts pson methods more resilient
They were currently failing if any values were nil, which happened a lot. We also prefer not to include nil values, since it muddies the json unnecessarily. Reviewed-by: Daniel Pittman <daniel@puppetlabs.com> Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'lib')
-rwxr-xr-xlib/puppet/node/facts.rb20
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb
index 577b62b62..2ff7156c8 100755
--- a/lib/puppet/node/facts.rb
+++ b/lib/puppet/node/facts.rb
@@ -61,18 +61,22 @@ class Puppet::Node::Facts
def self.from_pson(data)
result = new(data['name'], data['values'])
- result.timestamp = Time.parse(data['timestamp'])
- result.expiration = Time.parse(data['expiration'])
+ result.timestamp = Time.parse(data['timestamp']) if data['timestamp']
+ result.expiration = Time.parse(data['expiration']) if data['expiration']
result
end
def to_pson(*args)
- {
- 'expiration' => expiration,
- 'name' => name,
- 'timestamp' => timestamp,
- 'values' => strip_internal,
- }.to_pson(*args)
+ result = {
+ 'document_type' => "Puppet::Node::Facts",
+ 'data' => {}
+ }
+
+ result['data']['name'] = name
+ result['data']['expiration'] = expiration if expiration
+ result['data']['timestamp'] = timestamp if timestamp
+ result['data']['values'] = strip_internal
+ result.to_pson(*args)
end
# Add internal data to the facts for storage.