command/debug: use the correct env vars for Consul token (#8332)

This commit is contained in:
Lang Martin
2020-07-02 10:04:22 -04:00
committed by GitHub
parent bde973e366
commit 3a1cdac25e

View File

@@ -78,7 +78,8 @@ Debug Options:
in the current directory.
-consul-token
Token used to query Consul. Defaults to CONSUL_TOKEN
Token used to query Consul. Defaults to CONSUL_HTTP_TOKEN or the contents of
CONSUL_HTTP_TOKEN_FILE
-vault-token
Token used to query Vault. Defaults to VAULT_TOKEN
@@ -514,7 +515,19 @@ func (c *DebugCommand) collectConsul(dir, consul string) error {
token := c.consulToken
if token == "" {
os.Getenv("CONSUL_TOKEN")
token = os.Getenv("CONSUL_HTTP_TOKEN")
}
if token == "" {
file := os.Getenv("CONSUL_HTTP_TOKEN_FILE")
if file != "" {
fh, err := os.Open(file)
if err == nil {
bs, err := ioutil.ReadAll(fh)
if err == nil {
token = strings.TrimSpace(string(bs))
}
}
}
}
client := http.Client{