[#1183] node/config: Add notification configuration

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
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 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 ( const (
subsection = "node" subsection = "node"
persistentStateSubsection = "persistent_state" persistentStateSubsection = "persistent_state"
notificationSubsection = "notification"
attributePrefix = "attribute" attributePrefix = "attribute"
@ -172,3 +179,27 @@ func (x SubnetConfig) IterateSubnets(f func(string)) {
f(ids[i]) 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) attribute := Attributes(empty)
relay := Relay(empty) relay := Relay(empty)
persistatePath := PersistentState(empty).Path() persistatePath := PersistentState(empty).Path()
notificationEnabled := Notification(empty).Enabled()
notificationDefaultTopic := Notification(empty).DefaultTopic()
require.Empty(t, attribute) require.Empty(t, attribute)
require.Equal(t, false, relay) require.Equal(t, false, relay)
require.Equal(t, PersistentStatePathDefault, persistatePath) require.Equal(t, PersistentStatePathDefault, persistatePath)
require.Equal(t, false, notificationEnabled)
require.Equal(t, "", notificationDefaultTopic)
var subnetCfg SubnetConfig var subnetCfg SubnetConfig
@ -60,6 +64,8 @@ func TestNodeSection(t *testing.T) {
relay := Relay(c) relay := Relay(c)
wKey := Wallet(c) wKey := Wallet(c)
persistatePath := PersistentState(c).Path() persistatePath := PersistentState(c).Path()
notificationEnabled := Notification(c).Enabled()
notificationDefaultTopic := Notification(c).DefaultTopic()
expectedAddr := []struct { expectedAddr := []struct {
str string str string
@ -113,6 +119,8 @@ func TestNodeSection(t *testing.T) {
address.Uint160ToString(wKey.GetScriptHash())) address.Uint160ToString(wKey.GetScriptHash()))
require.Equal(t, "/state", persistatePath) require.Equal(t, "/state", persistatePath)
require.Equal(t, true, notificationEnabled)
require.Equal(t, "topic", notificationDefaultTopic)
var subnetCfg SubnetConfig var subnetCfg SubnetConfig

View file

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

View file

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

View file

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