From 5c2b2e137d5f98621e0dd081b9aca3e27ab86ee9 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 26 Jan 2022 10:53:30 +0300 Subject: [PATCH] [#1103] neofs-cli: disallow generating key for control commands Signed-off-by: Evgenii Stratonikov --- cmd/neofs-cli/modules/control.go | 13 ++++++------- cmd/neofs-cli/modules/root.go | 3 +++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/neofs-cli/modules/control.go b/cmd/neofs-cli/modules/control.go index 8a76acc7a..6195bd47c 100644 --- a/cmd/neofs-cli/modules/control.go +++ b/cmd/neofs-cli/modules/control.go @@ -24,7 +24,6 @@ var controlCmd = &cobra.Command{ PersistentPreRun: func(cmd *cobra.Command, args []string) { ff := cmd.Flags() - _ = viper.BindPFlag(generateKey, ff.Lookup(generateKey)) _ = viper.BindPFlag(walletPath, ff.Lookup(walletPath)) _ = viper.BindPFlag(address, ff.Lookup(address)) _ = viper.BindPFlag(controlRPC, ff.Lookup(controlRPC)) @@ -201,7 +200,7 @@ func init() { } func healthCheck(cmd *cobra.Command, _ []string) { - key, err := getKey() + key, err := getKeyNoGenerate() exitOnErr(cmd, err) 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) { - key, err := getKey() + key, err := getKeyNoGenerate() exitOnErr(cmd, err) var status control.NetmapStatus @@ -315,7 +314,7 @@ var dropObjectsCmd = &cobra.Command{ Short: "Drop objects from the node's local storage", Long: "Drop objects from the node's local storage", Run: func(cmd *cobra.Command, args []string) { - key, err := getKey() + key, err := getKeyNoGenerate() exitOnErr(cmd, err) binAddrList := make([][]byte, 0, len(dropObjectsList)) @@ -369,7 +368,7 @@ var snapshotCmd = &cobra.Command{ Short: "Get network map snapshot", Long: "Get network map snapshot", Run: func(cmd *cobra.Command, args []string) { - key, err := getKey() + key, err := getKeyNoGenerate() exitOnErr(cmd, err) req := new(control.NetmapSnapshotRequest) @@ -399,7 +398,7 @@ var snapshotCmd = &cobra.Command{ } func listShards(cmd *cobra.Command, _ []string) { - key, err := getKey() + key, err := getKeyNoGenerate() exitOnErr(cmd, err) req := new(control.ListShardsRequest) @@ -483,7 +482,7 @@ func prettyPrintShards(cmd *cobra.Command, ii []*control.ShardInfo) { } func setShardMode(cmd *cobra.Command, _ []string) { - key, err := getKey() + key, err := getKeyNoGenerate() exitOnErr(cmd, err) var mode control.ShardMode diff --git a/cmd/neofs-cli/modules/root.go b/cmd/neofs-cli/modules/root.go index fffeb3f7f..e33746305 100644 --- a/cmd/neofs-cli/modules/root.go +++ b/cmd/neofs-cli/modules/root.go @@ -174,7 +174,10 @@ func getKey() (*ecdsa.PrivateKey, error) { } return &priv.PrivateKey, nil } + return getKeyNoGenerate() +} +func getKeyNoGenerate() (*ecdsa.PrivateKey, error) { // 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. // Thus we try keys in the following order: