Skip to content

Commit

Permalink
Merge pull request #38 from kshpytsya/kafka-sasl-plain
Browse files Browse the repository at this point in the history
 Add SASL/PLAIN config to kafka
  • Loading branch information
jippi committed Jan 19, 2019
2 parents fc21876 + e556d30 commit 60be354
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ session "" {

### Kafka

To connect to Kafka with TLS, set the SINK_KAFKA_CA_CERT_PATH to the path to your CA cert file
To connect to Kafka with TLS, set the SINK_KAFKA_CA_CERT_PATH to the path to your CA cert file.
To use SASL/PLAIN authentication, set `$SINK_KAFKA_USER` and `$SINK_KAFKA_PASSWORD` environment variables.


## Usage
Expand Down
8 changes: 8 additions & 0 deletions sink/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ func NewKafka() (*KafkaSink, error) {
config.Net.TLS.Enable = true
}

user := os.Getenv("SINK_KAFKA_USER")
if user != "" {
password := os.Getenv("SINK_KAFKA_PASSWORD")
config.Net.SASL.Enable = true
config.Net.SASL.User = user
config.Net.SASL.Password = password
}

producer, err := sarama.NewSyncProducer(brokerList, config)
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 60be354

Please sign in to comment.