spf13 / viper

Go configuration with fangs
MIT License
26.26k stars 2k forks source link

Support etcd auth(username and password) #1873

Open ahuigo opened 5 days ago

ahuigo commented 5 days ago

Preflight Checklist

Problem Description

Viper doesn't support etcd auth.

Proposed Solution

  1. Merge this PR: https://github.com/sagikazarmark/crypt/pull/306
  2. In order to be compatible with the existing viper, how about putting the auth information in the endpoint? like this??
// old /remote/remote.go
case "etcd3":
    cm, err = crypt.NewStandardEtcdV3ConfigManager([]string{rp.Endpoint()})
// new
case "etcd3":
    var username,password string
    endpoint := rp.Endpoint() //"user:password@127.0.0.1:2379"
    eparts := strings.SplitN(endpoint, "@",2)
    if len(eparts) == 2{
        endpoint = eparts[1]
         userpass := strings.SplitN(eparts[0],":",2)
         username = userpass[0]
         password = userpass[1]
    }
    cm, err = crypt.NewStandardEtcdV3ConfigManagerRaw(goetcdv3.Config{
        Endpoints: []string(endpoint),
        Username: username,
        Password: password,
    })

Alternatives Considered

Add a new remote provider for etcd :

etcdConfig:= goetcdv3.Config{
    Endpoints: "127.0.0.1:2379"
    Username: "username",
    Password: "password",
}
viper.AddEtcd3RemoteProvider(etcdConfig, "/path")

Additional Information

No response

github-actions[bot] commented 5 days ago

👋 Thanks for reporting!

A maintainer will take a look at your issue shortly. 👀

In the meantime: We are working on Viper v2 and we would love to hear your thoughts about what you like or don't like about Viper, so we can improve or fix those issues.

⏰ If you have a couple minutes, please take some time and share your thoughts: https://forms.gle/R6faU74qPRPAzchZ9

📣 If you've already given us your feedback, you can still help by spreading the news, either by sharing the above link or telling people about this on Twitter:

https://twitter.com/sagikazarmark/status/1306904078967074816

Thank you! ❤️