From 1e96f62294775c0579ce68c0bc4121245f6b6b0d Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Mon, 1 Mar 2021 14:55:03 +0300 Subject: [PATCH] [#1183] node/config: Add NATS configuration Signed-off-by: Pavel Karpy --- cmd/neofs-node/config/node/config.go | 49 +++++++++++++++++++++++ cmd/neofs-node/config/node/config_test.go | 25 +++++++++++- config/example/node.env | 5 +++ config/example/node.json | 7 +++- config/example/node.yaml | 9 ++++- 5 files changed, 90 insertions(+), 5 deletions(-) diff --git a/cmd/neofs-node/config/node/config.go b/cmd/neofs-node/config/node/config.go index 2a3b94aa..37408743 100644 --- a/cmd/neofs-node/config/node/config.go +++ b/cmd/neofs-node/config/node/config.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "strconv" + "time" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" @@ -32,6 +33,9 @@ const ( // PersistentStatePathDefault is a default path for persistent state file. PersistentStatePathDefault = ".neofs-storage-state" + + // NotificationTimeoutDefault is a default timeout for object notification operation. + NotificationTimeoutDefault = 5 * time.Second ) // Key returns value of "key" config parameter @@ -203,3 +207,48 @@ func (n NotificationConfig) Enabled() bool { func (n NotificationConfig) DefaultTopic() string { return config.StringSafe(n.cfg, "default_topic") } + +// Endpoint returns value of "endpoint" config parameter from "notification" +// subsection of "node" section. +// +// Returns empty string if value is not presented. +func (n NotificationConfig) Endpoint() string { + return config.StringSafe(n.cfg, "endpoint") +} + +// Timeout returns value of "timeout" config parameter from "notification" +// subsection of "node" section. +// +// Returns NotificationTimeoutDefault if value is not positive. +func (n NotificationConfig) Timeout() time.Duration { + v := config.DurationSafe(n.cfg, "timeout") + if v > 0 { + return v + } + + return NotificationTimeoutDefault +} + +// CertPath returns value of "certificate_path" config parameter from "notification" +// subsection of "node" section. +// +// Returns empty string if value is not presented. +func (n NotificationConfig) CertPath() string { + return config.StringSafe(n.cfg, "certificate") +} + +// KeyPath returns value of "key_path" config parameter from +// "notification" subsection of "node" section. +// +// Returns empty string if value is not presented. +func (n NotificationConfig) KeyPath() string { + return config.StringSafe(n.cfg, "key") +} + +// CAPath returns value of "ca_path" config parameter from +// "notification" subsection of "node" section. +// +// Returns empty string if value is not presented. +func (n NotificationConfig) CAPath() string { + return config.StringSafe(n.cfg, "ca") +} diff --git a/cmd/neofs-node/config/node/config_test.go b/cmd/neofs-node/config/node/config_test.go index 7b97ed5f..805ab790 100644 --- a/cmd/neofs-node/config/node/config_test.go +++ b/cmd/neofs-node/config/node/config_test.go @@ -2,6 +2,7 @@ package nodeconfig import ( "testing" + "time" "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" @@ -31,14 +32,24 @@ func TestNodeSection(t *testing.T) { attribute := Attributes(empty) relay := Relay(empty) persistatePath := PersistentState(empty).Path() - notificationEnabled := Notification(empty).Enabled() + notificationDefaultEnabled := Notification(empty).Enabled() + notificationDefaultEndpoint := Notification(empty).Endpoint() + notificationDefaultTimeout := Notification(empty).Timeout() notificationDefaultTopic := Notification(empty).DefaultTopic() + notificationDefaultCertPath := Notification(empty).CertPath() + notificationDefaultKeyPath := Notification(empty).KeyPath() + notificationDefaultCAPath := Notification(empty).CAPath() require.Empty(t, attribute) require.Equal(t, false, relay) require.Equal(t, PersistentStatePathDefault, persistatePath) - require.Equal(t, false, notificationEnabled) + require.Equal(t, false, notificationDefaultEnabled) + require.Equal(t, "", notificationDefaultEndpoint) + require.Equal(t, NotificationTimeoutDefault, notificationDefaultTimeout) require.Equal(t, "", notificationDefaultTopic) + require.Equal(t, "", notificationDefaultCertPath) + require.Equal(t, "", notificationDefaultKeyPath) + require.Equal(t, "", notificationDefaultCAPath) var subnetCfg SubnetConfig @@ -65,7 +76,12 @@ func TestNodeSection(t *testing.T) { wKey := Wallet(c) persistatePath := PersistentState(c).Path() notificationEnabled := Notification(c).Enabled() + notificationEndpoint := Notification(c).Endpoint() + notificationTimeout := Notification(c).Timeout() notificationDefaultTopic := Notification(c).DefaultTopic() + notificationCertPath := Notification(c).CertPath() + notificationKeyPath := Notification(c).KeyPath() + notificationCAPath := Notification(c).CAPath() expectedAddr := []struct { str string @@ -120,7 +136,12 @@ func TestNodeSection(t *testing.T) { require.Equal(t, "/state", persistatePath) require.Equal(t, true, notificationEnabled) + require.Equal(t, "tls://localhost:4222", notificationEndpoint) + require.Equal(t, 6*time.Second, notificationTimeout) require.Equal(t, "topic", notificationDefaultTopic) + require.Equal(t, "/cert/path", notificationCertPath) + require.Equal(t, "/key/path", notificationKeyPath) + require.Equal(t, "/ca/path", notificationCAPath) var subnetCfg SubnetConfig diff --git a/config/example/node.env b/config/example/node.env index fc0e94df..06ef1fba 100644 --- a/config/example/node.env +++ b/config/example/node.env @@ -19,7 +19,12 @@ 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_ENDPOINT=tls://localhost:4222 +NEOFS_NODE_NOTIFICATION_TIMEOUT=6s NEOFS_NODE_NOTIFICATION_DEFAULT_TOPIC=topic +NEOFS_NODE_NOTIFICATION_CERTIFICATE=/cert/path +NEOFS_NODE_NOTIFICATION_KEY=/key/path +NEOFS_NODE_NOTIFICATION_CA=/ca/path # gRPC section NEOFS_GRPC_NUM=2 diff --git a/config/example/node.json b/config/example/node.json index a2df1752..18b4e003 100644 --- a/config/example/node.json +++ b/config/example/node.json @@ -39,7 +39,12 @@ }, "notification": { "enabled": true, - "default_topic": "topic" + "endpoint": "tls://localhost:4222", + "timeout": "6s", + "default_topic": "topic", + "certificate": "/cert/path", + "key": "/key/path", + "ca": "/ca/path" } }, "grpc": { diff --git a/config/example/node.yaml b/config/example/node.yaml index 7998700a..1327bb89 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -32,8 +32,13 @@ node: - 456 - 789 notification: - enabled: true - default_topic: "topic" + enabled: true # turn on object notification service + endpoint: "tls://localhost:4222" # notification server endpoint + timeout: "6s" # timeout for object notification client connection + default_topic: "topic" # default topic for object notifications if not found in object's meta + certificate: "/cert/path" # path to TLS certificate + key: "/key/path" # path to TLS key + ca: "/ca/path" # path to optional CA certificate grpc: num: 2 # total number of listener endpoints