|
| 1 | +# This is an autogenerated function, ported from the original legacy version. |
| 2 | +# It /should work/ as is, but will not have all the benefits of the modern |
| 3 | +# function API. You should see the function docs to learn how to add function |
| 4 | +# signatures for type safety and to document this function using puppet-strings. |
| 5 | +# |
| 6 | +# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html |
| 7 | +# |
| 8 | +# ---- original file header ---- |
| 9 | +require 'digest/sha1' |
| 10 | +# ---- original file header ---- |
| 11 | +# |
| 12 | +# @summary |
| 13 | +# @summary |
| 14 | +# Hash a string as mysql's "PASSWORD()" function would do it |
| 15 | +# |
| 16 | +# @param [String] password Plain text password. |
| 17 | +# |
| 18 | +# @return [String] the mysql password hash from the clear text password. |
| 19 | +# |
| 20 | +# |
| 21 | +Puppet::Functions.create_function(:'mysql::mysql_password') do |
| 22 | + # @param args |
| 23 | + # The original array of arguments. Port this to individually managed params |
| 24 | + # to get the full benefit of the modern function API. |
| 25 | + # |
| 26 | + # @return [Data type] |
| 27 | + # Describe what the function returns here |
| 28 | + # |
| 29 | + dispatch :default_impl do |
| 30 | + # Call the method named 'default_impl' when this is matched |
| 31 | + # Port this to match individual params for better type safety |
| 32 | + repeated_param 'Any', :args |
| 33 | + end |
| 34 | + |
| 35 | + def default_impl(*args) |
| 36 | + if args.size != 1 |
| 37 | + raise Puppet::ParseError, _('mysql_password(): Wrong number of arguments given (%{args_length} for 1)') % { args_length: args.length } |
| 38 | + end |
| 39 | + |
| 40 | + return '' if args[0].empty? |
| 41 | + return args[0] if args[0] =~ %r{\*[A-F0-9]{40}$} |
| 42 | + '*' + Digest::SHA1.hexdigest(Digest::SHA1.digest(args[0])).upcase |
| 43 | + end |
| 44 | +end |
0 commit comments