From 451343c75149eb5de91fe6610fb5646d75c763a3 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 23 Jun 2022 10:45:56 +0300 Subject: [PATCH] [#1539] neofs-adm: Retrieve storage wallet passwords from config Signed-off-by: Evgenii Stratonikov --- CHANGELOG.md | 2 ++ cmd/neofs-adm/internal/modules/config/config.go | 8 ++++++++ cmd/neofs-adm/internal/modules/morph/generate.go | 12 +++++++++--- cmd/neofs-adm/internal/modules/morph/root.go | 2 ++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5637cccfe..472508f77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ Changelog for NeoFS Node ### Added +- Retrieve passwords for storage wallets from the configuration in neofs-adm (#1539) + ### Changed ### Fixed diff --git a/cmd/neofs-adm/internal/modules/config/config.go b/cmd/neofs-adm/internal/modules/config/config.go index 1a9ba65c9..c398ba2c1 100644 --- a/cmd/neofs-adm/internal/modules/config/config.go +++ b/cmd/neofs-adm/internal/modules/config/config.go @@ -153,3 +153,11 @@ func GetPassword(v *viper.Viper, name string) (string, error) { prompt := "Password for " + name + " wallet > " return input.ReadPassword(prompt) } + +func GetStoragePassword(v *viper.Viper, name string) (string, error) { + key := "storage." + name + if name != "" && v.IsSet(key) { + return v.GetString(key), nil + } + return input.ReadPassword("New password > ") +} diff --git a/cmd/neofs-adm/internal/modules/morph/generate.go b/cmd/neofs-adm/internal/modules/morph/generate.go index 76941c633..bffada2a0 100644 --- a/cmd/neofs-adm/internal/modules/morph/generate.go +++ b/cmd/neofs-adm/internal/modules/morph/generate.go @@ -6,7 +6,6 @@ import ( "os" "path/filepath" - "github.com/nspcc-dev/neo-go/cli/input" "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" @@ -159,12 +158,19 @@ func refillGas(cmd *cobra.Command, gasFlag string, createWallet bool) error { } if createWallet { - password, err := input.ReadPassword("New password > ") + var password string + + label, _ := cmd.Flags().GetString(storageWalletLabelFlag) + password, err := config.GetStoragePassword(viper.GetViper(), label) if err != nil { return fmt.Errorf("can't fetch password: %w", err) } - if err := w.CreateAccount(singleAccountName, password); err != nil { + if label == "" { + label = singleAccountName + } + + if err := w.CreateAccount(label, password); err != nil { return fmt.Errorf("can't create account: %w", err) } } diff --git a/cmd/neofs-adm/internal/modules/morph/root.go b/cmd/neofs-adm/internal/modules/morph/root.go index 34ec928bb..1d65390a5 100644 --- a/cmd/neofs-adm/internal/modules/morph/root.go +++ b/cmd/neofs-adm/internal/modules/morph/root.go @@ -10,6 +10,7 @@ const ( alphabetSizeFlag = "size" endpointFlag = "rpc-endpoint" storageWalletFlag = "storage-wallet" + storageWalletLabelFlag = "label" storageGasCLIFlag = "initial-gas" storageGasConfigFlag = "storage.initial_gas" contractsInitFlag = "contracts" @@ -209,6 +210,7 @@ func init() { generateStorageCmd.Flags().StringP(endpointFlag, "r", "", "N3 RPC node endpoint") generateStorageCmd.Flags().String(storageWalletFlag, "", "path to new storage node wallet") generateStorageCmd.Flags().String(storageGasCLIFlag, "", "initial amount of GAS to transfer") + generateStorageCmd.Flags().StringP(storageWalletLabelFlag, "l", "", "wallet label") RootCmd.AddCommand(forceNewEpoch) forceNewEpoch.Flags().String(alphabetWalletsFlag, "", "path to alphabet wallets dir")