From e0cc1ce67998590fb0d4684bf3503b662aa15835 Mon Sep 17 00:00:00 2001 From: Illirgway Date: Wed, 16 Aug 2017 01:51:18 +0300 Subject: [PATCH] Fix bug with unused (replaced with "") CONSUL_HTTP_AUTH in some places example: https://github.com/hashicorp/consul/blob/master/watch/plan.go#L26 conf := consulapi.DefaultConfig() conf.Address = address conf.Datacenter = p.Datacenter conf.Token = p.Token # <-- replace Token from DefaultConfig/CONSUL_HTTP_AUTH with "" client, err := consulapi.NewClient(conf) how to reproduce bug: 0. consul -> localhost:8500 with more than 0 service checks 1. deny all for anonymous token 2. create appropriate acl for watch checks (agent:read + node:read,service:read) 3. bash: CONSUL_HTTP_AUTH= consul watch -http-addr=localhost:8500 -type=checks # --> return [] consul watch -http-addr=localhost:8500 -type=checks -token= # -> return { .... right json result .... } --- api/api.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/api.go b/api/api.go index 0a62b4f68d..78d2091d27 100644 --- a/api/api.go +++ b/api/api.go @@ -462,6 +462,10 @@ func NewClient(config *Config) (*Client, error) { config.Address = parts[1] } + if config.Token == "" { + config.Token = defConfig.Token + } + client := &Client{ config: *config, }