forked from TrueCloudLab/frostfs-node
[#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:
parent
e0500d3158
commit
e2f7b3f1cc
3 changed files with 9 additions and 8 deletions
|
@ -13,6 +13,7 @@ Changelog for NeoFS Node
|
|||
### Fixed
|
||||
- Do not require MainNet attributes in "Without MainNet" mode ([#663](https://github.com/nspcc-dev/neofs-node/issues/663)).
|
||||
- Stable alphabet list merge in Inner Ring governance ([#670](https://github.com/nspcc-dev/neofs-node/issues/670)).
|
||||
- User can specify only wallet section without node key ([#690](https://github.com/nspcc-dev/neofs-node/pull/690)).
|
||||
|
||||
### Removed
|
||||
- Debug output of public key in Inner Ring log ([#689](https://github.com/nspcc-dev/neofs-node/pull/689)).
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -14,9 +14,8 @@ func TestNodeSection(t *testing.T) {
|
|||
t.Run("defaults", func(t *testing.T) {
|
||||
empty := configtest.EmptyConfig()
|
||||
|
||||
require.PanicsWithError(
|
||||
require.Panics(
|
||||
t,
|
||||
errKeyNotSet.Error(),
|
||||
func() {
|
||||
Key(empty)
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue