func getConfigManager(rp viper.RemoteProvider) (crypt.ConfigManager, error) { var cm crypt.ConfigManager var err error if rp.SecretKeyring() != "" { kr, err := os.Open(rp.SecretKeyring()) defer kr.Close() if err != nil { return nil, err } if rp.Provider() == "etcd" { cm, err = crypt.NewEtcdConfigManager([]string{rp.Endpoint()}, kr) } else { cm, err = crypt.NewConsulConfigManager([]string{rp.Endpoint()}, kr) } } else { if rp.Provider() == "etcd" { cm, err = crypt.NewStandardEtcdConfigManager([]string{rp.Endpoint()}) } else { cm, err = crypt.NewStandardConsulConfigManager([]string{rp.Endpoint()}) } } if err != nil { return nil, err } return cm, nil }
func (v *Viper) getRemoteConfig(provider *remoteProvider) (map[string]interface{}, error) { var cm crypt.ConfigManager var err error if provider.secretKeyring != "" { kr, err := os.Open(provider.secretKeyring) defer kr.Close() if err != nil { return nil, err } if provider.provider == "etcd" { cm, err = crypt.NewEtcdConfigManager([]string{provider.endpoint}, kr) } else { cm, err = crypt.NewConsulConfigManager([]string{provider.endpoint}, kr) } } else { if provider.provider == "etcd" { cm, err = crypt.NewStandardEtcdConfigManager([]string{provider.endpoint}) } else { cm, err = crypt.NewStandardConsulConfigManager([]string{provider.endpoint}) } } if err != nil { return nil, err } b, err := cm.Get(provider.path) if err != nil { return nil, err } reader := bytes.NewReader(b) v.marshalReader(reader, v.kvstore) return v.kvstore, err }
func (etc *etcd) Init() error { var err error if len(etc.Endpoints) == 0 { return e.New("no end points") } cfg := client.Config{ Endpoints: etc.Endpoints, //Transport: http.DefaultTransport, } c, err := client.New(cfg) if err != nil { return e.Forward(err) } etc.kapi = client.NewKeysAPI(c) if etc.SecKeyRing == "" { return nil } kr, err := os.Open(etc.SecKeyRing) if err != nil { return e.Forward(err) } defer kr.Close() etc.cm, err = config.NewEtcdConfigManager(etc.Endpoints, kr) if err != nil { return e.Forward(err) } return nil }