Skip to content

Commit

Permalink
Add TLS option for Redis for the search index client
Browse files Browse the repository at this point in the history
  • Loading branch information
mihkelparna1 committed Feb 13, 2024
1 parent 191f24a commit 39a4ae0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/indexstorage/indexstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type IndexStorage interface {
func NewIndexStorage(providerType string) (IndexStorage, error) {
switch providerType {
case redis.ProviderType:
return redis.NewProvider(viper.GetString("redis_server.address"), viper.GetString("redis_server.port"), viper.GetString("redis_server.password"))
return redis.NewProvider(viper.GetString("redis_server.address"), viper.GetString("redis_server.port"), viper.GetString("redis_server.password"), viper.GetBool("redis_server.enable-tls"), viper.GetBool("redis_server.insecure-skip-verify"))
case mysql.ProviderType:
return mysql.NewProvider(viper.GetString("search_index.mysql.dsn"),
mysql.WithConnMaxIdleTime(viper.GetDuration("search_index.mysql.conn_max_idletime")),
Expand Down
10 changes: 9 additions & 1 deletion pkg/indexstorage/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package redis

import (
"context"
"crypto/tls"
"errors"
"fmt"
"strings"
Expand All @@ -30,14 +31,21 @@ type IndexStorageProvider struct {
client *redis.Client
}

func NewProvider(address, port, password string) (*IndexStorageProvider, error) {
func NewProvider(address, port, password string, enableTLS bool, insecureSkipVerify bool) (*IndexStorageProvider, error) {
provider := &IndexStorageProvider{}
provider.client = redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%v:%v", address, port),
Network: "tcp",
Password: password,
DB: 0, // default DB
})

// #nosec G402
if enableTLS {
provider.client.Options().TLSConfig = &tls.Config{
InsecureSkipVerify: insecureSkipVerify,
}
}
return provider, nil
}

Expand Down

0 comments on commit 39a4ae0

Please sign in to comment.