Parse template before splitting host/port

Ref: a33af1ca0b (r105444568)
This commit is contained in:
Jonathan Ballet 2017-03-13 21:40:37 +01:00
parent 72b0a7f34d
commit 3c5c49bedb
2 changed files with 12 additions and 10 deletions

View File

@ -794,6 +794,11 @@ func normalizeBind(addr, bind string) (string, error) {
//
// Loopback is only considered a valid advertise address in dev mode.
func normalizeAdvertise(addr string, bind string, defport int) (string, error) {
addr, err := parseSingleIPTemplate(addr)
if err != nil {
return "", fmt.Errorf("Error parsing advertise address template: %v", err)
}
if addr != "" {
// Default to using manually configured address
host, port, err := net.SplitHostPort(addr)
@ -805,12 +810,7 @@ func normalizeAdvertise(addr string, bind string, defport int) (string, error) {
port = strconv.Itoa(defport)
}
ipStr, err := parseSingleIPTemplate(host)
if err != nil {
return "", fmt.Errorf("Error parsing advertise address template: %v", err)
}
return net.JoinHostPort(ipStr, port), nil
return net.JoinHostPort(host, port), nil
}
// Fallback to bind address, as it has been resolved before.

View File

@ -612,8 +612,10 @@ func TestConfig_normalizeAddrs(t *testing.T) {
RPC: 4647,
Serf: 4648,
},
Addresses: &Addresses{},
AdvertiseAddrs: &AdvertiseAddrs{},
Addresses: &Addresses{},
AdvertiseAddrs: &AdvertiseAddrs{
RPC: "{{ GetPrivateIP }}:8888",
},
Server: &ServerConfig{
Enabled: true,
},
@ -627,8 +629,8 @@ func TestConfig_normalizeAddrs(t *testing.T) {
t.Fatalf("expected HTTP advertise address %s:4646, got %s", c.BindAddr, c.AdvertiseAddrs.HTTP)
}
if c.AdvertiseAddrs.RPC != fmt.Sprintf("%s:4647", c.BindAddr) {
t.Fatalf("expected RPC advertise address %s:4647, got %s", c.BindAddr, c.AdvertiseAddrs.RPC)
if c.AdvertiseAddrs.RPC != fmt.Sprintf("%s:8888", c.BindAddr) {
t.Fatalf("expected RPC advertise address %s:8888, got %s", c.BindAddr, c.AdvertiseAddrs.RPC)
}
if c.AdvertiseAddrs.Serf != fmt.Sprintf("%s:4648", c.BindAddr) {