mirror of https://github.com/status-im/consul.git
config: warn the user if client_addr is empty
if the provided value is empty string then the client services (DNS, HTTP, HTTPS, GRPC) are not listening and the user is not notified in any way about what's happening. Also, since a not provided client_addr defaults to 127.0.0.1, we make sure we are not getting unwanted warnings Signed-off-by: Alessandro De Blasis <alex@deblasis.net>
This commit is contained in:
parent
3f30afd26b
commit
2f970555d9
|
@ -552,6 +552,9 @@ func (b *builder) build() (rt RuntimeConfig, err error) {
|
||||||
|
|
||||||
// determine client addresses
|
// determine client addresses
|
||||||
clientAddrs := b.expandIPs("client_addr", c.ClientAddr)
|
clientAddrs := b.expandIPs("client_addr", c.ClientAddr)
|
||||||
|
if len(clientAddrs) == 0 {
|
||||||
|
b.warn("client_addr is empty, client services (DNS, HTTP, HTTPS, GRPC) will not be listening for connections")
|
||||||
|
}
|
||||||
dnsAddrs := b.makeAddrs(b.expandAddrs("addresses.dns", c.Addresses.DNS), clientAddrs, dnsPort)
|
dnsAddrs := b.makeAddrs(b.expandAddrs("addresses.dns", c.Addresses.DNS), clientAddrs, dnsPort)
|
||||||
httpAddrs := b.makeAddrs(b.expandAddrs("addresses.http", c.Addresses.HTTP), clientAddrs, httpPort)
|
httpAddrs := b.makeAddrs(b.expandAddrs("addresses.http", c.Addresses.HTTP), clientAddrs, httpPort)
|
||||||
httpsAddrs := b.makeAddrs(b.expandAddrs("addresses.https", c.Addresses.HTTPS), clientAddrs, httpsPort)
|
httpsAddrs := b.makeAddrs(b.expandAddrs("addresses.https", c.Addresses.HTTPS), clientAddrs, httpsPort)
|
||||||
|
|
|
@ -247,3 +247,47 @@ func TestLoad_HTTPMaxConnsPerClientExceedsRLimit(t *testing.T) {
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Contains(t, err.Error(), "but limits.http_max_conns_per_client: 16777217 needs at least 16777237")
|
assert.Contains(t, err.Error(), "but limits.http_max_conns_per_client: 16777217 needs at least 16777237")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLoad_EmptyClientAddr(t *testing.T) {
|
||||||
|
|
||||||
|
type testCase struct {
|
||||||
|
name string
|
||||||
|
clientAddr *string
|
||||||
|
expectedWarningMessage *string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn := func(t *testing.T, tc testCase) {
|
||||||
|
opts := LoadOpts{
|
||||||
|
FlagValues: Config{
|
||||||
|
ClientAddr: tc.clientAddr,
|
||||||
|
DataDir: pString("dir"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
patchLoadOptsShims(&opts)
|
||||||
|
result, err := Load(opts)
|
||||||
|
require.NoError(t, err)
|
||||||
|
if tc.expectedWarningMessage != nil {
|
||||||
|
require.Len(t, result.Warnings, 1)
|
||||||
|
require.Contains(t, result.Warnings[0], *tc.expectedWarningMessage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var testCases = []testCase{
|
||||||
|
{
|
||||||
|
name: "empty string",
|
||||||
|
clientAddr: pString(""),
|
||||||
|
expectedWarningMessage: pString("client_addr is empty, client services (DNS, HTTP, HTTPS, GRPC) will not be listening for connections"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "nil pointer",
|
||||||
|
clientAddr: nil, // defaults to 127.0.0.1
|
||||||
|
expectedWarningMessage: nil, // expecting no warnings
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
fn(t, tc)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue