From 4fc073b1f47f6de844b67fea587b972a23b22057 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Thu, 5 Nov 2020 19:18:37 -0500 Subject: [PATCH] stream: rename FilterByKey --- agent/consul/state/catalog_events.go | 3 +-- agent/consul/state/catalog_events_test.go | 2 +- agent/consul/state/store_integration_test.go | 2 +- agent/consul/stream/event.go | 13 ++++++------- agent/consul/stream/event_publisher_test.go | 2 +- agent/consul/stream/event_test.go | 4 ++-- agent/consul/stream/subscription.go | 2 +- 7 files changed, 13 insertions(+), 15 deletions(-) diff --git a/agent/consul/state/catalog_events.go b/agent/consul/state/catalog_events.go index 2a410d299..e9968eb64 100644 --- a/agent/consul/state/catalog_events.go +++ b/agent/consul/state/catalog_events.go @@ -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 } diff --git a/agent/consul/state/catalog_events_test.go b/agent/consul/state/catalog_events_test.go index 1efead52a..fb2818c58 100644 --- a/agent/consul/state/catalog_events_test.go +++ b/agent/consul/state/catalog_events_test.go @@ -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{ diff --git a/agent/consul/state/store_integration_test.go b/agent/consul/state/store_integration_test.go index 520913807..fc4d05591 100644 --- a/agent/consul/state/store_integration_test.go +++ b/agent/consul/state/store_integration_test.go @@ -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 } diff --git a/agent/consul/stream/event.go b/agent/consul/stream/event.go index 16a33fca7..1ee316d09 100644 --- a/agent/consul/stream/event.go +++ b/agent/consul/stream/event.go @@ -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 } diff --git a/agent/consul/stream/event_publisher_test.go b/agent/consul/stream/event_publisher_test.go index c9f91fd3d..576d4ccc3 100644 --- a/agent/consul/stream/event_publisher_test.go +++ b/agent/consul/stream/event_publisher_test.go @@ -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 } diff --git a/agent/consul/stream/event_test.go b/agent/consul/stream/event_test.go index 5a9cccea8..e18640d65 100644 --- a/agent/consul/stream/event_test.go +++ b/agent/consul/stream/event_test.go @@ -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) } diff --git a/agent/consul/stream/subscription.go b/agent/consul/stream/subscription.go index 5dc45efdf..795785e42 100644 --- a/agent/consul/stream/subscription.go +++ b/agent/consul/stream/subscription.go @@ -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