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"
|
||||
"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")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue