stream: rename FilterByKey

This commit is contained in:
Daniel Nephin 2020-11-05 19:18:37 -05:00
parent d4cd2fa6a8
commit 4fc073b1f4
7 changed files with 13 additions and 15 deletions

View File

@ -4,7 +4,6 @@ import (
memdb "github.com/hashicorp/go-memdb"
"github.com/hashicorp/consul/acl"
"github.com/hashicorp/consul/agent/consul/stream"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/proto/pbsubscribe"
@ -25,7 +24,7 @@ func (e EventPayloadCheckServiceNode) HasReadPermission(authz acl.Authorizer) bo
return e.Value.CanRead(authz) == acl.Allow
}
func (e EventPayloadCheckServiceNode) FilterByKey(key, namespace string) bool {
func (e EventPayloadCheckServiceNode) MatchesKey(key, namespace string) bool {
if key == "" && namespace == "" {
return true
}

View File

@ -1476,7 +1476,7 @@ func TestEventPayloadCheckServiceNode_FilterByKey(t *testing.T) {
t.Skip("cant test namespace matching without namespace support")
}
require.Equal(t, tc.expected, tc.payload.FilterByKey(tc.key, tc.namespace))
require.Equal(t, tc.expected, tc.payload.MatchesKey(tc.key, tc.namespace))
}
var testCases = []testCase{

View File

@ -410,7 +410,7 @@ type nodePayload struct {
node *structs.ServiceNode
}
func (p nodePayload) FilterByKey(key, _ string) bool {
func (p nodePayload) MatchesKey(key, _ string) bool {
return p.key == key
}

View File

@ -23,13 +23,12 @@ type Event struct {
}
type Payload interface {
// FilterByKey must return true if the Payload should be included in a subscription
// MatchesKey must return true if the Payload should be included in a subscription
// requested with the key and namespace.
// Generally this means that the payload matches the key and namespace or
// the payload is a special framing event that should be returned to every
// subscription.
// TODO: rename to MatchesKey
FilterByKey(key, namespace string) bool
MatchesKey(key, namespace string) bool
// HasReadPermission uses the acl.Authorizer to determine if the items in the
// Payload are visible to the request. It returns true if the payload is
@ -74,9 +73,9 @@ func (p *PayloadEvents) filter(f func(Event) bool) bool {
return true
}
func (p *PayloadEvents) FilterByKey(key, namespace string) bool {
func (p *PayloadEvents) MatchesKey(key, namespace string) bool {
return p.filter(func(event Event) bool {
return event.Payload.FilterByKey(key, namespace)
return event.Payload.MatchesKey(key, namespace)
})
}
@ -106,7 +105,7 @@ func (e Event) IsNewSnapshotToFollow() bool {
type framingEvent struct{}
func (framingEvent) FilterByKey(string, string) bool {
func (framingEvent) MatchesKey(string, string) bool {
return true
}
@ -126,7 +125,7 @@ type closeSubscriptionPayload struct {
tokensSecretIDs []string
}
func (closeSubscriptionPayload) FilterByKey(string, string) bool {
func (closeSubscriptionPayload) MatchesKey(string, string) bool {
return false
}

View File

@ -70,7 +70,7 @@ type simplePayload struct {
noReadPerm bool
}
func (p simplePayload) FilterByKey(key, _ string) bool {
func (p simplePayload) MatchesKey(key, _ string) bool {
if key == "" {
return true
}

View File

@ -35,7 +35,7 @@ func TestPayloadEvents_FilterByKey(t *testing.T) {
events = append(events, tc.events...)
pe := &PayloadEvents{Items: events}
ok := pe.FilterByKey(tc.req.Key, tc.req.Namespace)
ok := pe.MatchesKey(tc.req.Key, tc.req.Namespace)
require.Equal(t, tc.expectEvent, ok)
if !tc.expectEvent {
return
@ -144,7 +144,7 @@ type nsPayload struct {
value string
}
func (p nsPayload) FilterByKey(key, namespace string) bool {
func (p nsPayload) MatchesKey(key, namespace string) bool {
return (key == "" || key == p.key) && (namespace == "" || namespace == p.namespace)
}

View File

@ -102,7 +102,7 @@ func (s *Subscription) Next(ctx context.Context) (Event, error) {
continue
}
event := newEventFromBatch(s.req, next.Events)
if !event.Payload.FilterByKey(s.req.Key, s.req.Namespace) {
if !event.Payload.MatchesKey(s.req.Key, s.req.Namespace) {
continue
}
return event, nil