[#1424] neofs-cli: Fail immediately if a key can't be fetched

If the key can't be fetched, an error is always returned, so it makes
sense to fail the whole command inside of a `key.Get*()`.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-05-24 11:22:23 +03:00 committed by LeL
parent d9c5ca5e77
commit 295ec3700a
19 changed files with 70 additions and 69 deletions

View file

@ -139,19 +139,13 @@ func initConfig() {
}
}
// getKey returns private key that was provided in global arguments.
func getKey() (*ecdsa.PrivateKey, error) {
return key.GetOrGenerate()
}
type clientWithKey interface {
SetClient(*client.Client)
}
// reads private key from command args and call prepareAPIClientWithKey with it.
func prepareAPIClient(cmd *cobra.Command, dst ...clientWithKey) {
p, err := getKey()
common.ExitOnErr(cmd, "get private key: %w", err)
p := key.GetOrGenerate(cmd)
prepareAPIClientWithKey(cmd, p, dst...)
}