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>support/v0.27
parent
e0500d3158
commit
e2f7b3f1cc
|
@ -13,6 +13,7 @@ Changelog for NeoFS Node
|
||||||
### Fixed
|
### Fixed
|
||||||
- Do not require MainNet attributes in "Without MainNet" mode ([#663](https://github.com/nspcc-dev/neofs-node/issues/663)).
|
- 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)).
|
- 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
|
### Removed
|
||||||
- Debug output of public key in Inner Ring log ([#689](https://github.com/nspcc-dev/neofs-node/pull/689)).
|
- 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
|
package nodeconfig
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -18,16 +17,16 @@ const (
|
||||||
attributePrefix = "attribute"
|
attributePrefix = "attribute"
|
||||||
)
|
)
|
||||||
|
|
||||||
var errKeyNotSet = errors.New("empty/not set key address, see `node.key` section")
|
|
||||||
|
|
||||||
// Key returns value of "key" config parameter
|
// Key returns value of "key" config parameter
|
||||||
// from "node" section.
|
// 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 {
|
func Key(c *config.Config) *keys.PrivateKey {
|
||||||
v := config.StringSafe(c.Sub(subsection), "key")
|
v := config.StringSafe(c.Sub(subsection), "key")
|
||||||
if v == "" {
|
if v == "" {
|
||||||
panic(errKeyNotSet)
|
return Wallet(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -40,13 +39,15 @@ func Key(c *config.Config) *keys.PrivateKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Wallet(c)
|
panic(fmt.Errorf("invalid private key in node section: %w", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wallet returns value of node private key from "node" section.
|
// Wallet returns value of node private key from "node" section.
|
||||||
|
//
|
||||||
|
// Panics if section contains invalid values.
|
||||||
func Wallet(c *config.Config) *keys.PrivateKey {
|
func Wallet(c *config.Config) *keys.PrivateKey {
|
||||||
v := c.Sub(subsection).Sub("wallet")
|
v := c.Sub(subsection).Sub("wallet")
|
||||||
acc, err := utilConfig.LoadAccount(
|
acc, err := utilConfig.LoadAccount(
|
||||||
|
|
|
@ -14,9 +14,8 @@ func TestNodeSection(t *testing.T) {
|
||||||
t.Run("defaults", func(t *testing.T) {
|
t.Run("defaults", func(t *testing.T) {
|
||||||
empty := configtest.EmptyConfig()
|
empty := configtest.EmptyConfig()
|
||||||
|
|
||||||
require.PanicsWithError(
|
require.Panics(
|
||||||
t,
|
t,
|
||||||
errKeyNotSet.Error(),
|
|
||||||
func() {
|
func() {
|
||||||
Key(empty)
|
Key(empty)
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue