[#690] cmd/neofs-node: Fallback to wallet section if node key is not set

Some users want to specify only wallet section in the SN. It is not
possible if `Key` throws panic on empty value. Instead it should
fallback to wallet section. Panic is suitable if node's key is provided
but invalid.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-07-13 11:43:51 +03:00 committed by Alex Vanin
parent e0500d3158
commit e2f7b3f1cc
3 changed files with 9 additions and 8 deletions

View file

@ -1,7 +1,6 @@
package nodeconfig
import (
"errors"
"fmt"
"os"
"strconv"
@ -18,16 +17,16 @@ const (
attributePrefix = "attribute"
)
var errKeyNotSet = errors.New("empty/not set key address, see `node.key` section")
// Key returns value of "key" config parameter
// from "node" section.
//
// Panics if value is not a non-empty string.
// If value is not set, fallbacks to Wallet section.
//
// Panics if value is incorrect filename of binary encoded private key.
func Key(c *config.Config) *keys.PrivateKey {
v := config.StringSafe(c.Sub(subsection), "key")
if v == "" {
panic(errKeyNotSet)
return Wallet(c)
}
var (
@ -40,13 +39,15 @@ func Key(c *config.Config) *keys.PrivateKey {
}
if err != nil {
return Wallet(c)
panic(fmt.Errorf("invalid private key in node section: %w", err))
}
return key
}
// Wallet returns value of node private key from "node" section.
//
// Panics if section contains invalid values.
func Wallet(c *config.Config) *keys.PrivateKey {
v := c.Sub(subsection).Sub("wallet")
acc, err := utilConfig.LoadAccount(