forked from TrueCloudLab/frostfs-node
[#798] neofs-node/config: Add persistent_state section
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
005f54e61e
commit
cdb3b71070
5 changed files with 43 additions and 2 deletions
|
@ -11,10 +11,20 @@ import (
|
|||
utilConfig "github.com/nspcc-dev/neofs-node/pkg/util/config"
|
||||
)
|
||||
|
||||
// PersistentStateConfig is a wrapper over "persistent_state" config section
|
||||
// which provides access to persistent state storage configuration of node.
|
||||
type PersistentStateConfig struct {
|
||||
cfg *config.Config
|
||||
}
|
||||
|
||||
const (
|
||||
subsection = "node"
|
||||
subsection = "node"
|
||||
persistentStateSubsection = "persistent_state"
|
||||
|
||||
attributePrefix = "attribute"
|
||||
|
||||
// PersistentStatePathDefault is a default path for persistent state file.
|
||||
PersistentStatePathDefault = ".neofs-storage-state"
|
||||
)
|
||||
|
||||
// Key returns value of "key" config parameter
|
||||
|
@ -115,3 +125,23 @@ func Attributes(c *config.Config) (attrs []string) {
|
|||
func Relay(c *config.Config) bool {
|
||||
return config.BoolSafe(c.Sub(subsection), "relay")
|
||||
}
|
||||
|
||||
// PersistentState returns structure that provides access to "persistent_state"
|
||||
// subsection of "node" section.
|
||||
func PersistentState(c *config.Config) PersistentStateConfig {
|
||||
return PersistentStateConfig{
|
||||
c.Sub(subsection).Sub(persistentStateSubsection),
|
||||
}
|
||||
}
|
||||
|
||||
// Path returns value of "path" config parameter.
|
||||
//
|
||||
// Returns PersistentStatePathDefault if value is not a non-empty string.
|
||||
func (p PersistentStateConfig) Path() string {
|
||||
v := config.String(p.cfg, "path")
|
||||
if v != "" {
|
||||
return v
|
||||
}
|
||||
|
||||
return PersistentStatePathDefault
|
||||
}
|
||||
|
|
|
@ -30,9 +30,11 @@ func TestNodeSection(t *testing.T) {
|
|||
|
||||
attribute := Attributes(empty)
|
||||
relay := Relay(empty)
|
||||
persistatePath := PersistentState(empty).Path()
|
||||
|
||||
require.Empty(t, attribute)
|
||||
require.Equal(t, false, relay)
|
||||
require.Equal(t, PersistentStatePathDefault, persistatePath)
|
||||
})
|
||||
|
||||
const path = "../../../../config/example/node"
|
||||
|
@ -43,6 +45,7 @@ func TestNodeSection(t *testing.T) {
|
|||
attributes := Attributes(c)
|
||||
relay := Relay(c)
|
||||
wKey := Wallet(c)
|
||||
persistatePath := PersistentState(c).Path()
|
||||
|
||||
expectedAddr := []struct {
|
||||
str string
|
||||
|
@ -94,6 +97,8 @@ func TestNodeSection(t *testing.T) {
|
|||
require.Equal(t,
|
||||
config.StringSafe(c.Sub("node").Sub("wallet"), "address"),
|
||||
address.Uint160ToString(wKey.GetScriptHash()))
|
||||
|
||||
require.Equal(t, "/state", persistatePath)
|
||||
}
|
||||
|
||||
configtest.ForEachFileType(path, fileConfigTest)
|
||||
|
|
|
@ -15,6 +15,7 @@ NEOFS_NODE_ADDRESSES=s01.neofs.devenv:8080 /dns4/s02.neofs.devenv/tcp/8081 grpc:
|
|||
NEOFS_NODE_ATTRIBUTE_0=Price:11
|
||||
NEOFS_NODE_ATTRIBUTE_1=UN-LOCODE:RU MSK
|
||||
NEOFS_NODE_RELAY=true
|
||||
NEOFS_NODE_PERSISTENT_STATE_PATH=/state
|
||||
|
||||
# gRPC section
|
||||
NEOFS_GRPC_NUM=2
|
||||
|
|
|
@ -25,7 +25,10 @@
|
|||
],
|
||||
"attribute_0": "Price:11",
|
||||
"attribute_1": "UN-LOCODE:RU MSK",
|
||||
"relay": true
|
||||
"relay": true,
|
||||
"persistent_state": {
|
||||
"path": "/state"
|
||||
}
|
||||
},
|
||||
"grpc": {
|
||||
"num": 2,
|
||||
|
|
|
@ -23,6 +23,8 @@ node:
|
|||
attribute_0: "Price:11"
|
||||
attribute_1: UN-LOCODE:RU MSK
|
||||
relay: true
|
||||
persistent_state:
|
||||
path: /state
|
||||
|
||||
grpc:
|
||||
num: 2
|
||||
|
|
Loading…
Reference in a new issue