Skip to content

Commit 697b861

Browse files
authored
chore: there are access filters which also can't added by Consumer (#579)
This commit just changes err msg & field names. Signed-off-by: spacewander <spacewanderlzx@gmail.com> --------- Signed-off-by: spacewander <spacewanderlzx@gmail.com>
1 parent c90c33e commit 697b861

5 files changed

Lines changed: 12 additions & 29 deletions

File tree

api/pkg/filtermanager/filtermanager.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ func (p *FilterManagerConfigParser) Merge(parent interface{}, child interface{})
247247
}
248248

249249
type filterManager struct {
250-
filters []*model.FilterWrapper
251-
consumerFilters []*model.FilterWrapper
250+
filters []*model.FilterWrapper
251+
filtersNotAfterConsumer []*model.FilterWrapper
252252

253253
decodeRequestNeeded bool
254254
decodeIdx int
@@ -274,7 +274,7 @@ type filterManager struct {
274274

275275
func (m *filterManager) Reset() {
276276
m.filters = nil
277-
m.consumerFilters = nil
277+
m.filtersNotAfterConsumer = nil
278278

279279
m.decodeRequestNeeded = false
280280
m.decodeIdx = -1
@@ -539,8 +539,8 @@ func FilterManagerFactory(c interface{}) capi.StreamFilterFactory {
539539

540540
if conf.consumerFiltersEndAt != 0 {
541541
consumerFiltersEndAt := conf.consumerFiltersEndAt
542-
consumerFilters := filters[:consumerFiltersEndAt]
543-
fm.consumerFilters = consumerFilters
542+
filtersNotAfterConsumer := filters[:consumerFiltersEndAt]
543+
fm.filtersNotAfterConsumer = filtersNotAfterConsumer
544544
fm.filters = filters[consumerFiltersEndAt:]
545545
}
546546

@@ -645,9 +645,9 @@ func (m *filterManager) DecodeHeaders(headers capi.RequestHeaderMap, endStream b
645645
RequestHeaderMap: headers,
646646
}
647647
m.reqHdr = headers
648-
if len(m.consumerFilters) > 0 {
649-
for _, f := range m.consumerFilters {
650-
// Consumer plugins only use DecodeHeaders for now
648+
if len(m.filtersNotAfterConsumer) > 0 {
649+
for _, f := range m.filtersNotAfterConsumer {
650+
// these filters only use DecodeHeaders for now
651651
res = f.DecodeHeaders(headers, endStream)
652652
if m.handleAction(res, phaseDecodeHeaders) {
653653
return

api/pkg/plugins/plugins.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ const (
6464
errInvalidGoPluginOrder = "invalid plugin order position: Go plugin should not use OrderPositionOuter or OrderPositionInner"
6565
errInvalidNativePluginOrder = "invalid plugin order position: Native plugin should use OrderPositionOuter or OrderPositionInner"
6666
errInvalidConsumerPluginOrder = "invalid plugin order position: Consumer plugin should use OrderPositionAuthn"
67-
errAuthnPluginOrder = "Authn plugin should run in the DecodeHeaders phase"
6867
errDecodeRequestUnsatified = "DecodeRequest is run only after DecodeHeaders returns WaitAllData. So DecodeHeaders should be defined in this plugin."
6968
errEncodeResponseUnsatified = "EncodeResponse is run only after EncodeHeaders returns WaitAllData. So EncodeHeaders should be defined in this plugin."
7069
)

controller/tests/integration/controller/httpfilterpolicy_controller_gateway_test.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,7 @@ var _ = Describe("HTTPFilterPolicy controller, for gateway", func() {
186186
if len(policy.Status.Conditions) == 0 {
187187
return false
188188
}
189-
if policy.Name == "policy" {
190-
if policy.Status.Conditions[0].Reason != string(gwapiv1a2.PolicyReasonAccepted) {
191-
return false
192-
}
193-
} else {
189+
if policy.Name != "policy" {
194190
if policy.Status.Conditions[0].Reason != string(gwapiv1a2.PolicyReasonTargetNotFound) {
195191
return false
196192
}
@@ -263,10 +259,6 @@ var _ = Describe("HTTPFilterPolicy controller, for gateway", func() {
263259
if policy.Status.Conditions[0].Reason != string(gwapiv1a2.PolicyReasonTargetNotFound) {
264260
return false
265261
}
266-
} else {
267-
if policy.Status.Conditions[0].Reason != string(gwapiv1a2.PolicyReasonAccepted) {
268-
return false
269-
}
270262
}
271263
}
272264
return true
@@ -391,11 +383,7 @@ var _ = Describe("HTTPFilterPolicy controller, for gateway", func() {
391383
if len(policy.Status.Conditions) == 0 {
392384
return false
393385
}
394-
if policy.Name == "policy" {
395-
if policy.Status.Conditions[0].Reason != string(gwapiv1a2.PolicyReasonAccepted) {
396-
return false
397-
}
398-
} else {
386+
if policy.Name != "policy" {
399387
if policy.Status.Conditions[0].Reason != string(gwapiv1a2.PolicyReasonTargetNotFound) {
400388
return false
401389
}
@@ -469,10 +457,6 @@ var _ = Describe("HTTPFilterPolicy controller, for gateway", func() {
469457
if policy.Status.Conditions[0].Reason != string(gwapiv1a2.PolicyReasonTargetNotFound) {
470458
return false
471459
}
472-
} else {
473-
if policy.Status.Conditions[0].Reason != string(gwapiv1a2.PolicyReasonAccepted) {
474-
return false
475-
}
476460
}
477461
}
478462
return true

types/apis/v1/validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func ValidateConsumer(c *Consumer) error {
229229

230230
pos := p.Order().Position
231231
if pos <= plugins.OrderPositionAuthn || pos >= plugins.OrderPositionInner {
232-
return errors.New("http filter should not in authn/pre/post position: " + name)
232+
return errors.New("this http filter can not be added by the consumer: " + name)
233233
}
234234

235235
data := filter.Config.Raw

types/apis/v1/validation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ func TestValidateConsumer(t *testing.T) {
543543
},
544544
},
545545
},
546-
err: "http filter should not in authn/pre/post position: keyAuth",
546+
err: "this http filter can not be added by the consumer: keyAuth",
547547
},
548548
}
549549

0 commit comments

Comments
 (0)