[#1065] adm: refactor dump-config

Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
Alexander Chuprov 2024-03-31 21:36:57 +03:00
parent ffb1a6f81a
commit 0290f86579

View file

@ -105,12 +105,22 @@ func SetConfigCmd(cmd *cobra.Command, args []string) error {
forceFlag, _ := cmd.Flags().GetBool(forceConfigSet) forceFlag, _ := cmd.Flags().GetBool(forceConfigSet)
bw := io.NewBufBinWriter() bw := io.NewBufBinWriter()
prm := make(map[string]any)
for _, arg := range args { for _, arg := range args {
k, v, err := parseConfigPair(arg, forceFlag) k, v, err := parseConfigPair(arg, forceFlag)
if err != nil { if err != nil {
return err 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 // 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 // transaction locally. The first `nil` argument is required only for notary
// disabled environment which is not supported by that command. // disabled environment which is not supported by that command.
@ -128,6 +138,16 @@ func SetConfigCmd(cmd *cobra.Command, args []string) error {
return wCtx.AwaitTx() 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) { func parseConfigPair(kvStr string, force bool) (key string, val any, err error) {
k, v, found := strings.Cut(kvStr, "=") k, v, found := strings.Cut(kvStr, "=")
if !found { if !found {