Skip to content

Commit f32e3e6

Browse files
committed
dynamic password provider
1 parent 58c8190 commit f32e3e6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/mysql2/client.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def initialize(opts = {})
7979
end
8080

8181
user = opts[:username] || opts[:user]
82-
pass = opts[:password] || opts[:pass]
82+
pass = extract_password(opts)
8383
host = opts[:host] || opts[:hostname]
8484
port = opts[:port]
8585
database = opts[:database] || opts[:dbname] || opts[:db]
@@ -97,6 +97,14 @@ def initialize(opts = {})
9797
connect user, pass, host, port, database, socket, flags, conn_attrs
9898
end
9999

100+
def extract_password(opts)
101+
return (opts[:password] || opts[:pass]) if !opts[:password_provider]
102+
klass = Kernel.const_get(opts[:password_provider])
103+
104+
obj = klass.new(opts)
105+
obj.password
106+
end
107+
100108
def parse_ssl_mode(mode)
101109
m = mode.to_s.upcase
102110
if m.start_with?('SSL_MODE_')

0 commit comments

Comments
 (0)