[#1103] neofs-cli: disallow generating key for control commands

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-01-26 10:53:30 +03:00 committed by LeL
parent 007158ebe1
commit 5c2b2e137d
2 changed files with 9 additions and 7 deletions

View file

@ -24,7 +24,6 @@ var controlCmd = &cobra.Command{
PersistentPreRun: func(cmd *cobra.Command, args []string) { PersistentPreRun: func(cmd *cobra.Command, args []string) {
ff := cmd.Flags() ff := cmd.Flags()
_ = viper.BindPFlag(generateKey, ff.Lookup(generateKey))
_ = viper.BindPFlag(walletPath, ff.Lookup(walletPath)) _ = viper.BindPFlag(walletPath, ff.Lookup(walletPath))
_ = viper.BindPFlag(address, ff.Lookup(address)) _ = viper.BindPFlag(address, ff.Lookup(address))
_ = viper.BindPFlag(controlRPC, ff.Lookup(controlRPC)) _ = viper.BindPFlag(controlRPC, ff.Lookup(controlRPC))
@ -201,7 +200,7 @@ func init() {
} }
func healthCheck(cmd *cobra.Command, _ []string) { func healthCheck(cmd *cobra.Command, _ []string) {
key, err := getKey() key, err := getKeyNoGenerate()
exitOnErr(cmd, err) exitOnErr(cmd, err)
cli, err := getControlSDKClient(key) cli, err := getControlSDKClient(key)
@ -261,7 +260,7 @@ func healthCheckIR(cmd *cobra.Command, key *ecdsa.PrivateKey, c *client.Client)
} }
func setNetmapStatus(cmd *cobra.Command, _ []string) { func setNetmapStatus(cmd *cobra.Command, _ []string) {
key, err := getKey() key, err := getKeyNoGenerate()
exitOnErr(cmd, err) exitOnErr(cmd, err)
var status control.NetmapStatus var status control.NetmapStatus
@ -315,7 +314,7 @@ var dropObjectsCmd = &cobra.Command{
Short: "Drop objects from the node's local storage", Short: "Drop objects from the node's local storage",
Long: "Drop objects from the node's local storage", Long: "Drop objects from the node's local storage",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
key, err := getKey() key, err := getKeyNoGenerate()
exitOnErr(cmd, err) exitOnErr(cmd, err)
binAddrList := make([][]byte, 0, len(dropObjectsList)) binAddrList := make([][]byte, 0, len(dropObjectsList))
@ -369,7 +368,7 @@ var snapshotCmd = &cobra.Command{
Short: "Get network map snapshot", Short: "Get network map snapshot",
Long: "Get network map snapshot", Long: "Get network map snapshot",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
key, err := getKey() key, err := getKeyNoGenerate()
exitOnErr(cmd, err) exitOnErr(cmd, err)
req := new(control.NetmapSnapshotRequest) req := new(control.NetmapSnapshotRequest)
@ -399,7 +398,7 @@ var snapshotCmd = &cobra.Command{
} }
func listShards(cmd *cobra.Command, _ []string) { func listShards(cmd *cobra.Command, _ []string) {
key, err := getKey() key, err := getKeyNoGenerate()
exitOnErr(cmd, err) exitOnErr(cmd, err)
req := new(control.ListShardsRequest) req := new(control.ListShardsRequest)
@ -483,7 +482,7 @@ func prettyPrintShards(cmd *cobra.Command, ii []*control.ShardInfo) {
} }
func setShardMode(cmd *cobra.Command, _ []string) { func setShardMode(cmd *cobra.Command, _ []string) {
key, err := getKey() key, err := getKeyNoGenerate()
exitOnErr(cmd, err) exitOnErr(cmd, err)
var mode control.ShardMode var mode control.ShardMode

View file

@ -174,7 +174,10 @@ func getKey() (*ecdsa.PrivateKey, error) {
} }
return &priv.PrivateKey, nil return &priv.PrivateKey, nil
} }
return getKeyNoGenerate()
}
func getKeyNoGenerate() (*ecdsa.PrivateKey, error) {
// Ideally we want to touch file-system on the last step. // Ideally we want to touch file-system on the last step.
// However, asking for NEP-2 password seems to be confusing if we provide a wallet. // However, asking for NEP-2 password seems to be confusing if we provide a wallet.
// Thus we try keys in the following order: // Thus we try keys in the following order: