Sha256: acec2ae312d83652752b252ca0645e412c5299762476fdbea46bdc9c1770ca6e

Contents?: true

Size: 940 Bytes

Versions: 27

Compression:

Stored size: 940 Bytes

Contents

# frozen_string_literal: true

module Kafka
  module Sasl
    class Plain
      PLAIN_IDENT = "PLAIN"

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

      def ident
        PLAIN_IDENT
      end

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

      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
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
ruby-kafka-0.7.5 lib/kafka/sasl/plain.rb
ruby-kafka-0.7.5.beta1 lib/kafka/sasl/plain.rb
ruby-kafka-0.7.4 lib/kafka/sasl/plain.rb
ruby-kafka-0.7.3 lib/kafka/sasl/plain.rb
ruby-kafka-0.7.2 lib/kafka/sasl/plain.rb
ruby-kafka-0.7.1.debugcorruption2 lib/kafka/sasl/plain.rb
ruby-kafka-0.7.1.messagecorruptiondebug lib/kafka/sasl/plain.rb
ruby-kafka-0.7.1 lib/kafka/sasl/plain.rb
ruby-kafka-0.7.1.beta2 lib/kafka/sasl/plain.rb
ruby-kafka-0.7.1.possible.pre.fetch.pre.fix lib/kafka/sasl/plain.rb
ruby-kafka-0.7.1.beta1 lib/kafka/sasl/plain.rb
ruby-kafka-0.7.0 lib/kafka/sasl/plain.rb
ruby-kafka-0.6.8 lib/kafka/sasl/plain.rb
ruby-kafka-0.7.0.beta2 lib/kafka/sasl/plain.rb
ruby-kafka-0.7.0.beta1 lib/kafka/sasl/plain.rb
ruby-kafka-0.7.0.alpha4 lib/kafka/sasl/plain.rb
ruby-kafka-0.6.7 lib/kafka/sasl/plain.rb
ruby-kafka-0.6.6 lib/kafka/sasl/plain.rb
ruby-kafka-0.6.5 lib/kafka/sasl/plain.rb
ruby-kafka-0.6.4 lib/kafka/sasl/plain.rb