stream: rename FilterByKey
This commit is contained in:
parent
d4cd2fa6a8
commit
4fc073b1f4
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue