From 46cf15f03ca9286cb99427b8533250651e39b090 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 17 Feb 2022 15:42:32 +0300 Subject: [PATCH] [#1183] node/config: Add notification configuration Signed-off-by: Pavel Karpy --- cmd/neofs-node/config/node/config.go | 31 +++++++++++++++++++++++ cmd/neofs-node/config/node/config_test.go | 8 ++++++ config/example/node.env | 2 ++ config/example/node.json | 4 +++ config/example/node.yaml | 3 +++ 5 files changed, 48 insertions(+) diff --git a/cmd/neofs-node/config/node/config.go b/cmd/neofs-node/config/node/config.go index adabeb1627..2a3b94aa4c 100644 --- a/cmd/neofs-node/config/node/config.go +++ b/cmd/neofs-node/config/node/config.go @@ -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") +} diff --git a/cmd/neofs-node/config/node/config_test.go b/cmd/neofs-node/config/node/config_test.go index 827b57a79a..7b97ed5f24 100644 --- a/cmd/neofs-node/config/node/config_test.go +++ b/cmd/neofs-node/config/node/config_test.go @@ -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 diff --git a/config/example/node.env b/config/example/node.env index 6eb0b10350..fc0e94dfb6 100644 --- a/config/example/node.env +++ b/config/example/node.env @@ -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 diff --git a/config/example/node.json b/config/example/node.json index 4a49cddd95..a2df175293 100644 --- a/config/example/node.json +++ b/config/example/node.json @@ -36,6 +36,10 @@ "456", "789" ] + }, + "notification": { + "enabled": true, + "default_topic": "topic" } }, "grpc": { diff --git a/config/example/node.yaml b/config/example/node.yaml index 48820481df..7998700a57 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -31,6 +31,9 @@ node: - 123 - 456 - 789 + notification: + enabled: true + default_topic: "topic" grpc: num: 2 # total number of listener endpoints