class PG::AWS_RDS_IAM::AuthTokenGenerator

Generates short-lived authentication tokens for connecting to Amazon RDS instances.

@see docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.html

Public Class Methods

new(credentials:, region:) click to toggle source

Creates a new authentication token generator.

@param credentials [Aws::CredentialProvider] the IAM credentials with which to sign the token @param region [String] the AWS region in which the RDS instances are running

# File lib/pg/aws_rds_iam/auth_token_generator.rb, line 13
def initialize(credentials:, region:)
  @generator = Aws::RDS::AuthTokenGenerator.new(credentials: credentials)
  @region = region
end

Public Instance Methods

call(host:, port:, user:) click to toggle source

Generates an authentication token for connecting to an Amazon RDS instance.

@param host [String] the host name of the RDS instance that you want to access @param port [String] the port number used for connecting to your RDS instance @param user [String] the database account that you want to access @return [String] the generated authentication token

# File lib/pg/aws_rds_iam/auth_token_generator.rb, line 24
def call(host:, port:, user:)
  @generator.auth_token(region: @region, endpoint: "#{host}:#{port}", user_name: user)
end