From c65349833f108d1e94cf3c0cf9da98c40b77fb93 Mon Sep 17 00:00:00 2001 From: Vadim Voitenko Date: Sat, 24 Aug 2024 12:24:27 +0300 Subject: [PATCH 1/2] fix: added error unused decoder setting Now if user provides the unknown key the error will be thrown Closes #176 --- cmd/greenmask/cmd/root.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/greenmask/cmd/root.go b/cmd/greenmask/cmd/root.go index b7f21f44..7c676879 100644 --- a/cmd/greenmask/cmd/root.go +++ b/cmd/greenmask/cmd/root.go @@ -140,6 +140,7 @@ func initConfig() { mapstructure.StringToTimeDurationHookFunc(), mapstructure.StringToSliceHookFunc(","), ) + cfg.ErrorUnused = true } if err := viper.Unmarshal(Config, decoderCfg); err != nil { From 69ac47e3dff51143e70884384ed03c675e026db2 Mon Sep 17 00:00:00 2001 From: Vadim Voitenko Date: Sat, 24 Aug 2024 13:12:07 +0300 Subject: [PATCH 2/2] fix: added error unused decoder setting Fixed parameters encoding --- internal/domains/config.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/domains/config.go b/internal/domains/config.go index 7737f51d..ada2d446 100644 --- a/internal/domains/config.go +++ b/internal/domains/config.go @@ -132,7 +132,11 @@ type TransformerConfig struct { // This cannot be parsed with mapstructure due to uncontrollable lowercasing // https://github.com/spf13/viper/issues/373 // Instead we have to use workaround and parse it manually - Params toolkit.StaticParameters `mapstructure:"-" yaml:"-" json:"-"` // yaml:"params" json:"params,omitempty"` + // + // Params attribute decoding is dummy. It is replaced in the runtime internal/utils/config/viper_workaround.go + // But it is required to leave mapstruicture tag to avoid errors raised by viper and decoder setting + // ErrorUnused = true. It was set in PR #177 (https://github.com/GreenmaskIO/greenmask/pull/177/files) + Params toolkit.StaticParameters `mapstructure:"params" yaml:"params" json:"params"` // MetadataParams - encoded transformer parameters - uses only for storing into storage // TODO: You need to get rid of it by creating a separate structure for storing metadata in // internal/db/postgres/storage/metadata_json.go