From 58457d53c2731ccf27c3e3019e379d0e0b306170 Mon Sep 17 00:00:00 2001 From: Manendra Pal Singh Date: Fri, 9 Jan 2026 12:40:10 +0530 Subject: [PATCH 1/2] fix : add the tls support for the redis cache --- CONFIG.md | 11 +++++++++++ pkg/plugin/implementation/cache/cache.go | 12 +++++++++--- pkg/plugin/implementation/cache/cmd/plugin.go | 3 ++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CONFIG.md b/CONFIG.md index e4b72d8..e04a431 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -601,8 +601,19 @@ cache: addr: 10.81.192.4:6379 ``` +**Or with TLS enabled:** + +```yaml +cache: + id: cache + config: + addr: redis.example.com:6380 + use_tls: "true" +``` + **Parameters**: - `addr`: Redis server address and port +- `use_tls`: Enable TLS connection to Redis (`"true"` to enable, omit or any other value to disable). Default: disabled. --- diff --git a/pkg/plugin/implementation/cache/cache.go b/pkg/plugin/implementation/cache/cache.go index 1e38f96..c7c5a0c 100644 --- a/pkg/plugin/implementation/cache/cache.go +++ b/pkg/plugin/implementation/cache/cache.go @@ -2,6 +2,7 @@ package cache import ( "context" + "crypto/tls" "errors" "fmt" "os" @@ -31,7 +32,8 @@ type RedisClient interface { // Config holds the configuration required to connect to Redis. type Config struct { - Addr string + Addr string + UseTLS bool } // Cache wraps a Redis client to provide basic caching operations. @@ -62,11 +64,15 @@ func validate(cfg *Config) error { // RedisClientFunc is a function variable that creates a Redis client based on the provided configuration. // It can be overridden for testing purposes. var RedisClientFunc = func(cfg *Config) RedisClient { - return redis.NewClient(&redis.Options{ + opts := &redis.Options{ Addr: cfg.Addr, Password: os.Getenv("REDIS_PASSWORD"), DB: 0, - }) + } + if cfg.UseTLS { + opts.TLSConfig = &tls.Config{} + } + return redis.NewClient(opts) } // New initializes and returns a Cache instance along with a close function to release resources. diff --git a/pkg/plugin/implementation/cache/cmd/plugin.go b/pkg/plugin/implementation/cache/cmd/plugin.go index 5653495..0b33c0c 100644 --- a/pkg/plugin/implementation/cache/cmd/plugin.go +++ b/pkg/plugin/implementation/cache/cmd/plugin.go @@ -19,7 +19,8 @@ func (c cacheProvider) New(ctx context.Context, config map[string]string) (defin } // Create cache.Config directly from map - validation is handled by cache.New cacheConfig := &cache.Config{ - Addr: config["addr"], + Addr: config["addr"], + UseTLS: config["use_tls"] == "true", } log.Debugf(ctx, "Cache config mapped: %+v", cacheConfig) cache, closer, err := cache.New(ctx, cacheConfig) From f860ff820cb95de13b13c76e025c22f4973cd660 Mon Sep 17 00:00:00 2001 From: Manendra Pal Singh Date: Mon, 12 Jan 2026 16:44:29 +0530 Subject: [PATCH 2/2] add the valdation --- pkg/plugin/implementation/cache/cache.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/plugin/implementation/cache/cache.go b/pkg/plugin/implementation/cache/cache.go index c7c5a0c..fe91c17 100644 --- a/pkg/plugin/implementation/cache/cache.go +++ b/pkg/plugin/implementation/cache/cache.go @@ -48,6 +48,7 @@ var ( ErrAddrMissing = errors.New("missing required field 'Addr'") ErrCredentialMissing = errors.New("missing Redis credentials in environment") ErrConnectionFail = errors.New("failed to connect to Redis") + ErrInvalidUseTLS = errors.New("use_tls must be a boolean") ) // validate checks if the provided Redis configuration is valid. @@ -58,6 +59,11 @@ func validate(cfg *Config) error { if cfg.Addr == "" { return ErrAddrMissing } + + if cfg.UseTLS != true && cfg.UseTLS != false { + return ErrInvalidUseTLS + } + return nil }