Skip to content

Commit

Permalink
Add Username and Password for Selenium Grid Basic Auth (kedacore#6142)
Browse files Browse the repository at this point in the history
* Add Username and Password for Selenium Grid Basic Auth

Signed-off-by: Vei0vis <[email protected]>

* Update CHANGELOG.md

Signed-off-by: Vei0vis <[email protected]>

---------

Signed-off-by: Vei0vis <[email protected]>
Co-authored-by: Vei0vis <[email protected]>
  • Loading branch information
Vei0vis and Vei0vis authored Oct 6, 2024
1 parent 1b5533e commit c4f02d5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions pkg/scalers/selenium_grid_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions pkg/scalers/selenium_grid_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit c4f02d5

Please sign in to comment.