Skip to content

Commit

Permalink
Add TLS support for Redis connections (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertjndw authored Feb 7, 2024
1 parent eea0537 commit 534374a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
12 changes: 8 additions & 4 deletions HadesAPI/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"crypto/tls"
"fmt"
"os"

Expand Down Expand Up @@ -29,11 +30,14 @@ func main() {
var cfg HadesAPIConfig
utils.LoadConfig(&cfg)

asynq_client_opts := asynq.RedisClientOpt{Addr: cfg.RedisConfig.Addr, Password: cfg.RedisConfig.Pwd}
var err error
AsynqClient = asynq.NewClient(asynq_client_opts)
redis_opts := asynq.RedisClientOpt{Addr: cfg.RedisConfig.Addr, Password: cfg.RedisConfig.Pwd}
// Check whether TLS should be enabled
if cfg.RedisConfig.TLS_Enabled {
redis_opts.TLSConfig = &tls.Config{}
}
AsynqClient = asynq.NewClient(redis_opts)
if AsynqClient == nil {
log.WithError(err).Fatal("Failed to connect to Redis")
log.Fatal("Failed to connect to Redis")
return
}

Expand Down
13 changes: 9 additions & 4 deletions HadesScheduler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"crypto/tls"
"encoding/json"
"os"

Expand Down Expand Up @@ -37,8 +38,12 @@ func main() {
utils.LoadConfig(&executorCfg)
log.Debug("Executor config: ", executorCfg)

var err error
AsynqServer = asynq.NewServer(asynq.RedisClientOpt{Addr: cfg.RedisConfig.Addr}, asynq.Config{
redis_opts := asynq.RedisClientOpt{Addr: cfg.RedisConfig.Addr}
// Check whether TLS should be enabled
if cfg.RedisConfig.TLS_Enabled {
redis_opts.TLSConfig = &tls.Config{}
}
AsynqServer = asynq.NewServer(redis_opts, asynq.Config{
Concurrency: int(cfg.Concurrency),
Queues: map[string]int{
"critical": 5,
Expand All @@ -51,11 +56,11 @@ func main() {
Logger: log.StandardLogger(),
})
if AsynqServer == nil {
log.Panic(err)
log.Fatal("Failed to create Asynq server")
return
}

var scheduler JobScheduler

switch executorCfg.Executor {
// case "k8s":
// log.Info("Started HadesScheduler in Kubernetes mode")
Expand Down
5 changes: 3 additions & 2 deletions shared/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
)

type RedisConfig struct {
Addr string `env:"REDIS_ADDR,notEmpty" envDefault:"localhost:6379"`
Pwd string `env:"REDIS_PWD"`
Addr string `env:"REDIS_ADDR,notEmpty" envDefault:"localhost:6379"`
Pwd string `env:"REDIS_PWD"`
TLS_Enabled bool `env:"REDIS_TLS_ENABLED" envDefault:"false"`
}

type K8sConfig struct {
Expand Down

0 comments on commit 534374a

Please sign in to comment.