Class: PG::AzureWorkloadIdentity::ConnectionInfo::KeyValueString
- Inherits:
-
Object
- Object
- PG::AzureWorkloadIdentity::ConnectionInfo::KeyValueString
- Defined in:
- lib/pg/azure_workload_identity/connection_info/key_value_string.rb
Overview
Parses and manipulates a PostgreSQL connection string in libpq's
key=value format (e.g. "host=localhost user=admin port=5432").
The parser preserves functional parity with libpq's conninfo_parse,
supporting whitespace around the =, single-quoted values, and
backslash escapes (\\X -> X) in both quoted and unquoted values.
The non-standard azure_workload_identity parameter is recognized and
extracted on construction so it can drive Azure Workload Identity
authentication without being forwarded to libpq.
Defined Under Namespace
Classes: Parser
Instance Attribute Summary collapse
-
#azure_workload_identity ⇒ String?
readonly
The value of the
azure_workload_identityparameter that was present in the original connection string, ornilif the parameter was not set.
Instance Method Summary collapse
-
#host ⇒ String?
The value of the
hostparameter. -
#initialize(connection_string) ⇒ KeyValueString
constructor
Parses the given connection string and extracts the
azure_workload_identityparameter (if any) so it is not forwarded to libpq. -
#password=(value) ⇒ String
Sets the
passwordparameter. -
#port ⇒ String?
The value of the
portparameter. -
#to_h ⇒ Hash{Symbol => String}
A copy of the parsed parameters (excluding
azure_workload_identity, which was extracted at construction). -
#to_s ⇒ String
Serializes the parameters back to a libpq key=value connection string.
-
#user ⇒ String?
The value of the
userparameter.
Constructor Details
#initialize(connection_string) ⇒ KeyValueString
Parses the given connection string and extracts the
azure_workload_identity parameter (if any) so it is not forwarded to
libpq.
36 37 38 39 |
# File 'lib/pg/azure_workload_identity/connection_info/key_value_string.rb', line 36 def initialize(connection_string) @params = Parser.new(connection_string).parse @azure_workload_identity = @params.delete(:azure_workload_identity) end |
Instance Attribute Details
#azure_workload_identity ⇒ String? (readonly)
Returns the value of the azure_workload_identity
parameter that was present in the original connection string, or
nil if the parameter was not set.
27 28 29 |
# File 'lib/pg/azure_workload_identity/connection_info/key_value_string.rb', line 27 def azure_workload_identity @azure_workload_identity end |
Instance Method Details
#host ⇒ String?
Returns the value of the host parameter.
47 48 49 |
# File 'lib/pg/azure_workload_identity/connection_info/key_value_string.rb', line 47 def host @params[:host] end |
#password=(value) ⇒ String
Sets the password parameter.
60 61 62 |
# File 'lib/pg/azure_workload_identity/connection_info/key_value_string.rb', line 60 def password=(value) @params[:password] = value end |
#port ⇒ String?
Returns the value of the port parameter.
52 53 54 |
# File 'lib/pg/azure_workload_identity/connection_info/key_value_string.rb', line 52 def port @params[:port] end |
#to_h ⇒ Hash{Symbol => String}
Returns a copy of the parsed parameters
(excluding azure_workload_identity, which was extracted at
construction).
78 79 80 |
# File 'lib/pg/azure_workload_identity/connection_info/key_value_string.rb', line 78 def to_h @params.dup end |
#to_s ⇒ String
Serializes the parameters back to a libpq key=value connection
string. Values are quoted/escaped via PG::Connection.quote_connstr
so they remain valid when whitespace or special characters are
present. The azure_workload_identity parameter extracted at
construction is not included.
71 72 73 |
# File 'lib/pg/azure_workload_identity/connection_info/key_value_string.rb', line 71 def to_s @params.map { |key, value| "#{key}=#{PG::Connection.quote_connstr(value)}" }.join(" ") end |
#user ⇒ String?
Returns the value of the user parameter.
42 43 44 |
# File 'lib/pg/azure_workload_identity/connection_info/key_value_string.rb', line 42 def user @params[:user] end |