Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

neofs-adm: retrieve storage wallet passwords from config #1539

Merged
merged 1 commit into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Changelog for NeoFS Node

### Added

- Retrieve passwords for storage wallets from the configuration in neofs-adm (#1539)

### Changed

### Fixed
Expand Down
8 changes: 8 additions & 0 deletions cmd/neofs-adm/internal/modules/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
cthulhu-rider marked this conversation as resolved.
Show resolved Hide resolved
return v.GetString(key), nil
}
return input.ReadPassword("New password > ")
}
12 changes: 9 additions & 3 deletions cmd/neofs-adm/internal/modules/morph/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/neofs-adm/internal/modules/morph/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
alphabetSizeFlag = "size"
endpointFlag = "rpc-endpoint"
storageWalletFlag = "storage-wallet"
storageWalletLabelFlag = "label"
storageGasCLIFlag = "initial-gas"
storageGasConfigFlag = "storage.initial_gas"
contractsInitFlag = "contracts"
Expand Down Expand Up @@ -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")
Expand Down