Provides a flexible method for encoding AMQP credentials. PLAIN and EXTERNAL are provided by this gem. In order to implement a new authentication mechanism, create a subclass like so:
class MyAuthMechanism < AMQP::Async::AuthMechanismAdapter auth_mechanism "X-MYAUTH" def encode_credentials(username, password) # ... end end
The Adapter that this AuthMechanismAdapter operates on behalf of.
Find and instantiate an AuthMechanismAdapter.
@param [Adapter] adapter The Adapter for which to encode credentials. @return [AuthMechanismAdapter] An AuthMechanismAdapter that can encode
credentials for the Adapter.
@raise [NotImplementedError] The Adapter's mechanism does not
correspond to any known AuthMechanismAdapter.
# File lib/amqp/auth_mechanism_adapter.rb, line 23 def self.for_adapter(adapter) registry[adapter.mechanism].new adapter end
Create a new AuthMechanismAdapter. Users of this class should instead retrieve an instance through for_adapter.
# File lib/amqp/auth_mechanism_adapter.rb, line 57 def initialize(adapter) @adapter = adapter end
Used by subclasses to declare the mechanisms that an AuthMechanismAdapter understands.
@param [Array<String>] mechanisms One or more mechanisms that can be
handled by the subclass.
# File lib/amqp/auth_mechanism_adapter.rb, line 34 def self.auth_mechanism(*mechanisms) mechanisms.each {|mechanism| registry[mechanism] = self} end
Accesses the registry of AuthMechanismAdapter subclasses. Keys in this hash are the names of the authentication mechanisms; values are the classes that handle them. Referencing an unknown mechanism from this Hash will raise NotImplementedError.
# File lib/amqp/auth_mechanism_adapter.rb, line 44 def self.registry @@registry ||= Hash.new {raise NotImplementedError} end