diff --git a/.chloggen/solace-receiver-validation-improvements.yaml b/.chloggen/solace-receiver-validation-improvements.yaml new file mode 100644 index 000000000000..9bf32f5b1b64 --- /dev/null +++ b/.chloggen/solace-receiver-validation-improvements.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: solacereceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Update validation step to allow only one auth method. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [36386] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/receiver/solacereceiver/config.go b/receiver/solacereceiver/config.go index e8eaffa48894..ceae502ecde7 100644 --- a/receiver/solacereceiver/config.go +++ b/receiver/solacereceiver/config.go @@ -19,6 +19,7 @@ const ( var ( errMissingAuthDetails = errors.New("authentication details are required, either for plain user name password or XOAUTH2 or client certificate") + errTooManyAuthDetails = errors.New("only one authentication method must be used") errMissingQueueName = errors.New("queue definition is required, queue definition has format queue://") errMissingPlainTextParams = errors.New("missing plain text auth params: Username, Password") errMissingXauth2Params = errors.New("missing xauth2 text auth params: Username, Bearer") @@ -46,9 +47,22 @@ type Config struct { // Validate checks the receiver configuration is valid func (cfg *Config) Validate() error { - if cfg.Auth.PlainText == nil && cfg.Auth.External == nil && cfg.Auth.XAuth2 == nil { + authMethod := 0 + if cfg.Auth.PlainText != nil { + authMethod++ + } + if cfg.Auth.External != nil { + authMethod++ + } + if cfg.Auth.XAuth2 != nil { + authMethod++ + } + if authMethod == 0 { return errMissingAuthDetails } + if authMethod > 1 { + return errTooManyAuthDetails + } if len(strings.TrimSpace(cfg.Queue)) == 0 { return errMissingQueueName } diff --git a/receiver/solacereceiver/config_test.go b/receiver/solacereceiver/config_test.go index e0169e79c27d..230027892180 100644 --- a/receiver/solacereceiver/config_test.go +++ b/receiver/solacereceiver/config_test.go @@ -87,6 +87,15 @@ func TestConfigValidateMissingAuth(t *testing.T) { assert.Equal(t, errMissingAuthDetails, err) } +func TestConfigValidateMultipleAuth(t *testing.T) { + cfg := createDefaultConfig().(*Config) + cfg.Queue = "someQueue" + cfg.Auth.PlainText = &SaslPlainTextConfig{"Username", "Password"} + cfg.Auth.XAuth2 = &SaslXAuth2Config{"Username", "Bearer"} + err := component.ValidateConfig(cfg) + assert.Equal(t, errTooManyAuthDetails, err) +} + func TestConfigValidateMissingQueue(t *testing.T) { cfg := createDefaultConfig().(*Config) cfg.Auth.PlainText = &SaslPlainTextConfig{"Username", "Password"}