3 module Puppet::Parser::Functions
4 newfunction(:postgresql_escape, :type => :rvalue, :doc => <<-EOS
5 Safely escapes a string using $$ using a random tag which should be consistent
9 raise(Puppet::ParseError, "postgresql_escape(): Wrong number of arguments " +
10 "given (#{args.size} for 1)") if args.size != 1
14 if password !~ /\$\$/ and password[-1] != '$'
15 retval = "$$#{password}$$"
17 escape = Digest::MD5.hexdigest(password)[0..5].gsub(/\d/,'')
18 until password !~ /#{escape}/
19 escape = Digest::MD5.hexdigest(escape)[0..5].gsub(/\d/,'')
21 retval = "$#{escape}$#{password}$#{escape}$"