Skip to content

Commit 086d3c3

Browse files
authored
Merge pull request #7 from MinerYang/topic/yminer/support-redis-acl
support redis acl
2 parents 0c62ec3 + a9c58f1 commit 086d3c3

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

configuration/configuration.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ type Configuration struct {
174174
// Password string to use when making a connection.
175175
Password string `yaml:"password,omitempty"`
176176

177+
// Username string to use when making a connection.
178+
Username string `yaml:"username,omitempty"`
179+
177180
// DB specifies the database to connect to on the redis instance.
178181
DB int `yaml:"db,omitempty"`
179182

registry/handlers/app.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,15 @@ func (app *App) configureRedis(configuration *configuration.Configuration) {
582582
}
583583

584584
// authorize the connection
585-
if configuration.Redis.Password != "" {
586-
if _, err = conn.Do("AUTH", configuration.Redis.Password); err != nil {
585+
username := configuration.Redis.Username
586+
password := configuration.Redis.Password
587+
if password != "" {
588+
authArgs := make([]interface{}, 0, 2)
589+
if username != "" {
590+
authArgs = append(authArgs, username)
591+
}
592+
authArgs = append(authArgs, password)
593+
if _, err = conn.Do("AUTH", authArgs...); err != nil {
587594
defer conn.Close()
588595
done(err)
589596
return nil, err

registry/handlers/app_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,31 @@ func TestNewAppWithRedisTLSSentinelCluster(t *testing.T) {
235235
runAppWithConfig(t, config)
236236
}
237237

238+
func TestNewAppWithRedisSentinelACL(t *testing.T) {
239+
config := configuration.Configuration{
240+
Storage: configuration.Storage{
241+
"testdriver": nil,
242+
"maintenance": configuration.Parameters{"uploadpurging": map[interface{}]interface{}{
243+
"enabled": false,
244+
}},
245+
},
246+
Auth: configuration.Auth{
247+
// For now, we simply test that new auth results in a viable
248+
// application.
249+
"silly": {
250+
"realm": "realm-test",
251+
"service": "service-test",
252+
},
253+
},
254+
}
255+
config.Redis.Addr = "192.168.0.11:30013,192.168.0.12:30014,192.168.0.12:30015"
256+
config.Redis.DB = 0
257+
config.Redis.SentinelMasterSet = "mymaster"
258+
config.Redis.Username = "foo"
259+
config.Redis.Password = "mypwd"
260+
runAppWithConfig(t, config)
261+
}
262+
238263
func runAppWithConfig(t *testing.T, config configuration.Configuration) {
239264
ctx := context.Background()
240265
// Mostly, with this test, given a sane configuration, we are simply

0 commit comments

Comments
 (0)