Update docs and give better error for unknown client scheme

This commit is contained in:
Kyle Havlovitz 2017-02-10 19:55:54 -05:00
parent bdb58adb80
commit 35d99a81ac
No known key found for this signature in database
GPG Key ID: 8A5E6B173056AD6C
3 changed files with 14 additions and 5 deletions

View File

@ -348,9 +348,11 @@ func NewClient(config *Config) (*Client, error) {
parts := strings.SplitN(config.Address, "://", 2) parts := strings.SplitN(config.Address, "://", 2)
if len(parts) == 2 { if len(parts) == 2 {
if parts[0] == "https" { switch parts[0] {
case "http":
case "https":
config.Scheme = "https" config.Scheme = "https"
} else if parts[0] == "unix" { case "unix":
trans := cleanhttp.DefaultTransport() trans := cleanhttp.DefaultTransport()
trans.Dial = func(_, _ string) (net.Conn, error) { trans.Dial = func(_, _ string) (net.Conn, error) {
return net.Dial("unix", parts[1]) return net.Dial("unix", parts[1])
@ -358,6 +360,8 @@ func NewClient(config *Config) (*Client, error) {
config.HttpClient = &http.Client{ config.HttpClient = &http.Client{
Transport: trans, Transport: trans,
} }
default:
return nil, fmt.Errorf("Unknown protocol scheme: %s", parts[0])
} }
config.Address = parts[1] config.Address = parts[1]
} }

View File

@ -1086,8 +1086,11 @@ func (c *Command) Run(args []string) int {
var err error var err error
if config.Ports.HTTP != -1 { if config.Ports.HTTP != -1 {
httpAddr, err = config.ClientListener(config.Addresses.HTTP, config.Ports.HTTP) httpAddr, err = config.ClientListener(config.Addresses.HTTP, config.Ports.HTTP)
} else { } else if config.Ports.HTTPS != -1 {
httpAddr, err = config.ClientListener(config.Addresses.HTTPS, config.Ports.HTTPS) httpAddr, err = config.ClientListener(config.Addresses.HTTPS, config.Ports.HTTPS)
} else if len(config.WatchPlans) > 0 {
c.Ui.Error("Error: cannot use watches if both HTTP and HTTPS are disabled")
return 1
} }
if err != nil { if err != nil {
c.Ui.Error(fmt.Sprintf("Failed to determine HTTP address: %v", err)) c.Ui.Error(fmt.Sprintf("Failed to determine HTTP address: %v", err))

View File

@ -1,7 +1,9 @@
* `-http-addr=<addr>` - Address of the Consul agent with the port. This can be * `-http-addr=<addr>` - Address of the Consul agent with the port. This can be
an IP address or DNS address, but it must include the port. This can also be an IP address or DNS address, but it must include the port. This can also be
specified via the `CONSUL_HTTP_ADDR` environment variable. The default value is specified via the `CONSUL_HTTP_ADDR` environment variable. In Consul 0.8 and
127.0.0.1:8500. later, the default value is http://127.0.0.1:8500, and https can optionally
be used instead. The scheme can also be set to HTTPS by setting the
environment variable `CONSUL_HTTP_SSL=true`.
* `-token=<value>` - ACL token to use in the request. This can also be specified * `-token=<value>` - ACL token to use in the request. This can also be specified
via the `CONSUL_HTTP_TOKEN` environment variable. If unspecified, the query via the `CONSUL_HTTP_TOKEN` environment variable. If unspecified, the query