From e2f7b3f1ccdd359a41e7bfdfd5b9ef723af2caea Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 13 Jul 2021 11:43:51 +0300 Subject: [PATCH] [#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 --- CHANGELOG.md | 1 + cmd/neofs-node/config/node/config.go | 13 +++++++------ cmd/neofs-node/config/node/config_test.go | 3 +-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c0d1d83..89f6014a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)). diff --git a/cmd/neofs-node/config/node/config.go b/cmd/neofs-node/config/node/config.go index 2aad548b..c7f12771 100644 --- a/cmd/neofs-node/config/node/config.go +++ b/cmd/neofs-node/config/node/config.go @@ -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( diff --git a/cmd/neofs-node/config/node/config_test.go b/cmd/neofs-node/config/node/config_test.go index 6e49a855..54ced7d9 100644 --- a/cmd/neofs-node/config/node/config_test.go +++ b/cmd/neofs-node/config/node/config_test.go @@ -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) },