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