Skip to content

Commit

Permalink
Provide support for configuring authentication through TriggerAuthent…
Browse files Browse the repository at this point in the history
…ication for Stan scaler (#2167)

Signed-off-by: Ritikaa96 <[email protected]>
Co-authored-by: Zbynek Roubalik <[email protected]>
  • Loading branch information
Ritikaa96 and zroubalik authored Oct 13, 2021
1 parent 17a380c commit 6dadf28
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions pkg/scalers/stan_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
24 changes: 14 additions & 10 deletions pkg/scalers/stan_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{
Expand All @@ -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")
}
}
Expand Down

0 comments on commit 6dadf28

Please sign in to comment.