From 068c35406b1a5289fce0c921e10fad54684999a1 Mon Sep 17 00:00:00 2001 From: jorturfer Date: Tue, 21 Sep 2021 22:53:35 +0200 Subject: [PATCH 1/3] Adds support to set the connection data from Trigger Authorization Signed-off-by: jorturfer --- pkg/scalers/mssql_scaler.go | 33 ++++++++++++++++++++++---------- pkg/scalers/mssql_scaler_test.go | 8 ++++++++ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/pkg/scalers/mssql_scaler.go b/pkg/scalers/mssql_scaler.go index 805bae96f29..981327b887e 100644 --- a/pkg/scalers/mssql_scaler.go +++ b/pkg/scalers/mssql_scaler.go @@ -108,28 +108,41 @@ func parseMSSQLMetadata(config *ScalerConfig) (*mssqlMetadata, error) { meta.connectionString = config.ResolvedEnv[config.TriggerMetadata["connectionStringFromEnv"]] default: meta.connectionString = "" - if val, ok := config.TriggerMetadata["host"]; ok { - meta.host = val - } else { + + if config.AuthParams["host"] != "" { + meta.host = config.AuthParams["host"] + } else if config.TriggerMetadata["host"] != "" { + meta.host = config.TriggerMetadata["host"] + } + if meta.host == "" { return nil, fmt.Errorf("no host given") } - if val, ok := config.TriggerMetadata["port"]; ok { - port, err := strconv.Atoi(val) + var paramPort string + if config.AuthParams["port"] != "" { + paramPort = config.AuthParams["port"] + } else if config.TriggerMetadata["port"] != "" { + paramPort = config.TriggerMetadata["port"] + } + if paramPort != "" { + port, err := strconv.Atoi(paramPort) if err != nil { return nil, fmt.Errorf("port parsing error %s", err.Error()) } - meta.port = port } - if val, ok := config.TriggerMetadata["username"]; ok { - meta.username = val + if config.AuthParams["username"] != "" { + meta.username = config.AuthParams["username"] + } else if config.TriggerMetadata["username"] != "" { + meta.username = config.TriggerMetadata["username"] } // database is optional in SQL s - if val, ok := config.TriggerMetadata["database"]; ok { - meta.database = val + if config.AuthParams["database"] != "" { + meta.database = config.AuthParams["database"] + } else if config.TriggerMetadata["database"] != "" { + meta.database = config.TriggerMetadata["database"] } if config.AuthParams["password"] != "" { diff --git a/pkg/scalers/mssql_scaler_test.go b/pkg/scalers/mssql_scaler_test.go index 8f5291333a8..b8d9043976e 100644 --- a/pkg/scalers/mssql_scaler_test.go +++ b/pkg/scalers/mssql_scaler_test.go @@ -65,6 +65,14 @@ var testInputs = []mssqlTestData{ expectedMetricName: "mssql-AdventureWorks", expectedConnectionString: "sqlserver://user2:Password%232@example.database.windows.net?database=AdventureWorks", }, + // connection string generated from full authParams + { + metadata: map[string]string{"query": "SELECT 1", "targetValue": "1"}, + resolvedEnv: map[string]string{}, + authParams: map[string]string{"password": "Password#2", "host": "example.database.windows.net", "username": "user2", "database": "AdventureWorks", "port": "1433"}, + expectedMetricName: "mssql-AdventureWorks", + expectedConnectionString: "sqlserver://user2:Password%232@example.database.windows.net:1433?database=AdventureWorks", + }, // variation of previous: no database name, metricName from host { metadata: map[string]string{"query": "SELECT 1", "targetValue": "1", "host": "example.database.windows.net", "username": "user3"}, From b0dffc40b7bfe56e90293ea427a358ddbc960806 Mon Sep 17 00:00:00 2001 From: jorturfer Date: Tue, 21 Sep 2021 22:56:03 +0200 Subject: [PATCH 2/3] Update CHANGELOG Signed-off-by: jorturfer --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d278c433fc6..94e1f9c0760 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ - Escape `queueName` and `vhostName` in RabbitMQ Scaler before use them in query string (bug fix) ([#2055](https://github.com/kedacore/keda/pull/2055)) - TriggerAuthentication/Vault: add support for HashiCorp Vault namespace (Vault Enterprise) ([#2085](https://github.com/kedacore/keda/pull/2085)) - Add custom http timeout in RabbitMQ Scaler ([#2086](https://github.com/kedacore/keda/pull/2086)) +- Add support to getthe connection data from Trigger Authorization in MSSQL Scaler ([#2112](https://github.com/kedacore/keda/pull/2112)) ### Breaking Changes From 43bf0a6d28c07a4f4ebd582b487daa417f5f5208 Mon Sep 17 00:00:00 2001 From: jorturfer Date: Tue, 21 Sep 2021 22:57:58 +0200 Subject: [PATCH 3/3] Update CHANGELOG Signed-off-by: jorturfer --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94e1f9c0760..c0c09b442c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,7 +35,7 @@ - Escape `queueName` and `vhostName` in RabbitMQ Scaler before use them in query string (bug fix) ([#2055](https://github.com/kedacore/keda/pull/2055)) - TriggerAuthentication/Vault: add support for HashiCorp Vault namespace (Vault Enterprise) ([#2085](https://github.com/kedacore/keda/pull/2085)) - Add custom http timeout in RabbitMQ Scaler ([#2086](https://github.com/kedacore/keda/pull/2086)) -- Add support to getthe 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 MSSQL Scaler ([#2112](https://github.com/kedacore/keda/pull/2112)) ### Breaking Changes