Skip to content

Commit

Permalink
validate only one method of auth
Browse files Browse the repository at this point in the history
  • Loading branch information
wildum committed Nov 14, 2024
1 parent e96ada4 commit 2c62521
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/component/otelcol/receiver/solace/solace.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,17 @@ func (args *Arguments) SetToDefault() {

// Validate implements syntax.Validator.
func (args *Arguments) Validate() error {
if args.Auth.PlainText == nil && args.Auth.External == nil && args.Auth.XAuth2 == nil {
authMethod := 0
if args.Auth.PlainText != nil {
authMethod++
}
if args.Auth.External != nil {
authMethod++
}
if args.Auth.XAuth2 != nil {
authMethod++
}
if authMethod != 1 {
return fmt.Errorf("the auth block must contain either a sasl_plain block, a sasl_xauth2 block or a sasl_external block")
}
if len(strings.TrimSpace(args.Queue)) == 0 {
Expand Down
18 changes: 18 additions & 0 deletions internal/component/otelcol/receiver/solace/solace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,24 @@ func TestArguments_Validate(t *testing.T) {
`,
expectedError: "the auth block must contain either a sasl_plain block, a sasl_xauth2 block or a sasl_external block",
},
{
testName: "Multiple Auth",
cfg: `
queue = "queue://#telemetry_testprofile"
auth {
sasl_plain {
username = "alloy"
password = "password"
}
sasl_xauth2 {
username = "alloy"
bearer = "bearer"
}
}
output {}
`,
expectedError: "the auth block must contain either a sasl_plain block, a sasl_xauth2 block or a sasl_external block",
},
{
testName: "Empty Queue",
cfg: `
Expand Down

0 comments on commit 2c62521

Please sign in to comment.