forked from TrueCloudLab/frostfs-node
[#562] cmd/neofs-node: use NEP-6 wallet for keys
Also use neo-go private key wrapper where possible, as it already has methods for (un)marshaling. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
1553967328
commit
3f07313604
17 changed files with 119 additions and 53 deletions
|
@ -1,6 +1,9 @@
|
|||
package controlconfig
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
||||
)
|
||||
|
||||
|
@ -18,12 +21,24 @@ const (
|
|||
GRPCEndpointDefault = ""
|
||||
)
|
||||
|
||||
// AuthorizedKeysString returns string array of "authorized_keys" config
|
||||
// AuthorizedKeys parses and returns array of "authorized_keys" config
|
||||
// parameter from "control" section.
|
||||
//
|
||||
// Returns empty list if not set.
|
||||
func AuthorizedKeysString(c *config.Config) []string {
|
||||
return config.StringSliceSafe(c.Sub(subsection), "authorized_keys")
|
||||
func AuthorizedKeys(c *config.Config) keys.PublicKeys {
|
||||
strKeys := config.StringSliceSafe(c.Sub(subsection), "authorized_keys")
|
||||
pubs := make(keys.PublicKeys, 0, len(strKeys))
|
||||
|
||||
for i := range strKeys {
|
||||
pub, err := keys.NewPublicKeyFromString(strKeys[i])
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("invalid permitted key for Control service %s: %w", strKeys[i], err))
|
||||
}
|
||||
|
||||
pubs = append(pubs, pub)
|
||||
}
|
||||
|
||||
return pubs
|
||||
}
|
||||
|
||||
// GRPC returns structure that provides access to "grpc" subsection of
|
||||
|
|
|
@ -3,6 +3,7 @@ package controlconfig_test
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
||||
controlconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/control"
|
||||
configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test"
|
||||
|
@ -13,19 +14,18 @@ func TestControlSection(t *testing.T) {
|
|||
t.Run("defaults", func(t *testing.T) {
|
||||
empty := configtest.EmptyConfig()
|
||||
|
||||
require.Empty(t, controlconfig.AuthorizedKeysString(empty))
|
||||
require.Empty(t, controlconfig.AuthorizedKeys(empty))
|
||||
require.Equal(t, controlconfig.GRPCEndpointDefault, controlconfig.GRPC(empty).Endpoint())
|
||||
})
|
||||
|
||||
const path = "../../../../config/example/node"
|
||||
|
||||
var keys = []string{
|
||||
"035839e45d472a3b7769a2a1bd7d54c4ccd4943c3b40f547870e83a8fcbfb3ce11",
|
||||
"028f42cfcb74499d7b15b35d9bff260a1c8d27de4f446a627406a382d8961486d6",
|
||||
}
|
||||
pubs := make(keys.PublicKeys, 2)
|
||||
pubs[0], _ = keys.NewPublicKeyFromString("035839e45d472a3b7769a2a1bd7d54c4ccd4943c3b40f547870e83a8fcbfb3ce11")
|
||||
pubs[1], _ = keys.NewPublicKeyFromString("028f42cfcb74499d7b15b35d9bff260a1c8d27de4f446a627406a382d8961486d6")
|
||||
|
||||
var fileConfigTest = func(c *config.Config) {
|
||||
require.Equal(t, keys, controlconfig.AuthorizedKeysString(c))
|
||||
require.Equal(t, pubs, controlconfig.AuthorizedKeys(c))
|
||||
require.Equal(t, "127.0.0.1:8090", controlconfig.GRPC(c).Endpoint())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue