Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 54 additions & 54 deletions router/broker.go → router/broker/broker.go

Large diffs are not rendered by default.

133 changes: 73 additions & 60 deletions router/broker_test.go → router/broker/broker_test.go

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions router/broker/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package broker

import (
"github.com/gammazero/nexus/v3/wamp"
)

type TopicEventHistoryConfig struct {
Topic wamp.URI `json:"topic"` // Topic URI
MatchPolicy string `json:"match"` // Matching policy (exact|prefix|wildcard)
Limit int `json:"limit"` // Number of most recent events to store
}
2 changes: 1 addition & 1 deletion router/publishfilter.go → router/broker/publishfilter.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package router
package broker

import (
"slices"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package router //nolint:testpackage
package broker_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/gammazero/nexus/v3/router/broker"
"github.com/gammazero/nexus/v3/wamp"
)

func TestFilterBlacklist(t *testing.T) {
const (
shouldAllowMsg = "Publish to session should be allowed"
shouldDenyMsg = "Publish to session should be denied"
)
const (
shouldAllowMsg = "Publish to session should be allowed"
shouldDenyMsg = "Publish to session should be denied"
)

func TestFilterBlacklist(t *testing.T) {
allowedID := wamp.ID(1234)
allowedAuthid := "root"
allowedAuthrole := "admin"
Expand All @@ -32,7 +33,7 @@ func TestFilterBlacklist(t *testing.T) {
Topic: wamp.URI("blacklist.test"),
}

pf := NewSimplePublishFilter(pub)
pf := broker.NewSimplePublishFilter(pub)

details := wamp.Dict{
"authid": allowedAuthid,
Expand Down Expand Up @@ -62,11 +63,6 @@ func TestFilterBlacklist(t *testing.T) {
}

func TestFilterWhitelist(t *testing.T) {
const (
shouldAllowMsg = "Publish to session should be allowed"
shouldDenyMsg = "Publish to session should be denied"
)

allowedID := wamp.ID(1234)
allowedAuthid := "root"
allowedAuthrole := "admin"
Expand All @@ -85,7 +81,7 @@ func TestFilterWhitelist(t *testing.T) {
Topic: wamp.URI("whitelist.test"),
}

pf := NewSimplePublishFilter(pub)
pf := broker.NewSimplePublishFilter(pub)

details := wamp.Dict{
"authid": allowedAuthid,
Expand Down Expand Up @@ -115,11 +111,6 @@ func TestFilterWhitelist(t *testing.T) {
}

func TestFilterBlackWhitelistPrecedence(t *testing.T) {
const (
shouldAllowMsg = "Publish to session should be allowed"
shouldDenyMsg = "Publish to session should be denied"
)

allowedID := wamp.ID(1234)
allowedAuthid := "root"
allowedAuthrole := "admin"
Expand All @@ -141,7 +132,7 @@ func TestFilterBlackWhitelistPrecedence(t *testing.T) {
Topic: wamp.URI("whitelist.test"),
}

pf := NewSimplePublishFilter(pub)
pf := broker.NewSimplePublishFilter(pub)

details := wamp.Dict{
"authid": allowedAuthid,
Expand Down
11 changes: 3 additions & 8 deletions router/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package router

import (
"github.com/gammazero/nexus/v3/router/auth"
"github.com/gammazero/nexus/v3/router/broker"
"github.com/gammazero/nexus/v3/wamp"
)

Expand Down Expand Up @@ -72,18 +73,12 @@ type RealmConfig struct {
// logic when it may not be needed otherwise.
EnableMetaModify bool `json:"enable_meta_modify"`

TopicEventHistoryConfigs []*TopicEventHistoryConfig `json:"event_history"`
TopicEventHistoryConfigs []*broker.TopicEventHistoryConfig `json:"event_history"`

// PublishFilterFactory is a function used to create a PublishFilter to
// check which sessions a publication should be sent to.
//
// This value is not set via json config, but is configured when embedding
// nexus. A value of nil enables the default filtering.
PublishFilterFactory FilterFactory
}

type TopicEventHistoryConfig struct {
Topic wamp.URI `json:"topic"` // Topic URI
MatchPolicy string `json:"match"` // Matching policy (exact|prefix|wildcard)
Limit int `json:"limit"` // Number of most recent events to store
PublishFilterFactory broker.FilterFactory
}
Loading