Move verifyUniqueListeners to command/agent/config.go

pull/3006/head
Frank Schroeder 8 years ago committed by Frank Schröder
parent d34ba3e823
commit 78fc19c48c

@ -442,50 +442,6 @@ func (c *Command) readConfig() *Config {
return config return config
} }
// verifyUniqueListeners checks to see if an address was used more than once in
// the config
func (c *Config) verifyUniqueListeners() error {
listeners := []struct {
host string
port int
descr string
}{
{c.Addresses.DNS, c.Ports.DNS, "DNS"},
{c.Addresses.HTTP, c.Ports.HTTP, "HTTP"},
{c.Addresses.HTTPS, c.Ports.HTTPS, "HTTPS"},
{c.AdvertiseAddr, c.Ports.Server, "Server RPC"},
{c.AdvertiseAddr, c.Ports.SerfLan, "Serf LAN"},
{c.AdvertiseAddr, c.Ports.SerfWan, "Serf WAN"},
}
type key struct {
host string
port int
}
m := make(map[key]string, len(listeners))
for _, l := range listeners {
if l.host == "" {
l.host = "0.0.0.0"
} else if strings.HasPrefix(l.host, "unix") {
// Don't compare ports on unix sockets
l.port = 0
}
if l.host == "0.0.0.0" && l.port <= 0 {
continue
}
k := key{l.host, l.port}
v, ok := m[k]
if ok {
return fmt.Errorf("%s address already configured for %s", l.descr, v)
}
m[k] = l.descr
}
return nil
}
// discoverEc2Hosts searches an AWS region, returning a list of instance ips
// where EC2TagKey = EC2TagValue // where EC2TagKey = EC2TagValue
func (c *Config) discoverEc2Hosts(logger *log.Logger) ([]string, error) { func (c *Config) discoverEc2Hosts(logger *log.Logger) ([]string, error) {
config := c.RetryJoinEC2 config := c.RetryJoinEC2

@ -931,6 +931,49 @@ func (c *Config) GetTokenForAgent() string {
return "" return ""
} }
// verifyUniqueListeners checks to see if an address was used more than once in
// the config
func (c *Config) verifyUniqueListeners() error {
listeners := []struct {
host string
port int
descr string
}{
{c.Addresses.DNS, c.Ports.DNS, "DNS"},
{c.Addresses.HTTP, c.Ports.HTTP, "HTTP"},
{c.Addresses.HTTPS, c.Ports.HTTPS, "HTTPS"},
{c.AdvertiseAddr, c.Ports.Server, "Server RPC"},
{c.AdvertiseAddr, c.Ports.SerfLan, "Serf LAN"},
{c.AdvertiseAddr, c.Ports.SerfWan, "Serf WAN"},
}
type key struct {
host string
port int
}
m := make(map[key]string, len(listeners))
for _, l := range listeners {
if l.host == "" {
l.host = "0.0.0.0"
} else if strings.HasPrefix(l.host, "unix") {
// Don't compare ports on unix sockets
l.port = 0
}
if l.host == "0.0.0.0" && l.port <= 0 {
continue
}
k := key{l.host, l.port}
v, ok := m[k]
if ok {
return fmt.Errorf("%s address already configured for %s", l.descr, v)
}
m[k] = l.descr
}
return nil
}
// DecodeConfig reads the configuration from the given reader in JSON // DecodeConfig reads the configuration from the given reader in JSON
// format and decodes it into a proper Config structure. // format and decodes it into a proper Config structure.
func DecodeConfig(r io.Reader) (*Config, error) { func DecodeConfig(r io.Reader) (*Config, error) {

Loading…
Cancel
Save