[#1183] node/config: Add NATS configuration

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-03-01 14:55:03 +03:00 committed by Alex Vanin
parent 79c6f52a27
commit 1e96f62294
5 changed files with 90 additions and 5 deletions

View file

@ -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")
}

View file

@ -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

View file

@ -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

View file

@ -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": {

View file

@ -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