Skip to content

Commit

Permalink
report listener and storage types as found keys (#15383)
Browse files Browse the repository at this point in the history
* report listener and storage types as found keys

* changelog
  • Loading branch information
HridoyRoy committed May 12, 2022
1 parent 56fb894 commit 79df79f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelog/15383.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
command: do not report listener and storage types as key not found warnings
```
6 changes: 6 additions & 0 deletions command/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
4 changes: 4 additions & 0 deletions command/server/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ func TestParseSeals(t *testing.T) {
func TestUnknownFieldValidation(t *testing.T) {
testUnknownFieldValidation(t)
}

func TestUnknownFieldValidationListenerAndStorage(t *testing.T) {
testUnknownFieldValidationStorageAndListener(t)
}
10 changes: 10 additions & 0 deletions command/server/config_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions command/server/test-fixtures/storage-listener-config.json
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions internalshared/configutil/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down

0 comments on commit 79df79f

Please sign in to comment.