From 136dd73cb79aea7e16d482cdeb07dcf666459898 Mon Sep 17 00:00:00 2001 From: Scott Miller Date: Mon, 12 Jul 2021 16:33:17 -0500 Subject: [PATCH] Wire up remaining sections for config validation (#12048) * wip * Add validation to storage, serviceregistration * Wire up remaining sections except Storage which is generic --- command/server/config.go | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/command/server/config.go b/command/server/config.go index 914e5b7210..7e4e81b511 100644 --- a/command/server/config.go +++ b/command/server/config.go @@ -19,6 +19,10 @@ import ( "github.com/hashicorp/vault/sdk/helper/parseutil" ) +var entConfigValidate = func(_ *Config, _ string) []configutil.ConfigError { + return nil +} + // Config is the configuration for the vault server. type Config struct { UnusedKeys configutil.UnusedKeyMap `hcl:",unusedKeyPositions"` @@ -88,13 +92,21 @@ func (c *Config) Validate(sourceFilePath string) []configutil.ConfigError { results := configutil.ValidateUnusedFields(c.UnusedKeys, sourceFilePath) if c.Telemetry != nil { results = append(results, c.Telemetry.Validate(sourceFilePath)...) - for _, l := range c.Listeners { - results = append(results, l.Validate(sourceFilePath)...) - } } + if c.ServiceRegistration != nil { + results = append(results, c.ServiceRegistration.Validate(sourceFilePath)...) + } + for _, l := range c.Listeners { + results = append(results, l.Validate(sourceFilePath)...) + } + results = append(results, c.validateEnt(sourceFilePath)...) return results } +func (c *Config) validateEnt(sourceFilePath string) []configutil.ConfigError { + return entConfigValidate(c, sourceFilePath) +} + // DevConfig is a Config that is used for dev mode of Vault. func DevConfig(storageType string) (*Config, error) { hclStr := ` @@ -130,7 +142,6 @@ ui = true // Storage is the underlying storage configuration for the server. type Storage struct { - UnusedKeys []string `hcl:",unusedKeys"` Type string RedirectAddr string ClusterAddr string @@ -144,8 +155,13 @@ func (b *Storage) GoString() string { // ServiceRegistration is the optional service discovery for the server. type ServiceRegistration struct { - Type string - Config map[string]string + UnusedKeys configutil.UnusedKeyMap `hcl:",unusedKeyPositions"` + Type string + Config map[string]string +} + +func (b *ServiceRegistration) Validate(source string) []configutil.ConfigError { + return configutil.ValidateUnusedFields(b.UnusedKeys, source) } func (b *ServiceRegistration) GoString() string {