mirror of https://github.com/tidwall/tile38.git
Add option to select sha function
This commit is contained in:
parent
6dfcf896d4
commit
bb2253204c
|
@ -67,6 +67,8 @@ type Endpoint struct {
|
||||||
Port int
|
Port int
|
||||||
TopicName string
|
TopicName string
|
||||||
SASL bool
|
SASL bool
|
||||||
|
SASLSHA256 bool
|
||||||
|
SASLSHA512 bool
|
||||||
TLS bool
|
TLS bool
|
||||||
CACertFile string
|
CACertFile string
|
||||||
CertFile string
|
CertFile string
|
||||||
|
@ -426,6 +428,10 @@ func parseEndpoint(s string) (Endpoint, error) {
|
||||||
endpoint.Kafka.KeyFile = val[0]
|
endpoint.Kafka.KeyFile = val[0]
|
||||||
case "sasl":
|
case "sasl":
|
||||||
endpoint.Kafka.SASL, _ = strconv.ParseBool(val[0])
|
endpoint.Kafka.SASL, _ = strconv.ParseBool(val[0])
|
||||||
|
case "sha256":
|
||||||
|
endpoint.Kafka.SASLSHA256, _ = strconv.ParseBool(val[0])
|
||||||
|
case "sha512":
|
||||||
|
endpoint.Kafka.SASLSHA512, _ = strconv.ParseBool(val[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,9 +84,15 @@ func (conn *KafkaConn) Send(msg string) error {
|
||||||
cfg.Net.SASL.User = os.Getenv("KAFKA_USERNAME")
|
cfg.Net.SASL.User = os.Getenv("KAFKA_USERNAME")
|
||||||
cfg.Net.SASL.Password = os.Getenv("KAFKA_PASSWORD")
|
cfg.Net.SASL.Password = os.Getenv("KAFKA_PASSWORD")
|
||||||
cfg.Net.SASL.Handshake = true
|
cfg.Net.SASL.Handshake = true
|
||||||
|
if conn.ep.Kafka.SASLSHA256 {
|
||||||
|
cfg.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient { return &XDGSCRAMClient{HashGeneratorFcn: SHA256} }
|
||||||
|
cfg.Net.SASL.Mechanism = sarama.SASLTypeSCRAMSHA256
|
||||||
|
}
|
||||||
|
if conn.ep.Kafka.SASLSHA512 {
|
||||||
cfg.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient { return &XDGSCRAMClient{HashGeneratorFcn: SHA512} }
|
cfg.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient { return &XDGSCRAMClient{HashGeneratorFcn: SHA512} }
|
||||||
cfg.Net.SASL.Mechanism = sarama.SASLTypeSCRAMSHA512
|
cfg.Net.SASL.Mechanism = sarama.SASLTypeSCRAMSHA512
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cfg.Net.DialTimeout = time.Second
|
cfg.Net.DialTimeout = time.Second
|
||||||
cfg.Net.ReadTimeout = time.Second * 5
|
cfg.Net.ReadTimeout = time.Second * 5
|
||||||
|
|
Loading…
Reference in New Issue