Skip to content

Commit

Permalink
chore: there are access filters which also can't added by Consumer (#579
Browse files Browse the repository at this point in the history
)

This commit just changes err msg & field names.
Signed-off-by: spacewander <spacewanderlzx@gmail.com>

---------

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
  • Loading branch information
spacewander committed Jun 14, 2024
1 parent c90c33e commit 697b861
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 29 deletions.
16 changes: 8 additions & 8 deletions api/pkg/filtermanager/filtermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ func (p *FilterManagerConfigParser) Merge(parent interface{}, child interface{})
}

type filterManager struct {
filters []*model.FilterWrapper
consumerFilters []*model.FilterWrapper
filters []*model.FilterWrapper
filtersNotAfterConsumer []*model.FilterWrapper

decodeRequestNeeded bool
decodeIdx int
Expand All @@ -274,7 +274,7 @@ type filterManager struct {

func (m *filterManager) Reset() {
m.filters = nil
m.consumerFilters = nil
m.filtersNotAfterConsumer = nil

m.decodeRequestNeeded = false
m.decodeIdx = -1
Expand Down Expand Up @@ -539,8 +539,8 @@ func FilterManagerFactory(c interface{}) capi.StreamFilterFactory {

if conf.consumerFiltersEndAt != 0 {
consumerFiltersEndAt := conf.consumerFiltersEndAt
consumerFilters := filters[:consumerFiltersEndAt]
fm.consumerFilters = consumerFilters
filtersNotAfterConsumer := filters[:consumerFiltersEndAt]
fm.filtersNotAfterConsumer = filtersNotAfterConsumer
fm.filters = filters[consumerFiltersEndAt:]
}

Expand Down Expand Up @@ -645,9 +645,9 @@ func (m *filterManager) DecodeHeaders(headers capi.RequestHeaderMap, endStream b
RequestHeaderMap: headers,
}
m.reqHdr = headers
if len(m.consumerFilters) > 0 {
for _, f := range m.consumerFilters {
// Consumer plugins only use DecodeHeaders for now
if len(m.filtersNotAfterConsumer) > 0 {
for _, f := range m.filtersNotAfterConsumer {
// these filters only use DecodeHeaders for now
res = f.DecodeHeaders(headers, endStream)
if m.handleAction(res, phaseDecodeHeaders) {
return
Expand Down
1 change: 0 additions & 1 deletion api/pkg/plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const (
errInvalidGoPluginOrder = "invalid plugin order position: Go plugin should not use OrderPositionOuter or OrderPositionInner"
errInvalidNativePluginOrder = "invalid plugin order position: Native plugin should use OrderPositionOuter or OrderPositionInner"
errInvalidConsumerPluginOrder = "invalid plugin order position: Consumer plugin should use OrderPositionAuthn"
errAuthnPluginOrder = "Authn plugin should run in the DecodeHeaders phase"
errDecodeRequestUnsatified = "DecodeRequest is run only after DecodeHeaders returns WaitAllData. So DecodeHeaders should be defined in this plugin."
errEncodeResponseUnsatified = "EncodeResponse is run only after EncodeHeaders returns WaitAllData. So EncodeHeaders should be defined in this plugin."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,7 @@ var _ = Describe("HTTPFilterPolicy controller, for gateway", func() {
if len(policy.Status.Conditions) == 0 {
return false
}
if policy.Name == "policy" {
if policy.Status.Conditions[0].Reason != string(gwapiv1a2.PolicyReasonAccepted) {
return false
}
} else {
if policy.Name != "policy" {
if policy.Status.Conditions[0].Reason != string(gwapiv1a2.PolicyReasonTargetNotFound) {
return false
}
Expand Down Expand Up @@ -263,10 +259,6 @@ var _ = Describe("HTTPFilterPolicy controller, for gateway", func() {
if policy.Status.Conditions[0].Reason != string(gwapiv1a2.PolicyReasonTargetNotFound) {
return false
}
} else {
if policy.Status.Conditions[0].Reason != string(gwapiv1a2.PolicyReasonAccepted) {
return false
}
}
}
return true
Expand Down Expand Up @@ -391,11 +383,7 @@ var _ = Describe("HTTPFilterPolicy controller, for gateway", func() {
if len(policy.Status.Conditions) == 0 {
return false
}
if policy.Name == "policy" {
if policy.Status.Conditions[0].Reason != string(gwapiv1a2.PolicyReasonAccepted) {
return false
}
} else {
if policy.Name != "policy" {
if policy.Status.Conditions[0].Reason != string(gwapiv1a2.PolicyReasonTargetNotFound) {
return false
}
Expand Down Expand Up @@ -469,10 +457,6 @@ var _ = Describe("HTTPFilterPolicy controller, for gateway", func() {
if policy.Status.Conditions[0].Reason != string(gwapiv1a2.PolicyReasonTargetNotFound) {
return false
}
} else {
if policy.Status.Conditions[0].Reason != string(gwapiv1a2.PolicyReasonAccepted) {
return false
}
}
}
return true
Expand Down
2 changes: 1 addition & 1 deletion types/apis/v1/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func ValidateConsumer(c *Consumer) error {

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

data := filter.Config.Raw
Expand Down
2 changes: 1 addition & 1 deletion types/apis/v1/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ func TestValidateConsumer(t *testing.T) {
},
},
},
err: "http filter should not in authn/pre/post position: keyAuth",
err: "this http filter can not be added by the consumer: keyAuth",
},
}

Expand Down

0 comments on commit 697b861

Please sign in to comment.