report listener and storage types as found keys (#15383)

* report listener and storage types as found keys

* changelog
This commit is contained in:
Hridoy Roy 2022-05-12 09:04:56 -07:00 committed by GitHub
parent 01bd627ee9
commit 0c955eb743
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 0 deletions

3
changelog/15383.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
command: do not report listener and storage types as key not found warnings
```

View File

@ -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)
}

View File

@ -51,3 +51,7 @@ func TestParseSeals(t *testing.T) {
func TestUnknownFieldValidation(t *testing.T) {
testUnknownFieldValidation(t)
}
func TestUnknownFieldValidationListenerAndStorage(t *testing.T) {
testUnknownFieldValidationStorageAndListener(t)
}

View File

@ -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 {

View File

@ -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
}

View File

@ -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))
}