-
Notifications
You must be signed in to change notification settings - Fork 6
/
config_sasl.go
48 lines (41 loc) · 1.33 KB
/
config_sasl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package kafka
import (
"flag"
"fmt"
)
const (
SASLMechanismPlain = "PLAIN"
SASLMechanismScramSHA256 = "SCRAM-SHA-256"
SASLMechanismScramSHA512 = "SCRAM-SHA-512"
SASLMechanismGSSAPI = "GSSAPI"
SASLMechanismOAuthBearer = "OAUTHBEARER"
)
// SASLConfig for Kafka client
type SASLConfig struct {
Enabled bool `yaml:"enabled"`
Username string `yaml:"username"`
Password string `yaml:"password"`
Mechanism string `yaml:"mechanism"`
GSSAPIConfig SASLGSSAPIConfig `yaml:"gssapi"`
}
// RegisterFlags for all sensitive Kafka SASL configs.
func (c *SASLConfig) RegisterFlags(f *flag.FlagSet) {
f.StringVar(&c.Password, "shop.kafka.sasl.password", "", "SASL password")
c.GSSAPIConfig.RegisterFlags(f)
}
// SetDefaults for SASL Config
func (c *SASLConfig) SetDefaults() {
c.Mechanism = SASLMechanismPlain
}
// Validate SASL config input
func (c *SASLConfig) Validate() error {
switch c.Mechanism {
case SASLMechanismPlain, SASLMechanismScramSHA256, SASLMechanismScramSHA512, SASLMechanismGSSAPI:
// Valid and supported
case SASLMechanismOAuthBearer:
return fmt.Errorf("sasl mechanism '%v' is valid but not yet supported. Please submit an issue if you need it", c.Mechanism)
default:
return fmt.Errorf("given sasl mechanism '%v' is invalid", c.Mechanism)
}
return nil
}