-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metricbeat/module/redis: Add TLS and username support for Redis module (
- Loading branch information
Showing
11 changed files
with
239 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package redis | ||
|
||
import ( | ||
"crypto/tls" | ||
"time" | ||
|
||
"github.com/elastic/elastic-agent-libs/transport/tlscommon" | ||
) | ||
|
||
type Config struct { | ||
IdleTimeout time.Duration `config:"idle_timeout"` | ||
Network string `config:"network"` | ||
MaxConn int `config:"maxconn" validate:"min=1"` | ||
TLS *tlscommon.Config `config:"ssl"` | ||
|
||
UseTLSConfig *tls.Config | ||
} | ||
|
||
// DefaultConfig return default config for the redis module. | ||
func DefaultConfig() Config { | ||
return Config{Network: "tcp", MaxConn: 10} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,57 +31,80 @@ func TestGetPasswordDBNumber(t *testing.T) { | |
cases := []struct { | ||
title string | ||
hostData mb.HostData | ||
expectedUser string | ||
expectedPassword string | ||
expectedDatabase int | ||
}{ | ||
{ | ||
"test redis://127.0.0.1:6379 without password", | ||
mb.HostData{URI: "redis://127.0.0.1:6379", Password: ""}, | ||
"", | ||
"", | ||
0, | ||
}, | ||
{ | ||
"test redis uri with password in URI user info field", | ||
"test redis URI with password in userinfo", | ||
mb.HostData{URI: "redis://:[email protected]:6379", Password: "password"}, | ||
"", | ||
"password", | ||
0, | ||
}, | ||
{ | ||
"test redis uri with password in query field", | ||
"test redis URI with password in query parameter", | ||
mb.HostData{URI: "redis://127.0.0.1:6379?password=test", Password: ""}, | ||
"", | ||
"test", | ||
0, | ||
}, | ||
{ | ||
"test redis uri with password and db in query field", | ||
"test redis URI with password and db in query parameter", | ||
mb.HostData{URI: "redis://127.0.0.1:6379?password=test&db=1", Password: ""}, | ||
"", | ||
"test", | ||
1, | ||
}, | ||
{ | ||
"test redis uri with password in URI user info field and query field", | ||
"test redis URI with password in userinfo and URI's query parameter", | ||
mb.HostData{URI: "redis://:[email protected]:6379?password=password2", Password: "password1"}, | ||
"", | ||
"password2", | ||
0, | ||
}, | ||
{ | ||
"test redis uri with db number in URI", | ||
"test redis URI with db number in URI's query parameter and password in userinfo", | ||
mb.HostData{URI: "redis://:[email protected]:6379/1", Password: "password1"}, | ||
"", | ||
"password1", | ||
1, | ||
}, | ||
{ | ||
"test redis uri with db number in URI and query field", | ||
"test redis URI with db number and password in URI's query parameter and password in userinfo", | ||
mb.HostData{URI: "redis://:[email protected]:6379/1?password=password2&db=2", Password: "password1"}, | ||
"", | ||
"password2", | ||
2, | ||
}, | ||
{ | ||
"test redis URI with db number, user and password in URI's query parameter and password in userinfo", | ||
mb.HostData{URI: "redis://antirez:[email protected]:6379/1?password=password2&db=2", User: "antirez", Password: "password1"}, | ||
"antirez", | ||
"password2", | ||
2, | ||
}, | ||
{ | ||
"test redis URI with db number, user & password in URI's query parameter and user & password in userinfo", | ||
mb.HostData{URI: "redis://antirez:[email protected]:6379/1?username=salvatore&password=password2&db=2", User: "antirez", Password: "password1"}, | ||
"salvatore", | ||
"password2", | ||
2, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.title, func(t *testing.T) { | ||
password, database, err := getPasswordDBNumber(c.hostData) | ||
username, password, database, err := getUsernamePasswordDBNumber(c.hostData) | ||
assert.NoError(t, err) | ||
assert.Equal(t, c.expectedUser, username) | ||
assert.Equal(t, c.expectedPassword, password) | ||
assert.Equal(t, c.expectedDatabase, database) | ||
}) | ||
|
Oops, something went wrong.