diff --git a/lib/mysql2/aws_iam_auth.rb b/lib/mysql2/aws_iam_auth.rb index 03a56538..df1ac01e 100644 --- a/lib/mysql2/aws_iam_auth.rb +++ b/lib/mysql2/aws_iam_auth.rb @@ -6,7 +6,7 @@ class AwsTokenAuth # Tokens are valid for up to 15 minutes. # We will assume ours expire in 14 minutes to be safe. - TOKEN_EXPIRES_IN = (60*14) # 14 minutes + TOKEN_EXPIRES_IN = (60 * 14) # 14 minutes def initialize begin @@ -25,7 +25,7 @@ def initialize @generator = Aws::RDS::AuthTokenGenerator.new end - def password(user, host port, opts) + def password(user, host, port, opts) params = to_params(user, host, port, opts) key = key_from_params(params) passwd = nil @@ -35,9 +35,10 @@ def password(user, host port, opts) passwd = @passwords[key][:password] end rescue KeyError + passwd = nil end end - if passwd return passwd + return passwd unless passwd.nil? AwsTokenAuth.instance.mutex.synchronize do @passwords[key] = {} @@ -59,8 +60,7 @@ def to_params(user, host, port, opts) end def key_from_params(params) - return "#{params[:user_name]}/#{params[:endpoint]}/#{params[:region]}" + "#{params[:user_name]}/#{params[:endpoint]}/#{params[:region]}" end - end end