Class: Kafka::Sasl::Plain

Inherits:
Object
  • Object
show all
Defined in:
lib/kafka/sasl/plain.rb

Constant Summary collapse

PLAIN_IDENT =
"PLAIN"

Instance Method Summary collapse

Constructor Details

#initialize(logger:, authzid:, username:, password:) ⇒ Plain

Returns a new instance of Plain.



8
9
10
11
12
13
# File 'lib/kafka/sasl/plain.rb', line 8

def initialize(logger:, authzid:, username:, password:)
  @logger = TaggedLogger.new(logger)
  @authzid = authzid
  @username = username
  @password = password
end

Instance Method Details

#authenticate!(host, encoder, decoder) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kafka/sasl/plain.rb', line 23

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.message}"
  end

  @logger.debug "SASL PLAIN authentication successful."
end

#configured?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/kafka/sasl/plain.rb', line 19

def configured?
  @authzid && @username && @password
end

#identObject



15
16
17
# File 'lib/kafka/sasl/plain.rb', line 15

def ident
  PLAIN_IDENT
end