From 0c955eb74327506992e360c145f4e622d939073f Mon Sep 17 00:00:00 2001 From: Hridoy Roy Date: Thu, 12 May 2022 09:04:56 -0700 Subject: [PATCH] report listener and storage types as found keys (#15383) * report listener and storage types as found keys * changelog --- changelog/15383.txt | 3 +++ command/server/config.go | 6 ++++++ command/server/config_test.go | 4 ++++ command/server/config_test_helpers.go | 10 ++++++++++ .../test-fixtures/storage-listener-config.json | 17 +++++++++++++++++ internalshared/configutil/listener.go | 1 + 6 files changed, 41 insertions(+) create mode 100644 changelog/15383.txt create mode 100644 command/server/test-fixtures/storage-listener-config.json diff --git a/changelog/15383.txt b/changelog/15383.txt new file mode 100644 index 000000000..e9873821b --- /dev/null +++ b/changelog/15383.txt @@ -0,0 +1,3 @@ +```release-note:bug +command: do not report listener and storage types as key not found warnings +``` \ No newline at end of file diff --git a/command/server/config.go b/command/server/config.go index 911dfe537..8e97a659d 100644 --- a/command/server/config.go +++ b/command/server/config.go @@ -562,6 +562,7 @@ func ParseConfig(d, source string) (*Config, error) { if err := ParseStorage(result, o, "storage"); err != nil { return nil, fmt.Errorf("error parsing 'storage': %w", err) } + result.found(result.Storage.Type, result.Storage.Type) } else { delete(result.UnusedKeys, "backend") if o := list.Filter("backend"); len(o.Items) > 0 { @@ -967,3 +968,8 @@ func (c *Config) Prune() { c.Telemetry.UnusedKeys = nil } } + +func (c *Config) found(s, k string) { + delete(c.UnusedKeys, s) + c.FoundKeys = append(c.FoundKeys, k) +} diff --git a/command/server/config_test.go b/command/server/config_test.go index 8ba8d260d..d24608703 100644 --- a/command/server/config_test.go +++ b/command/server/config_test.go @@ -51,3 +51,7 @@ func TestParseSeals(t *testing.T) { func TestUnknownFieldValidation(t *testing.T) { testUnknownFieldValidation(t) } + +func TestUnknownFieldValidationListenerAndStorage(t *testing.T) { + testUnknownFieldValidationStorageAndListener(t) +} diff --git a/command/server/config_test_helpers.go b/command/server/config_test_helpers.go index 424d8fe81..06bb3a432 100644 --- a/command/server/config_test_helpers.go +++ b/command/server/config_test_helpers.go @@ -525,6 +525,16 @@ func testUnknownFieldValidation(t *testing.T) { } } +func testUnknownFieldValidationStorageAndListener(t *testing.T) { + config, err := LoadConfigFile("./test-fixtures/storage-listener-config.json") + if err != nil { + t.Fatalf("err: %s", err) + } + if len(config.UnusedKeys) != 0 { + t.Fatalf("unused keys for valid config are %+v\n", config.UnusedKeys) + } +} + func testLoadConfigFile_json(t *testing.T) { config, err := LoadConfigFile("./test-fixtures/config.hcl.json") if err != nil { diff --git a/command/server/test-fixtures/storage-listener-config.json b/command/server/test-fixtures/storage-listener-config.json new file mode 100644 index 000000000..30d25ab4e --- /dev/null +++ b/command/server/test-fixtures/storage-listener-config.json @@ -0,0 +1,17 @@ +{ + "api_addr": "https://localhost:8200", + "default_lease_ttl": "6h", + "disable_mlock": true, + "listener": { + "tcp": { + "address": "0.0.0.0:8200" + } + }, + "log_level": "info", + "storage": { + "consul": { + "address": "127.0.0.1:8500" + } + }, + "ui": true + } \ No newline at end of file diff --git a/internalshared/configutil/listener.go b/internalshared/configutil/listener.go index a9e1d7b5c..3f3c59930 100644 --- a/internalshared/configutil/listener.go +++ b/internalshared/configutil/listener.go @@ -167,6 +167,7 @@ func ParseListeners(result *SharedConfig, list *ast.ObjectList) error { l.Type = strings.ToLower(l.Type) switch l.Type { case "tcp", "unix": + result.found(l.Type, l.Type) default: return multierror.Prefix(fmt.Errorf("unsupported listener type %q", l.Type), fmt.Sprintf("listeners.%d:", i)) }