From a090caf2c3c7442b2322d797937410b31e2e2c84 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Thu, 17 Dec 2015 12:48:13 +0100 Subject: [PATCH] Basic Auth support for Etcd. Fixes #859 --- physical/etcd.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/physical/etcd.go b/physical/etcd.go index 9c61aaecb..ecd76e825 100644 --- a/physical/etcd.go +++ b/physical/etcd.go @@ -4,6 +4,7 @@ import ( "encoding/base64" "errors" "net/url" + "os" "path/filepath" "strings" "sync" @@ -121,6 +122,22 @@ func newEtcdBackend(conf map[string]string) (Backend, error) { Transport: cTransport, } + // Set credentials. + username := os.Getenv("ETCD_USERNAME") + if username == "" { + username, _ = conf["username"] + } + + password := os.Getenv("ETCD_PASSWORD") + if password == "" { + password, _ = conf["password"] + } + + if username != "" && password != "" { + cfg.Username = username + cfg.Password = password + } + c, err := client.New(cfg) if err != nil { return nil, err