forked from TrueCloudLab/frostfs-node
[#562] config: parse key on config load
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
9142c778c7
commit
2f020a500d
6 changed files with 20 additions and 8 deletions
|
@ -3,6 +3,7 @@ package nodeconfig
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
@ -26,16 +27,26 @@ var (
|
||||||
// from "node" section.
|
// from "node" section.
|
||||||
//
|
//
|
||||||
// Panics if value is not a non-empty string.
|
// Panics if value is not a non-empty string.
|
||||||
func Key(c *config.Config) string {
|
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)
|
panic(errKeyNotSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add string -> `ecdsa.PrivateKey` parsing logic
|
var (
|
||||||
// after https://github.com/nspcc-dev/neofs-node/pull/569.
|
key *keys.PrivateKey
|
||||||
|
err error
|
||||||
|
data []byte
|
||||||
|
)
|
||||||
|
if data, err = ioutil.ReadFile(v); err == nil {
|
||||||
|
key, err = keys.NewPrivateKeyFromBytes(data)
|
||||||
|
}
|
||||||
|
|
||||||
return v
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("can't read key: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wallet returns value of node private key from "node" section.
|
// Wallet returns value of node private key from "node" section.
|
||||||
|
|
|
@ -49,7 +49,7 @@ func TestNodeSection(t *testing.T) {
|
||||||
expectedAddr, err := network.AddressFromString("s01.neofs.devenv:8080")
|
expectedAddr, err := network.AddressFromString("s01.neofs.devenv:8080")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, "path/hex/WIF", key)
|
require.Equal(t, "NbUgTSFvPmsRxmGeWpuuGeJUoRoi6PErcM", key.Address())
|
||||||
require.Equal(t, true, addr.Equal(expectedAddr))
|
require.Equal(t, true, addr.Equal(expectedAddr))
|
||||||
require.Equal(t, true, relay)
|
require.Equal(t, true, relay)
|
||||||
|
|
||||||
|
|
1
cmd/neofs-node/config/node/wallet.key
Normal file
1
cmd/neofs-node/config/node/wallet.key
Normal file
|
@ -0,0 +1 @@
|
||||||
|
с╨─ЧдФ╕Я?вьэЁ╡²Оv─/l⌠║еы╩
|
|
@ -7,7 +7,7 @@ NEOFS_METRICS_ADDRESS=127.0.0.1:9090
|
||||||
NEOFS_METRICS_SHUTDOWN_TIMEOUT=15s
|
NEOFS_METRICS_SHUTDOWN_TIMEOUT=15s
|
||||||
|
|
||||||
# Node section
|
# Node section
|
||||||
NEOFS_NODE_KEY=path/hex/WIF
|
NEOFS_NODE_KEY=./wallet.key
|
||||||
NEOFS_NODE_WALLET_PATH=./wallet.json
|
NEOFS_NODE_WALLET_PATH=./wallet.json
|
||||||
NEOFS_NODE_WALLET_ADDRESS=NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz
|
NEOFS_NODE_WALLET_ADDRESS=NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz
|
||||||
NEOFS_NODE_WALLET_PASSWORD=password
|
NEOFS_NODE_WALLET_PASSWORD=password
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
"shutdown_timeout": "15s"
|
"shutdown_timeout": "15s"
|
||||||
},
|
},
|
||||||
"node": {
|
"node": {
|
||||||
"key": "path/hex/WIF",
|
"key": "./wallet.key",
|
||||||
"wallet": {
|
"wallet": {
|
||||||
"path": "./wallet.json",
|
"path": "./wallet.json",
|
||||||
"address": "NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz",
|
"address": "NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz",
|
||||||
|
|
|
@ -10,7 +10,7 @@ metrics:
|
||||||
shutdown_timeout: 15s
|
shutdown_timeout: 15s
|
||||||
|
|
||||||
node:
|
node:
|
||||||
key: path/hex/WIF
|
key: ./wallet.key
|
||||||
wallet:
|
wallet:
|
||||||
path: "./wallet.json"
|
path: "./wallet.json"
|
||||||
address: "NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz"
|
address: "NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz"
|
||||||
|
|
Loading…
Reference in a new issue