Allow prefixing -http-addr with http/https schemes

This commit is contained in:
Kyle Havlovitz 2017-02-10 18:08:39 -05:00
parent 0a7c092326
commit a7a6ee9f4c
No known key found for this signature in database
GPG Key ID: 8A5E6B173056AD6C
2 changed files with 14 additions and 8 deletions

View File

@ -346,13 +346,18 @@ func NewClient(config *Config) (*Client, error) {
config.HttpClient = defConfig.HttpClient config.HttpClient = defConfig.HttpClient
} }
if parts := strings.SplitN(config.Address, "unix://", 2); len(parts) == 2 { parts := strings.SplitN(config.Address, "://", 2)
trans := cleanhttp.DefaultTransport() if len(parts) == 2 {
trans.Dial = func(_, _ string) (net.Conn, error) { if parts[0] == "https" {
return net.Dial("unix", parts[1]) config.Scheme = "https"
} } else if parts[0] == "unix" {
config.HttpClient = &http.Client{ trans := cleanhttp.DefaultTransport()
Transport: trans, trans.Dial = func(_, _ string) (net.Conn, error) {
return net.Dial("unix", parts[1])
}
config.HttpClient = &http.Client{
Transport: trans,
}
} }
config.Address = parts[1] config.Address = parts[1]
} }

View File

@ -86,7 +86,8 @@ func (c *Command) httpFlagsClient(f *flag.FlagSet) *flag.FlagSet {
"The `address` and port of the Consul HTTP agent. The value can be an IP "+ "The `address` and port of the Consul HTTP agent. The value can be an IP "+
"address or DNS address, but it must also include the port. This can "+ "address or DNS address, but it must also include the port. This can "+
"also be specified via the CONSUL_HTTP_ADDR environment variable. The "+ "also be specified via the CONSUL_HTTP_ADDR environment variable. The "+
"default value is 127.0.0.1:8500.") "default value is http://127.0.0.1:8500. The scheme can also be set to "+
"HTTPS by setting the environment variable CONSUL_HTTP_SSL=true.")
f.Var(&c.token, "token", f.Var(&c.token, "token",
"ACL token to use in the request. This can also be specified via the "+ "ACL token to use in the request. This can also be specified via the "+
"CONSUL_HTTP_TOKEN environment variable. If unspecified, the query will "+ "CONSUL_HTTP_TOKEN environment variable. If unspecified, the query will "+