[#1183] node/config: Add notification configuration

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
neofs-adm-notary-disabled
Pavel Karpy 2022-02-17 15:42:32 +03:00 committed by LeL
parent 90ff066940
commit 46cf15f03c
5 changed files with 48 additions and 0 deletions

View File

@ -17,9 +17,16 @@ type PersistentStateConfig struct {
cfg *config.Config
}
// NotificationConfig is a wrapper over "notification" config section
// which provides access to object notification configuration of node.
type NotificationConfig struct {
cfg *config.Config
}
const (
subsection = "node"
persistentStateSubsection = "persistent_state"
notificationSubsection = "notification"
attributePrefix = "attribute"
@ -172,3 +179,27 @@ func (x SubnetConfig) IterateSubnets(f func(string)) {
f(ids[i])
}
}
// Notification returns structure that provides access to "notification"
// subsection of "node" section.
func Notification(c *config.Config) NotificationConfig {
return NotificationConfig{
c.Sub(subsection).Sub(notificationSubsection),
}
}
// Enabled returns value of "enabled" config parameter from "notification"
// subsection of "node" section.
//
// Returns false if value is not presented.
func (n NotificationConfig) Enabled() bool {
return config.BoolSafe(n.cfg, "enabled")
}
// DefaultTopic returns value of "default_topic" config parameter from
// "notification" subsection of "node" section.
//
// Returns empty string if value is not presented.
func (n NotificationConfig) DefaultTopic() string {
return config.StringSafe(n.cfg, "default_topic")
}

View File

@ -31,10 +31,14 @@ func TestNodeSection(t *testing.T) {
attribute := Attributes(empty)
relay := Relay(empty)
persistatePath := PersistentState(empty).Path()
notificationEnabled := Notification(empty).Enabled()
notificationDefaultTopic := Notification(empty).DefaultTopic()
require.Empty(t, attribute)
require.Equal(t, false, relay)
require.Equal(t, PersistentStatePathDefault, persistatePath)
require.Equal(t, false, notificationEnabled)
require.Equal(t, "", notificationDefaultTopic)
var subnetCfg SubnetConfig
@ -60,6 +64,8 @@ func TestNodeSection(t *testing.T) {
relay := Relay(c)
wKey := Wallet(c)
persistatePath := PersistentState(c).Path()
notificationEnabled := Notification(c).Enabled()
notificationDefaultTopic := Notification(c).DefaultTopic()
expectedAddr := []struct {
str string
@ -113,6 +119,8 @@ func TestNodeSection(t *testing.T) {
address.Uint160ToString(wKey.GetScriptHash()))
require.Equal(t, "/state", persistatePath)
require.Equal(t, true, notificationEnabled)
require.Equal(t, "topic", notificationDefaultTopic)
var subnetCfg SubnetConfig

View File

@ -18,6 +18,8 @@ NEOFS_NODE_RELAY=true
NEOFS_NODE_PERSISTENT_STATE_PATH=/state
NEOFS_NODE_SUBNET_EXIT_ZERO=true
NEOFS_NODE_SUBNET_ENTRIES=123 456 789
NEOFS_NODE_NOTIFICATION_ENABLED=true
NEOFS_NODE_NOTIFICATION_DEFAULT_TOPIC=topic
# gRPC section
NEOFS_GRPC_NUM=2

View File

@ -36,6 +36,10 @@
"456",
"789"
]
},
"notification": {
"enabled": true,
"default_topic": "topic"
}
},
"grpc": {

View File

@ -31,6 +31,9 @@ node:
- 123
- 456
- 789
notification:
enabled: true
default_topic: "topic"
grpc:
num: 2 # total number of listener endpoints