Module: PG::AzureWorkloadIdentity::Connection
- Included in:
- PG::AzureWorkloadIdentity
- Defined in:
- lib/pg/azure_workload_identity/connection.rb
Overview
Patch prepended to PG::Connection.singleton_class that teaches libpq's
connection-parameter machinery about the non-standard
azure_workload_identity option and injects a freshly generated auth
token as the password when that option is set.
The three overrides cooperate:
- #conndefaults adds
azure_workload_identityto the list of known parameters so it is recognized rather than rejected as unknown. - #conninfo_parse parses a connection string while preserving the
value of
azure_workload_identityin the returned parameter list (libpq would otherwise drop it). - #parse_connect_args runs the final connection string through
AuthTokenInjector so the password is replaced with a generated
token whenever
azure_workload_identityis set.
Instance Method Summary collapse
-
#conndefaults ⇒ Array<Hash>
Lists libpq's connection parameter defaults, with the
azure_workload_identityoption appended. -
#conninfo_parse(connection_string) ⇒ Array<Hash>
Parses a connection string into the libpq parameter array, preserving the
azure_workload_identityoption. -
#parse_connect_args ⇒ String
Normalizes connection arguments and injects an Azure Workload Identity auth token as the password when
azure_workload_identityis set.
Instance Method Details
#conndefaults ⇒ Array<Hash>
Lists libpq's connection parameter defaults, with the
azure_workload_identity option appended.
27 28 29 |
# File 'lib/pg/azure_workload_identity/connection.rb', line 27 def conndefaults super + [conndefault_azure_workload_identity] end |
#conninfo_parse(connection_string) ⇒ Array<Hash>
Parses a connection string into the libpq parameter array, preserving
the azure_workload_identity option.
The input is first round-tripped through PG::AzureWorkloadIdentity::ConnectionInfo so the custom option is stripped before being handed to libpq's parser, and then re-appended to the parsed result with its original value.
42 43 44 45 46 47 48 49 50 |
# File 'lib/pg/azure_workload_identity/connection.rb', line 42 def conninfo_parse(connection_string) connection_info = ConnectionInfo.from_connection_string(connection_string) super(connection_info.to_s).tap do |result| if connection_info.azure_workload_identity result << conndefault_azure_workload_identity.merge(val: connection_info.azure_workload_identity) end end end |
#parse_connect_args ⇒ String
Normalizes connection arguments and injects an Azure Workload Identity
auth token as the password when azure_workload_identity is set.
59 60 61 |
# File 'lib/pg/azure_workload_identity/connection.rb', line 59 def parse_connect_args(...) AuthTokenInjector.new.inject_into_connection_string(super) end |