AuthTokenGenerator — AWS SDK for Ruby V3 (original) (raw)

Class: Aws::RDS::AuthTokenGenerator

Inherits:

Object

Defined in:

gems/aws-sdk-rds/lib/aws-sdk-rds/customizations/auth_token_generator.rb

Overview

A utility class that generates an auth token that supports database logins. IAM credentials are used for authentication instead of the database password.

Instance Method Summarycollapse

Constructor Details

#initialize(options = {}) ⇒ AuthTokenGenerator

Returns a new instance of AuthTokenGenerator.

16 17 18 # File 'gems/aws-sdk-rds/lib/aws-sdk-rds/customizations/auth_token_generator.rb', line 16 def initialize(options = {}) @credentials = options.fetch(:credentials) end

Instance Method Details

#generate_auth_token(options) ⇒ String Also known as:auth_token

Creates an auth login token.

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 # File 'gems/aws-sdk-rds/lib/aws-sdk-rds/customizations/auth_token_generator.rb', line 32 def generate_auth_token(options) region = options.fetch(:region) endpoint = options.fetch(:endpoint) user_name = options.fetch(:user_name) param_list = Aws::Query::ParamList.new param_list.set('Action', 'connect') param_list.set('DBUser', user_name) signer = Aws::Sigv4::Signer.new( service: 'rds-db', region: region, credentials_provider: @credentials ) presigned_url = signer.presign_url( http_method: 'GET', url: "https://#{endpoint}/?#{param_list}", body: '', expires_in: options[:expires_in] ).to_s presigned_url[8..-1] end