From 57f4b1dd2fdf29c0ca8a2723f5ec8e18fc4b8f62 Mon Sep 17 00:00:00 2001 From: Rafael Sierra Date: Mon, 10 Sep 2018 17:48:25 +0200 Subject: [PATCH] Added Token support for Consul Consul allows Tokens to be used when getting KVs, they are used to provide granullar access to KVs (and improve security overall as your Consul server will not be open to the world) --- backends/client.go | 1 + backends/consul/client.go | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/backends/client.go b/backends/client.go index 1e1bff119..a598ed49e 100644 --- a/backends/client.go +++ b/backends/client.go @@ -47,6 +47,7 @@ func New(config Config) (StoreClient, error) { config.BasicAuth, config.Username, config.Password, + config.AuthToken, ) case "etcd": // Create the etcd client upfront and use it for the life of the process. diff --git a/backends/consul/client.go b/backends/consul/client.go index c6ed090a5..d926bbb73 100644 --- a/backends/consul/client.go +++ b/backends/consul/client.go @@ -13,7 +13,7 @@ type ConsulClient struct { } // NewConsulClient returns a new client to Consul for the given address -func New(nodes []string, scheme, cert, key, caCert string, basicAuth bool, username string, password string) (*ConsulClient, error) { +func New(nodes []string, scheme, cert, key, caCert string, basicAuth bool, username string, password string, authToken string) (*ConsulClient, error) { conf := api.DefaultConfig() conf.Scheme = scheme @@ -36,6 +36,9 @@ func New(nodes []string, scheme, cert, key, caCert string, basicAuth bool, usern if caCert != "" { conf.TLSConfig.CAFile = caCert } + if authToken != "" { + conf.Token = authToken + } client, err := api.NewClient(conf) if err != nil {