Skip to content

Commit

Permalink
fix(return): fix broken return and removing unused tags
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDavidKruse committed Apr 10, 2020
1 parent 052991e commit 8b2ef89
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 40 deletions.
4 changes: 1 addition & 3 deletions pkg/kafka/auth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type AuthenticationConfig struct {
Kerberos KerberosConfig `mapstructure:"kerberos"`
TLS tlscfg.Options `mapstructure:"tls"`
PlainText PlainTextConfig `mapstructure:"plaintext"`
SCRAM SCRAMConfig `mapstructure:"scram"`
SCRAM scramConfig `mapstructure:"scram"`
}

//SetConfiguration set configure authentication into sarama config structure
Expand Down Expand Up @@ -106,6 +106,4 @@ func (config *AuthenticationConfig) InitFromViper(configPrefix string, v *viper.
config.SCRAM.userName = v.GetString(configPrefix + scramPrefix + suffixScramUserName)
config.SCRAM.password = v.GetString(configPrefix + scramPrefix + suffixScramPassword)
config.SCRAM.algorithm = v.GetString(configPrefix + scramPrefix + suffixScramAlgorithm)
config.SCRAM.useTLS = v.GetBool(configPrefix + scramPrefix + suffixScramTLS)
config.SCRAM.insecureSkipVerify = v.GetBool(configPrefix + scramPrefix + suffixScramInsecureSkipVerify)
}
29 changes: 8 additions & 21 deletions pkg/kafka/auth/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,14 @@ const (
defaultPlainTextPassword = ""

// Scram configuration options
scramPrefix = ".scram"
suffixScramUserName = ".username"
suffixScramAlgorithm = ".algorithm"
suffixScramPassword = ".password"
suffixScramTLS = ".usetls"
suffixScramInsecureSkipVerify = ".insecureSkipVerify"

defaultScramUserName = ""
defaultScramPassword = ""
defaultScramAlgorithm = ""
defaultScramGroup = ""
defaultScramTLS = true
defaultScramInsecureSkipVerify = false
scramPrefix = ".scram"
suffixScramUserName = ".username"
suffixScramAlgorithm = ".algorithm"
suffixScramPassword = ".password"

defaultScramUserName = ""
defaultScramPassword = ""
defaultScramAlgorithm = ""
)

func addKerberosFlags(configPrefix string, flagSet *flag.FlagSet) {
Expand Down Expand Up @@ -121,14 +116,6 @@ func addScramFlags(configPrefix string, flagSet *flag.FlagSet) {
configPrefix+scramPrefix+suffixScramAlgorithm,
defaultScramAlgorithm,
"Scram algorithm used to see how the steps should be hashed")
flagSet.Bool(
configPrefix+scramPrefix+suffixScramTLS,
defaultScramTLS,
"Scram useTLS boolean to see if TLS should be used")
flagSet.Bool(
configPrefix+scramPrefix+suffixScramInsecureSkipVerify,
defaultScramInsecureSkipVerify,
"Scram Insecure Skip Verify boolean to be able to use self signed certifications")
}

// AddFlags add configuration flags to a flagSet.
Expand Down
23 changes: 7 additions & 16 deletions pkg/kafka/auth/scram.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ import (
SCRAM "github.com/xdg/scram"
)

// SCRAMConfig describes the configuration properties required for the SCRAM handshake
// scramConfig describes the configuration properties required for the SCRAM handshake
// between the collector and the pipeline
type SCRAMConfig struct {
userName string `mapstructure:"userName"`
password string `mapstructure:"password"`
algorithm string `mapstructure:"algorithm"`
useTLS bool `mapstructure:"useTLS"`
insecureSkipVerify bool `mapstructure:"insecureSkipVerify"`
type scramConfig struct {
userName string `mapstructure:"userName"`
password string `mapstructure:"password"`
algorithm string `mapstructure:"algorithm"`
}

func setSCRAMConfiguration(config *SCRAMConfig, saramaConfig *sarama.Config) error {
func setSCRAMConfiguration(config *scramConfig, saramaConfig *sarama.Config) error {
saramaConfig.Net.SASL.Enable = true
saramaConfig.Net.SASL.User = config.userName
saramaConfig.Net.SASL.Password = config.password
Expand All @@ -46,14 +44,7 @@ func setSCRAMConfiguration(config *SCRAMConfig, saramaConfig *sarama.Config) err
saramaConfig.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient { return &SCRAMClient{HashGeneratorFcn: SHA256} }
saramaConfig.Net.SASL.Mechanism = sarama.SASLMechanism(sarama.SASLTypeSCRAMSHA256)
} else {
errors.Errorf("invalid SHA algorithm '%s': can be either 'sha256' or 'sha512'", config.algorithm)
}

if config.useTLS {
saramaConfig.Net.TLS.Enable = true
if config.insecureSkipVerify {
saramaConfig.Net.TLS.Config.InsecureSkipVerify = config.insecureSkipVerify
}
return errors.Errorf("invalid SHA algorithm '%s': can be either 'sha256' or 'sha512'", config.algorithm)
}

return nil
Expand Down

0 comments on commit 8b2ef89

Please sign in to comment.