Class: PG::AWS_RDS_IAM::AuthTokenGeneratorRegistry

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

Overview

Registers AuthTokenGenerators to be used to generate authentication tokens for PG::Connections that have the aws_rds_iam_auth_token_generator connection parameter set to the registered name.

Instance Method Summary collapse

Constructor Details

#initialize(default_auth_token_generator_class: AuthTokenGenerator) ⇒ AuthTokenGeneratorRegistry

Creates a new AuthTokenRegistry.

Parameters:



11
12
13
14
# File 'lib/pg/aws_rds_iam/auth_token_generator_registry.rb', line 11

def initialize(default_auth_token_generator_class: AuthTokenGenerator)
  @default_auth_token_generator_class = default_auth_token_generator_class
  reset
end

Instance Method Details

#add(name) ⇒ void

This method returns an undefined value.

Registers an PG::AWS_RDS_IAM::AuthTokenGenerator.

Parameters:

  • name (String, Symbol)

Yield Returns:



21
22
23
# File 'lib/pg/aws_rds_iam/auth_token_generator_registry.rb', line 21

def add(name, &)
  @registry[name.to_s] = Memoizer.new(&)
end

#fetch(name) ⇒ AuthTokenGenerator

Parameters:

  • name (String, Symbol)

Returns:



29
30
31
# File 'lib/pg/aws_rds_iam/auth_token_generator_registry.rb', line 29

def fetch(name)
  @registry.fetch(name.to_s).call
end

#remove(name) ⇒ void

This method returns an undefined value.

Unregisters an PG::AWS_RDS_IAM::AuthTokenGenerator.

Parameters:

  • name (String, Symbol)


37
38
39
# File 'lib/pg/aws_rds_iam/auth_token_generator_registry.rb', line 37

def remove(name)
  @registry.delete name.to_s
end

#resetvoid

This method returns an undefined value.

Unregisters all PG::AWS_RDS_IAM::AuthTokenGenerators and re-registers the default PG::AWS_RDS_IAM::AuthTokenGenerator.



44
45
46
47
48
49
50
51
# File 'lib/pg/aws_rds_iam/auth_token_generator_registry.rb', line 44

def reset
  @registry = {}

  add :default do
    config = Aws::RDS::Client.new.config
    @default_auth_token_generator_class.new(credentials: config.credentials, region: config.region)
  end
end