diff --git a/cmd/neofs-node/config/internal/validate/validate.go b/cmd/neofs-node/config/internal/validate/validate.go index e5736ec4a7..da0942b6a0 100644 --- a/cmd/neofs-node/config/internal/validate/validate.go +++ b/cmd/neofs-node/config/internal/validate/validate.go @@ -2,7 +2,9 @@ package validate import ( "fmt" + "reflect" + "github.com/mitchellh/mapstructure" "github.com/nspcc-dev/neofs-node/cmd/internal/configvalidator" "github.com/spf13/viper" ) @@ -10,7 +12,22 @@ import ( // ValidateStruct validates the viper config structure. func ValidateStruct(v *viper.Viper) error { var cfg valideConfig - if err := v.Unmarshal(&cfg); err != nil { + opt := viper.DecoderConfigOption(func(dc *mapstructure.DecoderConfig) { + dc.DecodeHook = mapstructure.ComposeDecodeHookFunc( + mapstructure.StringToTimeDurationHookFunc(), + mapstructure.StringToSliceHookFunc(","), + func(from reflect.Type, to reflect.Type, data any) (any, error) { + if from.Kind() == reflect.Map && to.Kind() == reflect.String { + _, ok := data.(map[string]any) + if !ok { + return data, nil + } + return "", nil + } + return data, nil + }) + }) + if err := v.Unmarshal(&cfg, opt); err != nil { return fmt.Errorf("unable to decode config: %w", err) } diff --git a/cmd/neofs-node/config/internal/validate/validate_test.go b/cmd/neofs-node/config/internal/validate/validate_test.go index 272dedf015..dfe2bd547d 100644 --- a/cmd/neofs-node/config/internal/validate/validate_test.go +++ b/cmd/neofs-node/config/internal/validate/validate_test.go @@ -160,6 +160,26 @@ grpc: enabled: false - endpoint: s03.neofs.devenv:8080 - unknown: field +`, + wantErr: true, + }, + { + name: "unknown field node.subnet", + config: ` +node: + attribute_0: "Price:11" + subnet: + exit_zero: False +`, + wantErr: true, + }, + { + name: "unknown field node.attribute_1", + config: ` +node: + attribute_0: "Price:11" + attribute_1: + aaa: "Price:11" `, wantErr: true, },