Skip to content
This repository was archived by the owner on Mar 16, 2021. It is now read-only.

Commit 7461418

Browse files
committed
2 parents 5e6804c + 14cfeb3 commit 7461418

File tree

6 files changed

+44
-16
lines changed

6 files changed

+44
-16
lines changed

LICENSE.md renamed to LICENSE

File renamed without changes.

build/config.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
ListenAddr: ':8080' # Consists of 'IP:Port', e.g. ':8080' listens on any IP and on Port 8080
22
BaseURL: 'http://localhost:3000' # Origin URL, required for the authentication via OAuth
33
Backend: boltdb # Can be 'boltdb' or 'redis'
4-
RedisHost: localhost:6379 # If using the redis backend, a host:port combination
5-
RedisPassword: replace me # if using the redis backend, a conneciton password.
64
DataDir: ./data # Contains: the database and the private key
75
EnableDebugMode: true # Activates more detailed logging
86
EnableAccessLogs: true # Enable GIN access logs (default is true; set to false to disable access logging)
@@ -22,3 +20,10 @@ Proxy: # only relevant when using the proxy authbackend
2220
RequireUserHeader: false # If true, will reject connections that do not have the UserHeader set
2321
UserHeader: "X-Goog-Authenticated-User-ID" # pull the unique user ID from this header
2422
DisplayNameHeader: "X-Goog-Authenticated-User-Email" # pull the display naem from this header
23+
Redis:
24+
Host: localhost:6379 # host:port combination; required
25+
Password: replace me # redis connection password; optional; default is none
26+
Db: 0 # redis index (https://redis.io/commands/select); optional; default is 0
27+
MaxRetries: 3 # maximum number of retries for a failed redis command
28+
ReadTimeout: 3s # timeout for read operations; default is 3s. This is a golang time.ParseDuration string
29+
WriteTimeout: 3s # timeout for write operations; default is 3s. This is a golang time.ParseDuration string

renovate.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

stores/redis/redis.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,26 @@ type Store struct {
2424
}
2525

2626
// New initializes connection to the redis instance.
27-
func New(hostaddr, password string) (*Store, error) {
27+
func New(hostaddr, password string, db int, maxRetries int, readTimeout string, writeTimeout string) (*Store, error) {
28+
var rt, wt time.Duration
29+
var err error
30+
31+
if rt, err = time.ParseDuration(readTimeout); err != nil {
32+
return nil, errors.Wrap(err, "Could not parse read timeout")
33+
}
34+
if wt, err = time.ParseDuration(writeTimeout); err != nil {
35+
return nil, errors.Wrap(err, "Could not parse write timeout")
36+
}
2837
c := redis.NewClient(&redis.Options{
29-
Addr: hostaddr,
30-
Password: password,
31-
DB: 0,
38+
Addr: hostaddr,
39+
Password: password,
40+
DB: db,
41+
MaxRetries: maxRetries,
42+
ReadTimeout: rt,
43+
WriteTimeout: wt,
3244
})
3345
// if we can't talk to redis, fail fast
34-
_, err := c.Ping().Result()
35-
if err != nil {
46+
if _, err = c.Ping().Result(); err != nil {
3647
return nil, errors.Wrap(err, "Could not connect to redis db0")
3748
}
3849
ret := &Store{c: c}

stores/store.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ func New() (*Store, error) {
4343
var s shared.Storage
4444
switch backend := util.GetConfig().Backend; backend {
4545
case "redis":
46-
s, err = redis.New(util.GetConfig().RedisHost, util.GetConfig().RedisPassword)
46+
conf := util.GetConfig().Redis
47+
s, err = redis.New(conf.Host, conf.Password, conf.DB,
48+
conf.MaxRetries, conf.ReadTimeout,
49+
conf.WriteTimeout)
4750
case "boltdb":
4851
s, err = boltdb.New(filepath.Join(util.GetConfig().DataDir, "main.db"))
4952
default:

util/config.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ type Configuration struct {
1818
BaseURL string `yaml:"BaseURL" env:"BASE_URL"`
1919
DataDir string `yaml:"DataDir" env:"DATA_DIR"`
2020
Backend string `yaml:"Backend" env:"BACKEND"`
21-
RedisHost string `yaml:"RedisHost" env:"REDIS_HOST"`
22-
RedisPassword string `yaml:"RedisPassword" env:"REDIS_PASSWORD"`
2321
AuthBackend string `yaml:"AuthBackend" env:"AUTH_BACKEND"`
2422
UseSSL bool `yaml:"EnableSSL" env:"USE_SSL"`
2523
EnableDebugMode bool `yaml:"EnableDebugMode" env:"ENABLE_DEBUG_MODE"`
@@ -30,6 +28,16 @@ type Configuration struct {
3028
GitHub oAuthConf `yaml:"GitHub" env:"GITHUB"`
3129
Microsoft oAuthConf `yaml:"Microsoft" env:"MICROSOFT"`
3230
Proxy proxyAuthConf `yaml:"Proxy" env:"PROXY"`
31+
Redis redisConf `yaml:"Redis" env:"REDIS"`
32+
}
33+
34+
type redisConf struct {
35+
Host string `yaml:"Host" env:"REDIS_HOST"`
36+
Password string `yaml:"Password" env:"REDIS_PASSWORD"`
37+
DB int `yaml:"DB" env:"REDIS_DB"`
38+
MaxRetries int `yaml:"MaxRetries" env:"REDIS_MAX_RETRIES"`
39+
ReadTimeout string `yaml:"ReadTimeout" env:"REDIS_READ_TIMEOUT"`
40+
WriteTimeout string `yaml:"WriteTimeout" env:"REDIS_WRITE_TIMEOUT"`
3341
}
3442

3543
type oAuthConf struct {
@@ -55,6 +63,12 @@ var Config = Configuration{
5563
UseSSL: false,
5664
ShortedIDLength: 4,
5765
AuthBackend: "oauth",
66+
Redis: redisConf{
67+
Host: "127.0.0.1:6379",
68+
MaxRetries: 3,
69+
ReadTimeout: "3s",
70+
WriteTimeout: "3s",
71+
},
5872
}
5973

6074
// ReadInConfig loads the Configuration and other needed folders for further usage

0 commit comments

Comments
 (0)