From 6dadf28c420a3462036a253d2c799c0579dbf5c2 Mon Sep 17 00:00:00 2001 From: Ritika <52399571+Ritikaa96@users.noreply.github.com> Date: Wed, 13 Oct 2021 16:25:51 +0530 Subject: [PATCH] Provide support for configuring authentication through TriggerAuthentication for Stan scaler (#2167) Signed-off-by: Ritikaa96 Co-authored-by: Zbynek Roubalik <726523+zroubalik@users.noreply.github.com> --- CHANGELOG.md | 1 + pkg/scalers/stan_scaler.go | 8 ++++---- pkg/scalers/stan_scaler_test.go | 24 ++++++++++++++---------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57202856280..5d8d3626d0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ - Add support to get connection data from Trigger Authorization in MSSQL Scaler ([#2112](https://github.com/kedacore/keda/pull/2112)) - Add support to get connection data from Trigger Authorization in PostgreSQL Scaler ([#2114](https://github.com/kedacore/keda/pull/2114)) - Add support to provide the metric name in Azure Log Analytics Scaler ([#2106](https://github.com/kedacore/keda/pull/2106)) +- Provide support for configuring authentication through TriggerAuthentication for Stan scaler ([#2167](https://github.com/kedacore/keda/pull/2167)) - Add `pageSize` (using regex) in RabbitMQ Scaler ([#2162](https://github.com/kedacore/keda/pull/2162)) - Add `unsafeSsl` parameter in InfluxDB scaler ([#2157](https://github.com/kedacore/keda/pull/2157)) - Improve metric name creation to be unique using scaler index inside the scaler ([#2161](https://github.com/kedacore/keda/pull/2161)) diff --git a/pkg/scalers/stan_scaler.go b/pkg/scalers/stan_scaler.go index fe21fe41d75..fce827343db 100644 --- a/pkg/scalers/stan_scaler.go +++ b/pkg/scalers/stan_scaler.go @@ -76,11 +76,11 @@ func NewStanScaler(config *ScalerConfig) (Scaler, error) { func parseStanMetadata(config *ScalerConfig) (stanMetadata, error) { meta := stanMetadata{} - - if config.TriggerMetadata["natsServerMonitoringEndpoint"] == "" { - return meta, errors.New("no monitoring endpoint given") + var err error + meta.natsServerMonitoringEndpoint, err = GetFromAuthOrMeta(config, "natsServerMonitoringEndpoint") + if err != nil { + return meta, err } - meta.natsServerMonitoringEndpoint = config.TriggerMetadata["natsServerMonitoringEndpoint"] if config.TriggerMetadata["queueGroup"] == "" { return meta, errors.New("no queue group given") diff --git a/pkg/scalers/stan_scaler_test.go b/pkg/scalers/stan_scaler_test.go index a842d6233fd..e5d8dab8ff2 100644 --- a/pkg/scalers/stan_scaler_test.go +++ b/pkg/scalers/stan_scaler_test.go @@ -6,8 +6,9 @@ import ( ) type parseStanMetadataTestData struct { - metadata map[string]string - isError bool + metadata map[string]string + authParams map[string]string + isError bool } type stanMetricIdentifier struct { @@ -18,15 +19,19 @@ type stanMetricIdentifier struct { var testStanMetadata = []parseStanMetadataTestData{ // nothing passed - {map[string]string{}, true}, + {map[string]string{}, map[string]string{}, true}, // Missing subject name, should fail - {map[string]string{"natsServerMonitoringEndpoint": "stan-nats-ss", "queueGroup": "grp1", "durableName": "ImDurable"}, true}, + {map[string]string{"natsServerMonitoringEndpoint": "stan-nats-ss", "queueGroup": "grp1", "durableName": "ImDurable"}, map[string]string{}, true}, // Missing durable name, should fail - {map[string]string{"natsServerMonitoringEndpoint": "stan-nats-ss", "queueGroup": "grp1", "subject": "mySubject"}, true}, + {map[string]string{"natsServerMonitoringEndpoint": "stan-nats-ss", "queueGroup": "grp1", "subject": "mySubject"}, map[string]string{}, true}, // Missing nats server monitoring endpoint, should fail - {map[string]string{"queueGroup": "grp1", "subject": "mySubject"}, true}, + {map[string]string{"queueGroup": "grp1", "subject": "mySubject"}, map[string]string{}, true}, // All good. - {map[string]string{"natsServerMonitoringEndpoint": "stan-nats-ss", "queueGroup": "grp1", "durableName": "ImDurable", "subject": "mySubject"}, false}, + {map[string]string{"natsServerMonitoringEndpoint": "stan-nats-ss", "queueGroup": "grp1", "durableName": "ImDurable", "subject": "mySubject"}, map[string]string{}, false}, + // natsServerMonitoringEndpoint is defined in authParams + {map[string]string{"queueGroup": "grp1", "durableName": "ImDurable", "subject": "mySubject"}, map[string]string{"natsServerMonitoringEndpoint": "stan-nats-ss"}, false}, + // Missing nats server monitoring endpoint , should fail + {map[string]string{"queueGroup": "grp1", "durableName": "ImDurable", "subject": "mySubject"}, map[string]string{"natsServerMonitoringEndpoint": ""}, true}, } var stanMetricIdentifiers = []stanMetricIdentifier{ @@ -36,11 +41,10 @@ var stanMetricIdentifiers = []stanMetricIdentifier{ func TestStanParseMetadata(t *testing.T) { for _, testData := range testStanMetadata { - _, err := parseStanMetadata(&ScalerConfig{TriggerMetadata: testData.metadata}) + _, err := parseStanMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) - } - if testData.isError && err == nil { + } else if testData.isError && err == nil { t.Error("Expected error but got success") } }