feat: add multiple endpoints support for remote

This commit is contained in:
Astone 2022-11-14 14:09:00 +08:00 committed by Márk Sági-Kazár
parent a7ad8cfcc4
commit 0755477020

View file

@ -10,6 +10,7 @@ import (
"bytes" "bytes"
"io" "io"
"os" "os"
"strings"
crypt "github.com/sagikazarmark/crypt/config" crypt "github.com/sagikazarmark/crypt/config"
@ -75,6 +76,7 @@ func getConfigManager(rp viper.RemoteProvider) (crypt.ConfigManager, error) {
var cm crypt.ConfigManager var cm crypt.ConfigManager
var err error var err error
endpoints := strings.Split(rp.Endpoint(), ";")
if rp.SecretKeyring() != "" { if rp.SecretKeyring() != "" {
var kr *os.File var kr *os.File
kr, err = os.Open(rp.SecretKeyring()) kr, err = os.Open(rp.SecretKeyring())
@ -84,24 +86,24 @@ func getConfigManager(rp viper.RemoteProvider) (crypt.ConfigManager, error) {
defer kr.Close() defer kr.Close()
switch rp.Provider() { switch rp.Provider() {
case "etcd": case "etcd":
cm, err = crypt.NewEtcdConfigManager([]string{rp.Endpoint()}, kr) cm, err = crypt.NewEtcdConfigManager(endpoints, kr)
case "etcd3": case "etcd3":
cm, err = crypt.NewEtcdV3ConfigManager([]string{rp.Endpoint()}, kr) cm, err = crypt.NewEtcdV3ConfigManager(endpoints, kr)
case "firestore": case "firestore":
cm, err = crypt.NewFirestoreConfigManager([]string{rp.Endpoint()}, kr) cm, err = crypt.NewFirestoreConfigManager(endpoints, kr)
default: default:
cm, err = crypt.NewConsulConfigManager([]string{rp.Endpoint()}, kr) cm, err = crypt.NewConsulConfigManager(endpoints, kr)
} }
} else { } else {
switch rp.Provider() { switch rp.Provider() {
case "etcd": case "etcd":
cm, err = crypt.NewStandardEtcdConfigManager([]string{rp.Endpoint()}) cm, err = crypt.NewStandardEtcdConfigManager(endpoints)
case "etcd3": case "etcd3":
cm, err = crypt.NewStandardEtcdV3ConfigManager([]string{rp.Endpoint()}) cm, err = crypt.NewStandardEtcdV3ConfigManager(endpoints)
case "firestore": case "firestore":
cm, err = crypt.NewStandardFirestoreConfigManager([]string{rp.Endpoint()}) cm, err = crypt.NewStandardFirestoreConfigManager(endpoints)
default: default:
cm, err = crypt.NewStandardConsulConfigManager([]string{rp.Endpoint()}) cm, err = crypt.NewStandardConsulConfigManager(endpoints)
} }
} }
if err != nil { if err != nil {