Class: PG::AzureWorkloadIdentity::ConnectionInfo::ActiveRecordConfigurationHash

Inherits:
Object
  • Object
show all
Defined in:
lib/pg/azure_workload_identity/connection_info/active_record_configuration_hash.rb

Overview

Wraps an ActiveRecord database configuration hash (as produced from config/database.yml) and exposes the connection parameters relevant to Azure Workload Identity authentication, including the non-standard azure_workload_identity flag.

Accessor names follow this gem's connection-info contract (user, host, port) rather than ActiveRecord's keys (note the :username -> #user mapping).

Instance Method Summary collapse

Constructor Details

#initialize(configuration_hash) ⇒ ActiveRecordConfigurationHash

Returns a new instance of ActiveRecordConfigurationHash.

Parameters:

  • configuration_hash (Hash{Symbol => Object})

    an ActiveRecord database configuration hash (symbol keys, as found under an environment in database.yml).



18
19
20
# File 'lib/pg/azure_workload_identity/connection_info/active_record_configuration_hash.rb', line 18

def initialize(configuration_hash)
  @configuration_hash = configuration_hash
end

Instance Method Details

#azure_workload_identityObject?

Returns the value of the azure_workload_identity key, or nil if not set. Truthy values opt the connection into Azure Workload Identity authentication.

Returns:

  • (Object, nil)

    the value of the azure_workload_identity key, or nil if not set. Truthy values opt the connection into Azure Workload Identity authentication.



25
26
27
# File 'lib/pg/azure_workload_identity/connection_info/active_record_configuration_hash.rb', line 25

def azure_workload_identity
  @configuration_hash[:azure_workload_identity]
end

#hostString?

Returns the database host.

Returns:

  • (String, nil)

    the database host.



36
37
38
# File 'lib/pg/azure_workload_identity/connection_info/active_record_configuration_hash.rb', line 36

def host
  @configuration_hash[:host]
end

#portInteger, ...

Returns the database port.

Returns:

  • (Integer, String, nil)

    the database port.



41
42
43
# File 'lib/pg/azure_workload_identity/connection_info/active_record_configuration_hash.rb', line 41

def port
  @configuration_hash[:port]
end

#userString?

Returns the database username (ActiveRecord's :username key).

Returns:

  • (String, nil)

    the database username (ActiveRecord's :username key).



31
32
33
# File 'lib/pg/azure_workload_identity/connection_info/active_record_configuration_hash.rb', line 31

def user
  @configuration_hash[:username]
end