Skip to content

Commit

Permalink
meta/redis: redis support certFile and keyFile (#3388)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijian-pro authored Mar 27, 2023
1 parent bad06db commit 75643f7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/meta/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package meta
import (
"bufio"
"context"
"crypto/tls"
"encoding/binary"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -110,6 +111,8 @@ func newRedisMeta(driver, addr string, conf *Config) (Meta, error) {
writeTimeout := query.duration("write-timeout", "write_timeout", time.Second*5)
routeRead := query.pop("route-read")
skipVerify := query.pop("insecure-skip-verify")
certFile := query.pop("tls-cert-file")
keyFile := query.pop("tls-key-file")
u.RawQuery = values.Encode()

hosts := u.Host
Expand All @@ -120,6 +123,13 @@ func newRedisMeta(driver, addr string, conf *Config) (Meta, error) {
if opt.TLSConfig != nil {
opt.TLSConfig.ServerName = "" // use the host of each connection as ServerName
opt.TLSConfig.InsecureSkipVerify = skipVerify != ""
if certFile != "" {
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
if err != nil {
return nil, fmt.Errorf("get certificate error certFile:%s keyFile:%s error:%s", certFile, keyFile, err)
}
opt.TLSConfig.Certificates = []tls.Certificate{cert}
}
}
if opt.Password == "" {
opt.Password = os.Getenv("REDIS_PASSWORD")
Expand Down

0 comments on commit 75643f7

Please sign in to comment.