forked from TrueCloudLab/frostfs-node
[#1183] node/config: Add NATS configuration
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
79c6f52a27
commit
1e96f62294
5 changed files with 90 additions and 5 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
"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 is a default path for persistent state file.
|
||||||
PersistentStatePathDefault = ".neofs-storage-state"
|
PersistentStatePathDefault = ".neofs-storage-state"
|
||||||
|
|
||||||
|
// NotificationTimeoutDefault is a default timeout for object notification operation.
|
||||||
|
NotificationTimeoutDefault = 5 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
// Key returns value of "key" config parameter
|
// Key returns value of "key" config parameter
|
||||||
|
@ -203,3 +207,48 @@ func (n NotificationConfig) Enabled() bool {
|
||||||
func (n NotificationConfig) DefaultTopic() string {
|
func (n NotificationConfig) DefaultTopic() string {
|
||||||
return config.StringSafe(n.cfg, "default_topic")
|
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")
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package nodeconfig
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
||||||
|
@ -31,14 +32,24 @@ 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()
|
notificationDefaultEnabled := Notification(empty).Enabled()
|
||||||
|
notificationDefaultEndpoint := Notification(empty).Endpoint()
|
||||||
|
notificationDefaultTimeout := Notification(empty).Timeout()
|
||||||
notificationDefaultTopic := Notification(empty).DefaultTopic()
|
notificationDefaultTopic := Notification(empty).DefaultTopic()
|
||||||
|
notificationDefaultCertPath := Notification(empty).CertPath()
|
||||||
|
notificationDefaultKeyPath := Notification(empty).KeyPath()
|
||||||
|
notificationDefaultCAPath := Notification(empty).CAPath()
|
||||||
|
|
||||||
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, false, notificationDefaultEnabled)
|
||||||
|
require.Equal(t, "", notificationDefaultEndpoint)
|
||||||
|
require.Equal(t, NotificationTimeoutDefault, notificationDefaultTimeout)
|
||||||
require.Equal(t, "", notificationDefaultTopic)
|
require.Equal(t, "", notificationDefaultTopic)
|
||||||
|
require.Equal(t, "", notificationDefaultCertPath)
|
||||||
|
require.Equal(t, "", notificationDefaultKeyPath)
|
||||||
|
require.Equal(t, "", notificationDefaultCAPath)
|
||||||
|
|
||||||
var subnetCfg SubnetConfig
|
var subnetCfg SubnetConfig
|
||||||
|
|
||||||
|
@ -65,7 +76,12 @@ func TestNodeSection(t *testing.T) {
|
||||||
wKey := Wallet(c)
|
wKey := Wallet(c)
|
||||||
persistatePath := PersistentState(c).Path()
|
persistatePath := PersistentState(c).Path()
|
||||||
notificationEnabled := Notification(c).Enabled()
|
notificationEnabled := Notification(c).Enabled()
|
||||||
|
notificationEndpoint := Notification(c).Endpoint()
|
||||||
|
notificationTimeout := Notification(c).Timeout()
|
||||||
notificationDefaultTopic := Notification(c).DefaultTopic()
|
notificationDefaultTopic := Notification(c).DefaultTopic()
|
||||||
|
notificationCertPath := Notification(c).CertPath()
|
||||||
|
notificationKeyPath := Notification(c).KeyPath()
|
||||||
|
notificationCAPath := Notification(c).CAPath()
|
||||||
|
|
||||||
expectedAddr := []struct {
|
expectedAddr := []struct {
|
||||||
str string
|
str string
|
||||||
|
@ -120,7 +136,12 @@ func TestNodeSection(t *testing.T) {
|
||||||
|
|
||||||
require.Equal(t, "/state", persistatePath)
|
require.Equal(t, "/state", persistatePath)
|
||||||
require.Equal(t, true, notificationEnabled)
|
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, "topic", notificationDefaultTopic)
|
||||||
|
require.Equal(t, "/cert/path", notificationCertPath)
|
||||||
|
require.Equal(t, "/key/path", notificationKeyPath)
|
||||||
|
require.Equal(t, "/ca/path", notificationCAPath)
|
||||||
|
|
||||||
var subnetCfg SubnetConfig
|
var subnetCfg SubnetConfig
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,12 @@ 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_ENABLED=true
|
||||||
|
NEOFS_NODE_NOTIFICATION_ENDPOINT=tls://localhost:4222
|
||||||
|
NEOFS_NODE_NOTIFICATION_TIMEOUT=6s
|
||||||
NEOFS_NODE_NOTIFICATION_DEFAULT_TOPIC=topic
|
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
|
# gRPC section
|
||||||
NEOFS_GRPC_NUM=2
|
NEOFS_GRPC_NUM=2
|
||||||
|
|
|
@ -39,7 +39,12 @@
|
||||||
},
|
},
|
||||||
"notification": {
|
"notification": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"default_topic": "topic"
|
"endpoint": "tls://localhost:4222",
|
||||||
|
"timeout": "6s",
|
||||||
|
"default_topic": "topic",
|
||||||
|
"certificate": "/cert/path",
|
||||||
|
"key": "/key/path",
|
||||||
|
"ca": "/ca/path"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"grpc": {
|
"grpc": {
|
||||||
|
|
|
@ -32,8 +32,13 @@ node:
|
||||||
- 456
|
- 456
|
||||||
- 789
|
- 789
|
||||||
notification:
|
notification:
|
||||||
enabled: true
|
enabled: true # turn on object notification service
|
||||||
default_topic: "topic"
|
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:
|
grpc:
|
||||||
num: 2 # total number of listener endpoints
|
num: 2 # total number of listener endpoints
|
||||||
|
|
Loading…
Reference in a new issue