From 0290f86579bc92cce094287a6bd00affb51b0f0b Mon Sep 17 00:00:00 2001 From: Alexander Chuprov Date: Sun, 31 Mar 2024 21:36:57 +0300 Subject: [PATCH] [#1065] adm: refactor dump-config Signed-off-by: Alexander Chuprov --- .../internal/modules/morph/config/config.go | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cmd/frostfs-adm/internal/modules/morph/config/config.go b/cmd/frostfs-adm/internal/modules/morph/config/config.go index 3414a8f7..2238a38d 100644 --- a/cmd/frostfs-adm/internal/modules/morph/config/config.go +++ b/cmd/frostfs-adm/internal/modules/morph/config/config.go @@ -105,12 +105,22 @@ func SetConfigCmd(cmd *cobra.Command, args []string) error { forceFlag, _ := cmd.Flags().GetBool(forceConfigSet) bw := io.NewBufBinWriter() + prm := make(map[string]any) + for _, arg := range args { k, v, err := parseConfigPair(arg, forceFlag) if err != nil { return err } + prm[k] = v + } + + if err := validateConfig(prm); err != nil { + return err + } + + for k, v := range prm { // In NeoFS this is done via Notary contract. Here, however, we can form the // transaction locally. The first `nil` argument is required only for notary // disabled environment which is not supported by that command. @@ -128,6 +138,16 @@ func SetConfigCmd(cmd *cobra.Command, args []string) error { return wCtx.AwaitTx() } +func validateConfig(args map[string]any) error { + for k, v := range args { + value, ok := v.(int64) + if !ok || value < 0 { + return fmt.Errorf("%s must be >= 0, got %v", k, v) + } + } + return nil +} + func parseConfigPair(kvStr string, force bool) (key string, val any, err error) { k, v, found := strings.Cut(kvStr, "=") if !found {