Skip to content

Commit

Permalink
feat: Add simple TLS support in Go RedisOnlineStore (#2860)
Browse files Browse the repository at this point in the history
* Add simple TLS support in RedisOnlineStore

Per the go-redis docs: 'To enable TLS/SSL, you need to provide an empty tls.Config.'
https://redis.uptrace.dev/guide/go-redis.html#using-tls

This will allow users to append ',ssl=True' to their connection string
in order to enable TLS/SSL support in the Redis client

Signed-off-by: William Horton <william.horton@grandrounds.com>

* Add tests of Redis config from connection string

Signed-off-by: William Horton <william.horton@grandrounds.com>
  • Loading branch information
wdhorton authored Jun 29, 2022
1 parent 2800e37 commit 521488d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 5 deletions.
17 changes: 12 additions & 5 deletions go/internal/feast/onlinestore/redisonlinestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package onlinestore

import (
"context"
"crypto/tls"
"encoding/binary"
"errors"
"fmt"
Expand Down Expand Up @@ -43,6 +44,7 @@ func NewRedisOnlineStore(project string, onlineStoreConfig map[string]interface{

var address []string
var password string
var tlsConfig *tls.Config
var db int // Default to 0

// Parse redis_type and write it into conf.t
Expand All @@ -69,8 +71,12 @@ func NewRedisOnlineStore(project string, onlineStoreConfig map[string]interface{
if kv[0] == "password" {
password = kv[1]
} else if kv[0] == "ssl" {
// TODO (woop): Add support for TLS/SSL
// ssl = kv[1] == "true"
result, err := strconv.ParseBool(kv[1])
if err != nil {
return nil, err
} else if result {
tlsConfig = &tls.Config{}
}
} else if kv[0] == "db" {
db, err = strconv.Atoi(kv[1])
if err != nil {
Expand All @@ -87,9 +93,10 @@ func NewRedisOnlineStore(project string, onlineStoreConfig map[string]interface{

if t == redisNode {
store.client = redis.NewClient(&redis.Options{
Addr: address[0],
Password: password, // No password set
DB: db,
Addr: address[0],
Password: password, // No password set
DB: db,
TLSConfig: tlsConfig,
})
} else {
return nil, errors.New("only single node Redis is supported at this time")
Expand Down
53 changes: 53 additions & 0 deletions go/internal/feast/onlinestore/redisonlinestore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package onlinestore

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestNewRedisOnlineStore(t *testing.T) {
var config = map[string]interface{}{
"connection_string": "redis://localhost:6379",
}
store, err := NewRedisOnlineStore("test", config)
assert.Nil(t, err)
var opts = store.client.Options()
assert.Equal(t, opts.Addr, "redis://localhost:6379")
assert.Equal(t, opts.Password, "")
assert.Equal(t, opts.DB, 0)
assert.Nil(t, opts.TLSConfig)
}

func TestNewRedisOnlineStoreWithPassword(t *testing.T) {
var config = map[string]interface{}{
"connection_string": "redis://localhost:6379,password=secret",
}
store, err := NewRedisOnlineStore("test", config)
assert.Nil(t, err)
var opts = store.client.Options()
assert.Equal(t, opts.Addr, "redis://localhost:6379")
assert.Equal(t, opts.Password, "secret")
}

func TestNewRedisOnlineStoreWithDB(t *testing.T) {
var config = map[string]interface{}{
"connection_string": "redis://localhost:6379,db=1",
}
store, err := NewRedisOnlineStore("test", config)
assert.Nil(t, err)
var opts = store.client.Options()
assert.Equal(t, opts.Addr, "redis://localhost:6379")
assert.Equal(t, opts.DB, 1)
}

func TestNewRedisOnlineStoreWithSsl(t *testing.T) {
var config = map[string]interface{}{
"connection_string": "redis://localhost:6379,ssl=true",
}
store, err := NewRedisOnlineStore("test", config)
assert.Nil(t, err)
var opts = store.client.Options()
assert.Equal(t, opts.Addr, "redis://localhost:6379")
assert.NotNil(t, opts.TLSConfig)
}

0 comments on commit 521488d

Please sign in to comment.