[#36] Parse attributes from node config

Well-known attributes set up with explicit configuration
values, other attributes set up from chain of attributes.

Chain of attributes is a string, that contains keys-value pairs,
divided by semicolon. Pairs itself divided by slash.

E.g. "StorageType:HDD/RPM:7200"

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-09-22 14:02:32 +03:00
parent 28534a509d
commit 1759ff57f1
2 changed files with 40 additions and 6 deletions

View file

@ -1,10 +1,12 @@
package main
import (
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/util/attributes"
"github.com/pkg/errors"
)
@ -30,10 +32,15 @@ func bootstrapNode(c *cfg) {
cliWrapper, err := wrapper.New(cli)
fatalOnErr(errors.Wrap(err, "bootstrap error"))
peerInfo := new(netmap.NodeInfo)
attrs, err := attributes.ParseV2Attributes(c.cfgNodeInfo.attributes, nil)
if err != nil {
fatalOnErr(errors.Wrap(err, "bootstrap attribute error"))
}
peerInfo := new(v2netmap.NodeInfo)
peerInfo.SetAddress(c.viper.GetString(cfgBootstrapAddress))
peerInfo.SetPublicKey(crypto.MarshalPublicKey(&c.key.PublicKey))
// todo: add attributes as opts
peerInfo.SetAttributes(attrs)
err = cliWrapper.AddPeer(peerInfo)
fatalOnErr(errors.Wrap(err, "bootstrap error"))