[#1539] neofs-adm: Retrieve storage wallet passwords from config

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-06-23 10:45:56 +03:00 committed by fyrchik
parent fc7940a5ea
commit 451343c751
4 changed files with 21 additions and 3 deletions

View file

@ -5,6 +5,8 @@ Changelog for NeoFS Node
### Added ### Added
- Retrieve passwords for storage wallets from the configuration in neofs-adm (#1539)
### Changed ### Changed
### Fixed ### Fixed

View file

@ -153,3 +153,11 @@ func GetPassword(v *viper.Viper, name string) (string, error) {
prompt := "Password for " + name + " wallet > " prompt := "Password for " + name + " wallet > "
return input.ReadPassword(prompt) 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 > ")
}

View file

@ -6,7 +6,6 @@ import (
"os" "os"
"path/filepath" "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/core/native/nativenames"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" "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 { 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 { if err != nil {
return fmt.Errorf("can't fetch password: %w", err) 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) return fmt.Errorf("can't create account: %w", err)
} }
} }

View file

@ -10,6 +10,7 @@ const (
alphabetSizeFlag = "size" alphabetSizeFlag = "size"
endpointFlag = "rpc-endpoint" endpointFlag = "rpc-endpoint"
storageWalletFlag = "storage-wallet" storageWalletFlag = "storage-wallet"
storageWalletLabelFlag = "label"
storageGasCLIFlag = "initial-gas" storageGasCLIFlag = "initial-gas"
storageGasConfigFlag = "storage.initial_gas" storageGasConfigFlag = "storage.initial_gas"
contractsInitFlag = "contracts" contractsInitFlag = "contracts"
@ -209,6 +210,7 @@ func init() {
generateStorageCmd.Flags().StringP(endpointFlag, "r", "", "N3 RPC node endpoint") generateStorageCmd.Flags().StringP(endpointFlag, "r", "", "N3 RPC node endpoint")
generateStorageCmd.Flags().String(storageWalletFlag, "", "path to new storage node wallet") generateStorageCmd.Flags().String(storageWalletFlag, "", "path to new storage node wallet")
generateStorageCmd.Flags().String(storageGasCLIFlag, "", "initial amount of GAS to transfer") generateStorageCmd.Flags().String(storageGasCLIFlag, "", "initial amount of GAS to transfer")
generateStorageCmd.Flags().StringP(storageWalletLabelFlag, "l", "", "wallet label")
RootCmd.AddCommand(forceNewEpoch) RootCmd.AddCommand(forceNewEpoch)
forceNewEpoch.Flags().String(alphabetWalletsFlag, "", "path to alphabet wallets dir") forceNewEpoch.Flags().String(alphabetWalletsFlag, "", "path to alphabet wallets dir")