diff options
author | 2019-02-01 16:30:53 +0100 | |
---|---|---|
committer | 2019-02-01 15:30:53 +0000 | |
commit | d878eeebbb890b2b73226e2440c73e8b2d1b102e (patch) | |
tree | b8cc14a5834ac28eebc0c809d87e063f482c2c91 /plugin/etcd/setup.go | |
parent | b455f86824a1c2108b305589190e964b5528fed3 (diff) | |
download | coredns-d878eeebbb890b2b73226e2440c73e8b2d1b102e.tar.gz coredns-d878eeebbb890b2b73226e2440c73e8b2d1b102e.tar.zst coredns-d878eeebbb890b2b73226e2440c73e8b2d1b102e.zip |
support etcd credentials in etcd plugin (#2442)
* support etcd credentials in etcd plugin
fixes #2441
* try to fix cleanup of authentication
Diffstat (limited to 'plugin/etcd/setup.go')
-rw-r--r-- | plugin/etcd/setup.go | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/plugin/etcd/setup.go b/plugin/etcd/setup.go index 68d5f147d..d0cdbc705 100644 --- a/plugin/etcd/setup.go +++ b/plugin/etcd/setup.go @@ -48,6 +48,8 @@ func etcdParse(c *caddy.Controller) (*Etcd, error) { tlsConfig *tls.Config err error endpoints = []string{defaultEndpoint} + username string + password string ) for c.Next() { etc.Zones = c.RemainingArgs() @@ -89,6 +91,15 @@ func etcdParse(c *caddy.Controller) (*Etcd, error) { if err != nil { return &Etcd{}, err } + case "credentials": + args := c.RemainingArgs() + if len(args) == 0 { + return &Etcd{}, c.ArgErr() + } + if len(args) != 2 { + return &Etcd{}, c.Errf("credentials requires 2 arguments, username and password") + } + username, password = args[0], args[1] default: if c.Val() != "}" { return &Etcd{}, c.Errf("unknown property '%s'", c.Val()) @@ -101,7 +112,7 @@ func etcdParse(c *caddy.Controller) (*Etcd, error) { } } - client, err := newEtcdClient(endpoints, tlsConfig) + client, err := newEtcdClient(endpoints, tlsConfig, username, password) if err != nil { return &Etcd{}, err } @@ -113,11 +124,15 @@ func etcdParse(c *caddy.Controller) (*Etcd, error) { return &Etcd{}, nil } -func newEtcdClient(endpoints []string, cc *tls.Config) (*etcdcv3.Client, error) { +func newEtcdClient(endpoints []string, cc *tls.Config, username, password string) (*etcdcv3.Client, error) { etcdCfg := etcdcv3.Config{ Endpoints: endpoints, TLS: cc, } + if username != "" && password != "" { + etcdCfg.Username = username + etcdCfg.Password = password + } cli, err := etcdcv3.New(etcdCfg) if err != nil { return nil, err |