Class: PG::AWS_RDS_IAM::AuthTokenGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/pg/aws_rds_iam/auth_token_generator.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(credentials:, region:) ⇒ AuthTokenGenerator

Creates a new authentication token generator.

Parameters:

  • credentials (Aws::CredentialProvider)

    the IAM credentials with which to sign the token

  • region (String)

    the AWS region in which the RDS instances are running



13
14
15
16
# File 'lib/pg/aws_rds_iam/auth_token_generator.rb', line 13

def initialize(credentials:, region:)
  @generator = Aws::RDS::AuthTokenGenerator.new(credentials:)
  @region = region
end

Instance Method Details

#call(host:, port:, user:) ⇒ String

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

Parameters:

  • host (String)

    the host name of the RDS instance that you want to access

  • port (String)

    the port number used for connecting to your RDS instance

  • user (String)

    the database account that you want to access

Returns:

  • (String)

    the generated authentication token



24
25
26
# 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