mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
common/kafka: rely on mechanism to enable or disable SASL
Some checks are pending
CI / 🤖 Check dependabot status (push) Waiting to run
CI / 🐧 Build and test on Linux (push) Blocked by required conditions
CI / 🍏 Build and test on macOS (push) Blocked by required conditions
CI / 🔍 Upload code coverage (push) Blocked by required conditions
CI / 🔭 Build Go backend (1.24) (push) Blocked by required conditions
CI / 🔭 Build JS frontend (18) (push) Blocked by required conditions
CI / 🔭 Build JS frontend (20) (push) Blocked by required conditions
CI / 🔭 Build JS frontend (22) (push) Blocked by required conditions
CI / ⚖️ Check licenses (push) Waiting to run
CI / 🐋 Build Docker images (push) Blocked by required conditions
CI / 🚀 Publish release (push) Blocked by required conditions
Update Nix dependencies / Update Nix lockfile (asn2org) (push) Waiting to run
Update Nix dependencies / Update Nix lockfile (nixpkgs) (push) Waiting to run
Update Nix dependencies / Update dependency hashes (push) Waiting to run
Some checks are pending
CI / 🤖 Check dependabot status (push) Waiting to run
CI / 🐧 Build and test on Linux (push) Blocked by required conditions
CI / 🍏 Build and test on macOS (push) Blocked by required conditions
CI / 🔍 Upload code coverage (push) Blocked by required conditions
CI / 🔭 Build Go backend (1.24) (push) Blocked by required conditions
CI / 🔭 Build JS frontend (18) (push) Blocked by required conditions
CI / 🔭 Build JS frontend (20) (push) Blocked by required conditions
CI / 🔭 Build JS frontend (22) (push) Blocked by required conditions
CI / ⚖️ Check licenses (push) Waiting to run
CI / 🐋 Build Docker images (push) Blocked by required conditions
CI / 🚀 Publish release (push) Blocked by required conditions
Update Nix dependencies / Update Nix lockfile (asn2org) (push) Waiting to run
Update Nix dependencies / Update Nix lockfile (nixpkgs) (push) Waiting to run
Update Nix dependencies / Update dependency hashes (push) Waiting to run
Instead of username. This should be the same, but the code is more correct this way.
This commit is contained in:
@@ -36,9 +36,9 @@ type Configuration struct {
|
||||
// SASLConfiguration defines SASL configuration.
|
||||
type SASLConfiguration struct {
|
||||
// Username tells the SASL username
|
||||
Username string `validate:"required_with=SASLAlgorithm"`
|
||||
Username string `validate:"required_with=SASLMechanism"`
|
||||
// Password tells the SASL password
|
||||
Password string `validate:"required_with=SASLAlgorithm SASLUsername"`
|
||||
Password string `validate:"required_with=SASLMechanism"`
|
||||
// Mechanism tells the SASL algorithm
|
||||
Mechanism SASLMechanism `validate:"required_with=SASLUsername"`
|
||||
// OAuthTokenURL tells which URL to use to get an OAuthToken
|
||||
@@ -111,7 +111,7 @@ func NewConfig(config Configuration) (*sarama.Config, error) {
|
||||
kafkaConfig.Net.TLS.Config = tlsConfig
|
||||
}
|
||||
// SASL
|
||||
if config.SASL.Username != "" {
|
||||
if config.SASL.Mechanism != SASLNone {
|
||||
kafkaConfig.Net.SASL.Enable = true
|
||||
kafkaConfig.Net.SASL.User = config.SASL.Username
|
||||
kafkaConfig.Net.SASL.Password = config.SASL.Password
|
||||
@@ -137,6 +137,8 @@ func NewConfig(config Configuration) (*sarama.Config, error) {
|
||||
tlsConfig,
|
||||
config.SASL.Username, config.SASL.Password,
|
||||
config.SASL.OAuthTokenURL)
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown SASL mechanism: %s", config.SASL.Mechanism)
|
||||
}
|
||||
}
|
||||
return kafkaConfig, nil
|
||||
|
||||
@@ -34,8 +34,9 @@ func TestKafkaNewConfig(t *testing.T) {
|
||||
Enable: true,
|
||||
},
|
||||
SASL: SASLConfiguration{
|
||||
Username: "hello",
|
||||
Password: "password",
|
||||
Username: "hello",
|
||||
Password: "password",
|
||||
Mechanism: SASLPlain,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
|
||||
Reference in New Issue
Block a user