Add actual postgresl module from puppetlabs
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / lib / puppet / parser / functions / postgresql_password.rb
diff --git a/3rdparty/modules/postgresql/lib/puppet/parser/functions/postgresql_password.rb b/3rdparty/modules/postgresql/lib/puppet/parser/functions/postgresql_password.rb
new file mode 100644 (file)
index 0000000..0689e0e
--- /dev/null
@@ -0,0 +1,18 @@
+# hash a string as mysql's "PASSWORD()" function would do it
+require 'digest/md5'
+
+module Puppet::Parser::Functions
+  newfunction(:postgresql_password, :type => :rvalue, :doc => <<-EOS
+    Returns the postgresql password hash from the clear text username / password.
+    EOS
+  ) do |args|
+
+    raise(Puppet::ParseError, "postgresql_password(): Wrong number of arguments " +
+      "given (#{args.size} for 2)") if args.size != 2
+
+    username = args[0]
+    password = args[1]
+
+    'md5' + Digest::MD5.hexdigest(password + username)
+  end
+end