/usr/share/puppet/modules.available/openstacklib/lib/puppet/parser/functions/os_database_connection.rb is in puppet-module-openstacklib 9.4.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | require 'puppet/parser/functions'
Puppet::Parser::Functions.newfunction(:os_database_connection,
:type => :rvalue,
:doc => <<-EOS
This function builds a os_database_connection string from various parameters.
EOS
) do |arguments|
require 'uri'
if (arguments.size != 1) then
raise(Puppet::ParseError, "os_database_connection(): Wrong number of arguments " +
"given (#{arguments.size} for 1)")
end
v = arguments[0]
klass = v.class
unless klass == Hash
raise(Puppet::ParseError, "os_database_connection(): Requires an hash, got #{klass}")
end
v.keys.each do |key|
klass = (key == 'extra') ? Hash : String
unless (v[key].class == klass) or (v[key] == :undef)
raise(Puppet::ParseError, "os_database_connection(): #{key} should be a #{klass}")
end
end
parts = {}
unless v.include?('dialect')
raise(Puppet::ParseError, 'os_database_connection(): dialect is required')
end
if v.include?('host')
parts[:host] = v['host']
end
unless v.include?('database')
raise(Puppet::ParseError, 'os_database_connection(): database is required')
end
if v.include?('port')
if v.include?('host')
parts[:port] = v['port'].to_i
else
raise(Puppet::ParseError, 'os_database_connection(): host is required with port')
end
end
if v.include?('username') and (v['username'] != :undef) and (v['username'].to_s != '')
parts[:userinfo] = URI.escape(v['username'])
if v.include?('password') and (v['password'] != :undef) and (v['password'].to_s != '')
parts[:userinfo] += ":#{URI.escape(v['password'])}"
end
end
# support previous charset option on the function. Setting charset will
# override charset if passed in via the extra parameters
if v.include?('charset')
if v.include?('extra')
v['extra'].merge!({ 'charset' => v['charset'] })
else
v['extra'] = { 'charset' => v['charset'] }
end
end
parts[:query] = v['extra'].map{ |k,v| "#{k}=#{v}" }.join('&') if v.include?('extra')
parts[:scheme] = v['dialect']
if v.include?('host')
parts[:path] = "/#{v['database']}"
else
parts[:path] = "///#{v['database']}"
end
URI::Generic.build(parts).to_s
end
|