From c4f02d5fbb95ab6affcc0cf4236d193cd5a84ff0 Mon Sep 17 00:00:00 2001 From: Vei0vis <101354315+Vei0vis@users.noreply.github.com> Date: Sun, 6 Oct 2024 23:56:25 +0200 Subject: [PATCH] Add Username and Password for Selenium Grid Basic Auth (#6142) * Add Username and Password for Selenium Grid Basic Auth Signed-off-by: Vei0vis * Update CHANGELOG.md Signed-off-by: Vei0vis --------- Signed-off-by: Vei0vis Co-authored-by: Vei0vis --- CHANGELOG.md | 1 + pkg/scalers/selenium_grid_scaler.go | 7 ++++++ pkg/scalers/selenium_grid_scaler_test.go | 27 ++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 989302b24b0..2790b3ae0ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,6 +75,7 @@ Here is an overview of all new **experimental** features: - **Grafana dashboard**: Fix dashboard to handle wildcard scaledObject variables ([#6214](https://github.com/kedacore/keda/issues/6214)) - **Kafka**: Fix logic to scale to zero on invalid offset even with earliest offsetResetPolicy ([#5689](https://github.com/kedacore/keda/issues/5689)) - **RabbitMQ Scaler**: Add connection name for AMQP ([#5958](https://github.com/kedacore/keda/issues/5958)) +- **Selenium Scaler**: Add Support for Username and Password Authentication ([#6144](https://github.com/kedacore/keda/issues/6144)) - TODO ([#XXX](https://github.com/kedacore/keda/issues/XXX)) ### Fixes diff --git a/pkg/scalers/selenium_grid_scaler.go b/pkg/scalers/selenium_grid_scaler.go index 4e1f75667ad..09f0adfd319 100644 --- a/pkg/scalers/selenium_grid_scaler.go +++ b/pkg/scalers/selenium_grid_scaler.go @@ -37,6 +37,10 @@ type seleniumGridScalerMetadata struct { UnsafeSsl bool `keda:"name=unsafeSsl, order=triggerMetadata, optional, default=false"` PlatformName string `keda:"name=platformName, order=triggerMetadata, optional, default=linux"` + // auth + Username string `keda:"name=username, order=authParams;resolvedEnv;triggerMetadata, optional"` + Password string `keda:"name=password, order=authParams;resolvedEnv;triggerMetadata, optional"` + TargetValue int64 } @@ -164,6 +168,9 @@ func (s *seleniumGridScaler) getSessionsCount(ctx context.Context, logger logr.L return -1, err } + // Add HTTP Auth + req.SetBasicAuth(s.metadata.Username, s.metadata.Password) + res, err := s.httpClient.Do(req) if err != nil { return -1, err diff --git a/pkg/scalers/selenium_grid_scaler_test.go b/pkg/scalers/selenium_grid_scaler_test.go index 95e24743c1e..557861b357e 100644 --- a/pkg/scalers/selenium_grid_scaler_test.go +++ b/pkg/scalers/selenium_grid_scaler_test.go @@ -610,6 +610,33 @@ func Test_parseSeleniumGridScalerMetadata(t *testing.T) { PlatformName: "linux", }, }, + { + name: "valid username and password in AuthParams, url, browsername, and sessionbrowsername should return metadata", + args: args{ + config: &scalersconfig.ScalerConfig{ + AuthParams: map[string]string{ + "username": "username", + "password": "password", + }, + TriggerMetadata: map[string]string{ + "url": "http://selenium-hub:4444/graphql", + "browserName": "MicrosoftEdge", + "sessionBrowserName": "msedge", + }, + }, + }, + wantErr: false, + want: &seleniumGridScalerMetadata{ + URL: "http://selenium-hub:4444/graphql", + BrowserName: "MicrosoftEdge", + SessionBrowserName: "msedge", + TargetValue: 1, + BrowserVersion: "latest", + PlatformName: "linux", + Username: "username", + Password: "password", + }, + }, { name: "valid url and browsername should return metadata", args: args{