Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support env SASL_USER_PASSWORD #442

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions kafka_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ func NewExporter(opts kafkaOpts, topicFilter string, topicExclude string, groupF
if opts.useSASL {
// Convert to lowercase so that SHA512 and SHA256 is still valid
opts.saslMechanism = strings.ToLower(opts.saslMechanism)

saslPassword := opts.saslPassword
if saslPassword == "" {
saslPassword = os.Getenv("SASL_USER_PASSWORD")
}

switch opts.saslMechanism {
case "scram-sha512":
config.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient { return &XDGSCRAMClient{HashGeneratorFcn: SHA512} }
Expand All @@ -182,7 +188,7 @@ func NewExporter(opts kafkaOpts, topicFilter string, topicExclude string, groupF
config.Net.SASL.GSSAPI.KeyTabPath = opts.keyTabPath
} else {
config.Net.SASL.GSSAPI.AuthType = sarama.KRB5_USER_AUTH
config.Net.SASL.GSSAPI.Password = opts.saslPassword
config.Net.SASL.GSSAPI.Password = saslPassword
}
if opts.saslDisablePAFXFast {
config.Net.SASL.GSSAPI.DisablePAFXFAST = true
Expand All @@ -202,8 +208,8 @@ func NewExporter(opts kafkaOpts, topicFilter string, topicExclude string, groupF
config.Net.SASL.User = opts.saslUsername
}

if opts.saslPassword != "" {
config.Net.SASL.Password = opts.saslPassword
if saslPassword != "" {
config.Net.SASL.Password = saslPassword
}
}

Expand Down