Skip to content

Commit 1335e41

Browse files
committed
Use go-redis UniversalOptions/Client for simpler config
This implicitly adds support for redis sentinel HA configuration
1 parent 38e7252 commit 1335e41

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

Diff for: auth_server/authn/tokendb_redis.go

+2-10
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ import (
3030
)
3131

3232
type RedisStoreConfig struct {
33-
ClientOptions *redis.Options `yaml:"redis_options,omitempty"`
34-
ClusterOptions *redis.ClusterOptions `yaml:"redis_cluster_options,omitempty"`
33+
ClientOptions *redis.UniversalOptions `yaml:"redis_options,omitempty"`
3534
TokenHashCost int `yaml:"token_hash_cost,omitempty"`
3635
}
3736

@@ -45,14 +44,7 @@ type RedisClient interface {
4544
//
4645
func NewRedisTokenDB(options *RedisStoreConfig) (TokenDB, error) {
4746
var client RedisClient
48-
if options.ClusterOptions != nil {
49-
if options.ClientOptions != nil {
50-
glog.Infof("Both redis_token_db.configs and redis_token_db.cluster_configs have been set. Only the latter will be used")
51-
}
52-
client = redis.NewClusterClient(options.ClusterOptions)
53-
} else {
54-
client = redis.NewClient(options.ClientOptions)
55-
}
47+
client = redis.NewUniversalClient(options.ClientOptions)
5648
tokenHashCost := options.TokenHashCost
5749
if tokenHashCost <= 0 {
5850
tokenHashCost = bcrypt.DefaultCost

Diff for: auth_server/server/config.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func validate(c *Config) error {
201201
return errors.New("google_auth.{client_id,client_secret,gcs_token_db{bucket,client_secret_file}} are required")
202202
}
203203

204-
if gac.ClientId == "" || gac.ClientSecret == "" || (gac.RedisTokenDB != nil && gac.RedisTokenDB.ClientOptions == nil && gac.RedisTokenDB.ClusterOptions == nil) {
204+
if gac.ClientId == "" || gac.ClientSecret == "" || (gac.RedisTokenDB != nil && gac.RedisTokenDB.ClientOptions == nil) {
205205
return errors.New("google_auth.{client_id,client_secret,redis_token_db.{redis_options,redis_cluster_options}} are required")
206206
}
207207

@@ -225,7 +225,7 @@ func validate(c *Config) error {
225225
return errors.New("github_auth.{client_id,client_secret,gcs_token_db{bucket,client_secret_file}} are required")
226226
}
227227

228-
if ghac.ClientId == "" || ghac.ClientSecret == "" || (ghac.RedisTokenDB != nil && ghac.RedisTokenDB.ClientOptions == nil && ghac.RedisTokenDB.ClusterOptions == nil) {
228+
if ghac.ClientId == "" || ghac.ClientSecret == "" || (ghac.RedisTokenDB != nil && ghac.RedisTokenDB.ClientOptions == nil) {
229229
return errors.New("github_auth.{client_id,client_secret,redis_token_db.{redis_options,redis_cluster_options}} are required")
230230
}
231231

@@ -253,7 +253,7 @@ func validate(c *Config) error {
253253
return errors.New("oidc_auth.{client_id,client_secret,gcs_token_db{bucket,client_secret_file}} are required")
254254
}
255255

256-
if oidc.ClientId == "" || oidc.ClientSecret == "" || (oidc.RedisTokenDB != nil && oidc.RedisTokenDB.ClientOptions == nil && oidc.RedisTokenDB.ClusterOptions == nil) {
256+
if oidc.ClientId == "" || oidc.ClientSecret == "" || (oidc.RedisTokenDB != nil && oidc.RedisTokenDB.ClientOptions == nil) {
257257
return errors.New("oidc_auth.{client_id,client_secret,redis_token_db.{redis_options,redis_cluster_options}} are required")
258258
}
259259

@@ -283,7 +283,7 @@ func validate(c *Config) error {
283283
return errors.New("gitlab_auth.{client_id,client_secret,gcs_token_db{bucket,client_secret_file}} are required")
284284
}
285285

286-
if glab.ClientId == "" || glab.ClientSecret == "" || (glab.RedisTokenDB != nil && glab.RedisTokenDB.ClientOptions == nil && glab.RedisTokenDB.ClusterOptions == nil) {
286+
if glab.ClientId == "" || glab.ClientSecret == "" || (glab.RedisTokenDB != nil && glab.RedisTokenDB.ClientOptions == nil) {
287287
return errors.New("gitlab_auth.{client_id,client_secret,redis_token_db.{redis_options,redis_cluster_options}} are required")
288288
}
289289

Diff for: examples/reference.yml

+12-8
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,13 @@ github_auth:
144144
# or Redis,
145145
redis_token_db:
146146
redis_options:
147-
# with a single instance,
148-
addr: localhost:6379
149-
redis_cluster_options:
150-
# or in the cluster mode.
151-
addrs: ["localhost:7000"]
147+
# with a single instance,
148+
addrs: ["localhost:6379"]
149+
# or in the cluster mode.
150+
addrs: ["localhost:7000", "localhost:7001"]
151+
# or in the failover mode with redis sentinel.
152+
mastername: redis-ha
153+
addrs: ["redis-sentinel:26379"]
152154
# How long to wait when talking to GitHub servers. Optional.
153155
http_timeout: "10s"
154156
# How long to wait before revalidating the GitHub token. Optional.
@@ -220,10 +222,12 @@ gitlab_auth:
220222
redis_token_db:
221223
redis_options:
222224
# with a single instance,
223-
addr: localhost:6379
224-
redis_cluster_options:
225+
addrs: ["localhost:6379"]
225226
# or in the cluster mode.
226-
addrs: ["localhost:7000"]
227+
addrs: ["localhost:7000", "localhost:7001"]
228+
# or in the failover mode with redis sentinel.
229+
mastername: redis-ha
230+
addrs: ["redis-sentinel:26379"]
227231
# How long to wait when talking to GitLab servers. Optional.
228232
http_timeout: "10s"
229233
# How long to wait before revalidating the Gitlab token. Optional.

0 commit comments

Comments
 (0)