Class: Sbmt::KafkaProducer::Config::Auth

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/sbmt/kafka_producer/config/auth.rb

Constant Summary collapse

AVAILABLE_AUTH_KINDS =
%w[plaintext sasl_plaintext].freeze
DEFAULT_AUTH_KIND =
"plaintext"
AVAILABLE_SASL_MECHANISMS =
%w[PLAIN SCRAM-SHA-256 SCRAM-SHA-512].freeze
DEFAULT_SASL_MECHANISM =
"SCRAM-SHA-512"

Instance Method Summary collapse

Instance Method Details

#to_kafka_optionsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sbmt/kafka_producer/config/auth.rb', line 24

def to_kafka_options
  ensure_options_are_valid

  opts = {}

  case kind
  when "sasl_plaintext"
    opts.merge!(
      "security.protocol": kind,
      "sasl.mechanism": sasl_mechanism,
      "sasl.username": sasl_username,
      "sasl.password": sasl_password
    )
  when "plaintext"
    opts[:"security.protocol"] = kind
  else
    raise Anyway::Config::ValidationError, "unknown auth kind: #{kind}"
  end

  opts.symbolize_keys
end