Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add simple TLS support in Go RedisOnlineStore #2860

Merged
merged 2 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}