Class: PG::AWS_RDS_IAM::AuthTokenGeneratorRegistry
- Inherits:
-
Object
- Object
- PG::AWS_RDS_IAM::AuthTokenGeneratorRegistry
- Defined in:
- lib/pg/aws_rds_iam/auth_token_generator_registry.rb
Overview
Registers AuthTokenGenerators to be used to generate authentication tokens for PG::Connection
s that have the
aws_rds_iam_auth_token_generator
connection parameter set to the registered name.
Instance Method Summary collapse
-
#add(name) ⇒ void
Registers an AuthTokenGenerator.
-
#fetch(name) ⇒ AuthTokenGenerator
Looks up an AuthTokenGenerator by name.
-
#initialize(default_auth_token_generator_class: AuthTokenGenerator) ⇒ AuthTokenGeneratorRegistry
constructor
Creates a new
AuthTokenRegistry
. -
#remove(name) ⇒ void
Unregisters an AuthTokenGenerator.
-
#reset ⇒ void
Unregisters all AuthTokenGenerators and re-registers the default AuthTokenGenerator.
Constructor Details
#initialize(default_auth_token_generator_class: AuthTokenGenerator) ⇒ AuthTokenGeneratorRegistry
Creates a new AuthTokenRegistry
.
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.
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
Looks up an PG::AWS_RDS_IAM::AuthTokenGenerator by name.
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.
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 |
#reset ⇒ void
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 |