Skip to content

Commit 2b355d0

Browse files
Amol VermaAmol Verma
Amol Verma
authored and
Amol Verma
committed
Fixed Lint Checks
Signed-off-by: Amol Verma <[email protected]>
1 parent b0b40ab commit 2b355d0

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

pkg/kafka/auth/config.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ func (config *AuthenticationConfig) SetConfiguration(saramaConfig *sarama.Config
4343
if strings.Trim(authentication, " ") == "" {
4444
authentication = none
4545
}
46-
if config.Authentication == tls || !config.TLS.Insecure {
47-
if err := setTLSConfiguration(&config.TLS, saramaConfig, logger); err != nil {
48-
return err
49-
}
50-
}
46+
if config.Authentication == tls || !config.TLS.Insecure {
47+
if err := setTLSConfiguration(&config.TLS, saramaConfig, logger); err != nil {
48+
return err
49+
}
50+
}
5151

5252
switch authentication {
5353
case none:
@@ -58,7 +58,7 @@ func (config *AuthenticationConfig) SetConfiguration(saramaConfig *sarama.Config
5858
setKerberosConfiguration(&config.Kerberos, saramaConfig)
5959
return nil
6060
case plaintext:
61-
return setPlainTextConfiguration(&config.PlainText, saramaConfig)
61+
return setPlainTextConfiguration(&config.PlainText, saramaConfig)
6262
default:
6363
return fmt.Errorf("Unknown/Unsupported authentication method %s to kafka cluster", config.Authentication)
6464
}
@@ -76,22 +76,22 @@ func (config *AuthenticationConfig) InitFromViper(configPrefix string, v *viper.
7676
config.Kerberos.KeyTabPath = v.GetString(configPrefix + kerberosPrefix + suffixKerberosKeyTab)
7777
config.Kerberos.DisablePAFXFast = v.GetBool(configPrefix + kerberosPrefix + suffixKerberosDisablePAFXFAST)
7878

79-
if config.Authentication == tls || v.GetBool(configPrefix+".tls.enabled"){
80-
tlsClientConfig := tlscfg.ClientFlagsConfig{
81-
Prefix: configPrefix,
82-
}
83-
tlsCfg, err := tlsClientConfig.InitFromViper(v)
84-
if err != nil {
85-
return fmt.Errorf("failed to process Kafka TLS options: %w", err)
86-
}
87-
config.TLS = tlsCfg
79+
tlsEnabled := v.GetBool(configPrefix + ".tls.enabled")
80+
if config.Authentication == tls || v.GetBool(configPrefix+".tls.enabled") {
81+
tlsClientConfig := tlscfg.ClientFlagsConfig{
82+
Prefix: configPrefix,
83+
}
84+
tlsCfg, err := tlsClientConfig.InitFromViper(v)
85+
if err != nil {
86+
return fmt.Errorf("failed to process Kafka TLS options: %w", err)
87+
}
88+
config.TLS = tlsCfg
8889
} else {
89-
// Explicitly set TLS to insecure when disabled
90-
config.TLS = configtls.ClientConfig{
91-
Insecure: true,
92-
}
93-
}
94-
90+
// Explicitly set TLS to insecure when disabled
91+
config.TLS = configtls.ClientConfig{
92+
Insecure: true,
93+
}
94+
}
9595

9696
config.PlainText.Username = v.GetString(configPrefix + plainTextPrefix + suffixPlainTextUsername)
9797
config.PlainText.Password = v.GetString(configPrefix + plainTextPrefix + suffixPlainTextPassword)

pkg/kafka/auth/tls.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import (
1212
"go.uber.org/zap"
1313
)
1414

15-
func setTLSConfiguration(config *configtls.ClientConfig, saramaConfig *sarama.Config, logger *zap.Logger) error {
16-
tlsConfig, err := config.LoadTLSConfig(context.Background())
17-
if err != nil {
18-
return fmt.Errorf("error loading tls config: %w", err)
19-
}
20-
21-
saramaConfig.Net.TLS.Enable = true
22-
saramaConfig.Net.TLS.Config = tlsConfig
23-
return nil
24-
}
15+
func setTLSConfiguration(config *configtls.ClientConfig, saramaConfig *sarama.Config, _ *zap.Logger) error {
16+
tlsConfig, err := config.LoadTLSConfig(context.Background())
17+
if err != nil {
18+
return fmt.Errorf("error loading tls config: %w", err)
19+
}
20+
21+
saramaConfig.Net.TLS.Enable = true
22+
saramaConfig.Net.TLS.Config = tlsConfig
23+
return nil
24+
}

0 commit comments

Comments
 (0)