Module: Mysql2::AwsRdsIam::ClientExtension

Defined in:
lib/mysql2/aws_rds_iam/client_extension.rb

Instance Method Summary collapse

Instance Method Details

#initialize(opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mysql2/aws_rds_iam/client_extension.rb', line 6

def initialize(opts = {})
  opts = opts.dup
  aws_rds_iam_auth = opts.delete(:aws_rds_iam_auth)

  if aws_rds_iam_auth
    raise Errors::ReconnectConfigEnabledError if opts[:reconnect]

    username = opts[:username]
    host = opts[:host]
    port = opts[:port]

    raise Errors::UsernameNotFoundError if username.nil?
    raise Errors::HostNotFoundError if host.nil?

    opts.delete(:password)

    aws_rds_iam_auth_token_generator = opts.delete(:aws_rds_iam_auth_token_generator)

    opts[:password] = AuthToken::Factory.call(aws_rds_iam_auth_token_generator, host, port, username)
    opts[:enable_cleartext_plugin] = true
  end

  super(opts)
end