Class: Kafka::Sasl::Plain
- Inherits:
-
Object
- Object
- Kafka::Sasl::Plain
- Defined in:
- lib/kafka/sasl/plain.rb
Constant Summary collapse
- PLAIN_IDENT =
"PLAIN"
Instance Method Summary collapse
- #authenticate!(host, encoder, decoder) ⇒ Object
- #configured? ⇒ Boolean
- #ident ⇒ Object
-
#initialize(logger:, authzid:, username:, password:) ⇒ Plain
constructor
A new instance of Plain.
Constructor Details
#initialize(logger:, authzid:, username:, password:) ⇒ Plain
Returns a new instance of Plain.
6 7 8 9 10 11 |
# File 'lib/kafka/sasl/plain.rb', line 6 def initialize(logger:, authzid:, username:, password:) @logger = logger @authzid = authzid @username = username @password = password end |
Instance Method Details
#authenticate!(host, encoder, decoder) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kafka/sasl/plain.rb', line 21 def authenticate!(host, encoder, decoder) msg = [@authzid, @username, @password].join("\000").force_encoding("utf-8") encoder.write_bytes(msg) begin msg = decoder.bytes raise Kafka::Error, "SASL PLAIN authentication failed: unknown error" unless msg rescue Errno::ETIMEDOUT, EOFError => e raise Kafka::Error, "SASL PLAIN authentication failed: #{e.}" end @logger.debug "SASL PLAIN authentication successful." end |
#configured? ⇒ Boolean
17 18 19 |
# File 'lib/kafka/sasl/plain.rb', line 17 def configured? @authzid && @username && @password end |
#ident ⇒ Object
13 14 15 |
# File 'lib/kafka/sasl/plain.rb', line 13 def ident PLAIN_IDENT end |