diff options
author | varac <varacanero@zeromail.org> | 2013-04-24 00:13:56 +0200 |
---|---|---|
committer | varac <varacanero@zeromail.org> | 2013-04-24 00:13:56 +0200 |
commit | 66e0fa8f1bc5062e9d753598ad17602c378a2994 (patch) | |
tree | 4135cf080574ed4f80e0c830816ac032346c4509 /lib/puppet/parser/functions | |
parent | 095a5a01d5a7c7e3d95a71846220545080f7581c (diff) |
added str_and_salt2sha1.rb for hashing couchdb pw
Diffstat (limited to 'lib/puppet/parser/functions')
-rw-r--r-- | lib/puppet/parser/functions/str_and_salt2sha1.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/str_and_salt2sha1.rb b/lib/puppet/parser/functions/str_and_salt2sha1.rb new file mode 100644 index 0000000..71d69cf --- /dev/null +++ b/lib/puppet/parser/functions/str_and_salt2sha1.rb @@ -0,0 +1,32 @@ +# +# str_and_salt2sha1.rb +# + +module Puppet::Parser::Functions + newfunction(:str_and_salt2sha1, :type => :rvalue, :doc => <<-EOS +This converts a string to an array containing the salted SHA1 password hash in +the first field, and the salt itself in second field of the returned array. +This combination is used i.e. for couchdb passwords. + EOS + ) do |arguments| + require 'digest/sha1' + + raise(Puppet::ParseError, "str_and_salt2sha1(): Wrong number of arguments " + + "passed (#{arguments.size} but we require 1)") if arguments.size != 1 + + str_and_salt = arguments[0] + + unless str_and_salt.is_a?(Array) + raise(Puppet::ParseError, 'str_and_salt2sha1(): Requires a ' + + "Array argument, you passed: #{password.class}") + end + + str = str_and_salt[0] + salt = str_and_salt[1] + sha1 = Digest::SHA1.hexdigest(str+ salt) + + return sha1 + end +end + +# vim: set ts=2 sw=2 et : |