diff --git a/CHANGELOG.md b/CHANGELOG.md index ef37a7f330f..d706e8321f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ - 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)) - 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)) ### Breaking Changes diff --git a/pkg/scalers/influxdb_scaler.go b/pkg/scalers/influxdb_scaler.go index befe8d043ab..ff78c3215e6 100644 --- a/pkg/scalers/influxdb_scaler.go +++ b/pkg/scalers/influxdb_scaler.go @@ -2,6 +2,7 @@ package scalers import ( "context" + "crypto/tls" "fmt" "net/url" "strconv" @@ -28,6 +29,7 @@ type influxDBMetadata struct { organizationName string query string serverURL string + unsafeSsL bool thresholdValue float64 } @@ -41,7 +43,13 @@ func NewInfluxDBScaler(config *ScalerConfig) (Scaler, error) { } influxDBLog.Info("starting up influxdb client") - + // In case unsafeSsL is enabled. + if meta.unsafeSsL { + return &influxDBScaler{ + client: influxdb2.NewClientWithOptions(meta.serverURL, meta.authToken, influxdb2.DefaultOptions().SetTLSConfig(&tls.Config{InsecureSkipVerify: true})), + metadata: meta, + }, nil + } return &influxDBScaler{ client: influxdb2.NewClient(meta.serverURL, meta.authToken), metadata: meta, @@ -55,6 +63,7 @@ func parseInfluxDBMetadata(config *ScalerConfig) (*influxDBMetadata, error) { var organizationName string var query string var serverURL string + var unsafeSsL bool var thresholdValue float64 val, ok := config.TriggerMetadata["authToken"] @@ -127,6 +136,14 @@ func parseInfluxDBMetadata(config *ScalerConfig) (*influxDBMetadata, error) { } else { return nil, fmt.Errorf("no threshold value given") } + unsafeSsL = false + if val, ok := config.TriggerMetadata["unsafeSsL"]; ok { + parsedVal, err := strconv.ParseBool(val) + if err != nil { + return nil, fmt.Errorf("error parsing unsafeSsL: %s", err) + } + unsafeSsL = parsedVal + } return &influxDBMetadata{ authToken: authToken, @@ -135,6 +152,7 @@ func parseInfluxDBMetadata(config *ScalerConfig) (*influxDBMetadata, error) { query: query, serverURL: serverURL, thresholdValue: thresholdValue, + unsafeSsL: unsafeSsL, }, nil } diff --git a/pkg/scalers/influxdb_scaler_test.go b/pkg/scalers/influxdb_scaler_test.go index 7c1b3d62dcd..db83262183a 100644 --- a/pkg/scalers/influxdb_scaler_test.go +++ b/pkg/scalers/influxdb_scaler_test.go @@ -26,21 +26,23 @@ var testInfluxDBMetadata = []parseInfluxDBMetadataTestData{ // nothing passed {map[string]string{}, true, map[string]string{}}, // everything is passed in verbatim - {map[string]string{"serverURL": "https://influxdata.com", "metricName": "influx_metric", "organizationName": "influx_org", "query": "from(bucket: hello)", "thresholdValue": "10", "authToken": "myToken"}, false, map[string]string{}}, + {map[string]string{"serverURL": "https://influxdata.com", "metricName": "influx_metric", "organizationName": "influx_org", "query": "from(bucket: hello)", "thresholdValue": "10", "authToken": "myToken", "unsafeSsL": "false"}, false, map[string]string{}}, // everything is passed in (environment variables) - {map[string]string{"serverURL": "https://influxdata.com", "organizationNameFromEnv": "INFLUX_ORG", "query": "from(bucket: hello)", "thresholdValue": "10", "authTokenFromEnv": "INFLUX_TOKEN"}, false, map[string]string{}}, + {map[string]string{"serverURL": "https://influxdata.com", "organizationNameFromEnv": "INFLUX_ORG", "query": "from(bucket: hello)", "thresholdValue": "10", "authTokenFromEnv": "INFLUX_TOKEN", "unsafeSsL": "false"}, false, map[string]string{}}, // no serverURL passed - {map[string]string{"metricName": "influx_metric", "organizationName": "influx_org", "query": "from(bucket: hello)", "thresholdValue": "10", "authToken": "myToken"}, true, map[string]string{}}, + {map[string]string{"metricName": "influx_metric", "organizationName": "influx_org", "query": "from(bucket: hello)", "thresholdValue": "10", "authToken": "myToken", "unsafeSsL": "false"}, true, map[string]string{}}, // no organization name passed - {map[string]string{"serverURL": "https://influxdata.com", "metricName": "influx_metric", "query": "from(bucket: hello)", "thresholdValue": "10", "authToken": "myToken"}, true, map[string]string{}}, + {map[string]string{"serverURL": "https://influxdata.com", "metricName": "influx_metric", "query": "from(bucket: hello)", "thresholdValue": "10", "authToken": "myToken", "unsafeSsL": "false"}, true, map[string]string{}}, // no query passed - {map[string]string{"serverURL": "https://influxdata.com", "organizationName": "influx_org", "thresholdValue": "10", "authToken": "myToken"}, true, map[string]string{}}, + {map[string]string{"serverURL": "https://influxdata.com", "organizationName": "influx_org", "thresholdValue": "10", "authToken": "myToken", "unsafeSsL": "false"}, true, map[string]string{}}, // no threshold value passed - {map[string]string{"serverURL": "https://influxdata.com", "organizationName": "influx_org", "query": "from(bucket: hello)", "authToken": "myToken"}, true, map[string]string{}}, + {map[string]string{"serverURL": "https://influxdata.com", "organizationName": "influx_org", "query": "from(bucket: hello)", "authToken": "myToken", "unsafeSsL": "false"}, true, map[string]string{}}, // no auth token passed - {map[string]string{"serverURL": "https://influxdata.com", "organizationName": "influx_org", "query": "from(bucket: hello)", "thresholdValue": "10"}, true, map[string]string{}}, + {map[string]string{"serverURL": "https://influxdata.com", "organizationName": "influx_org", "query": "from(bucket: hello)", "thresholdValue": "10", "unsafeSsL": "false"}, true, map[string]string{}}, // authToken, organizationName, and serverURL are defined in authParams - {map[string]string{"query": "from(bucket: hello)", "thresholdValue": "10"}, false, map[string]string{"serverURL": "https://influxdata.com", "organizationName": "influx_org", "authToken": "myToken"}}, + {map[string]string{"query": "from(bucket: hello)", "thresholdValue": "10", "unsafeSsL": "false"}, false, map[string]string{"serverURL": "https://influxdata.com", "organizationName": "influx_org", "authToken": "myToken"}}, + // no sunsafeSsl value passed + {map[string]string{"serverURL": "https://influxdata.com", "metricName": "influx_metric", "organizationName": "influx_org", "query": "from(bucket: hello)", "thresholdValue": "10", "authToken": "myToken"}, false, map[string]string{}}, } var influxDBMetricIdentifiers = []influxDBMetricIdentifier{