2011-04-30 15:36:25 +02:00
|
|
|
#
|
2011-08-05 09:25:03 +02:00
|
|
|
# parsejson.rb
|
2011-04-30 15:36:25 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
module Puppet::Parser::Functions
|
2011-08-05 09:25:03 +02:00
|
|
|
newfunction(:parsejson, :type => :rvalue, :doc => <<-EOS
|
2011-07-30 00:09:30 +02:00
|
|
|
This function accepts JSON as a string and converts into the correct Puppet
|
|
|
|
structure.
|
2011-04-30 15:36:25 +02:00
|
|
|
EOS
|
|
|
|
) do |arguments|
|
2011-06-29 22:21:55 +02:00
|
|
|
|
|
|
|
if (arguments.size != 1) then
|
2011-08-05 09:25:03 +02:00
|
|
|
raise(Puppet::ParseError, "parsejson(): Wrong number of arguments "+
|
2011-06-29 22:21:55 +02:00
|
|
|
"given #{arguments.size} for 1")
|
|
|
|
end
|
|
|
|
|
|
|
|
json = arguments[0]
|
|
|
|
|
2011-10-26 00:54:47 +02:00
|
|
|
# PSON is natively available in puppet
|
|
|
|
PSON.load(json)
|
2011-04-30 15:36:25 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# vim: set ts=2 sw=2 et :
|