3
0

Prevent API GW filters from overwriting the same registry struct

This commit is contained in:
Tomaž Jerman 2021-09-27 14:11:40 +02:00
parent f9398a6ebf
commit 52e0e838e9
8 changed files with 35 additions and 1 deletions

View File

@ -61,6 +61,10 @@ func NewRedirection() (e *redirection) {
return
}
func (h redirection) New() types.Handler {
return NewRedirection()
}
func (h redirection) String() string {
return fmt.Sprintf("apigw filter %s (%s)", h.Name, h.Label)
}
@ -109,6 +113,10 @@ func NewDefaultJsonResponse() (e *defaultJsonResponse) {
return
}
func (h defaultJsonResponse) New() types.Handler {
return NewDefaultJsonResponse()
}
func (h defaultJsonResponse) String() string {
return fmt.Sprintf("apigw filter %s (%s)", h.Name, h.Label)
}

View File

@ -56,6 +56,10 @@ func NewHeader() (v *header) {
return
}
func (h header) New() types.Handler {
return NewHeader()
}
func (h header) String() string {
return fmt.Sprintf("apigw filter %s (%s)", h.Name, h.Label)
}
@ -133,6 +137,10 @@ func NewQueryParam() (v *queryParam) {
return
}
func (h queryParam) New() types.Handler {
return NewQueryParam()
}
func (h queryParam) String() string {
return fmt.Sprintf("apigw filter %s (%s)", h.Name, h.Label)
}

View File

@ -66,6 +66,10 @@ func NewWorkflow(wf WfExecer) (p *workflow) {
return
}
func (h workflow) New() types.Handler {
return NewWorkflow(h.d)
}
func (h workflow) String() string {
return fmt.Sprintf("apigw filter %s (%s)", h.Name, h.Label)
}
@ -185,6 +189,10 @@ func NewPayload(l *zap.Logger) (p *processerPayload) {
return
}
func (h processerPayload) New() types.Handler {
return NewPayload(h.log)
}
func (h processerPayload) String() string {
return fmt.Sprintf("apigw filter %s (%s)", h.Name, h.Label)
}

View File

@ -67,6 +67,10 @@ func New(l *zap.Logger, c *http.Client, s types.SecureStorager) (p *proxy) {
return
}
func (h proxy) New() types.Handler {
return New(h.log, h.c, h.s)
}
func (h proxy) String() string {
return fmt.Sprintf("apigw filter %s (%s)", h.Name, h.Label)
}

View File

@ -45,7 +45,7 @@ func (r *Registry) Get(identifier string) (types.Handler, error) {
return nil, fmt.Errorf("could not get element from registry: %s", identifier)
}
return f, nil
return f.New(), nil
}
func (r *Registry) All() (list types.FilterMetaList) {

View File

@ -142,6 +142,7 @@ func Test_serviceInit(t *testing.T) {
},
},
reg: map[string]types.Handler{"testExistingFilter": &mockExistingHandler{
MockHandler: &types.MockHandler{},
merge: func(params []byte) (types.Handler, error) {
return nil, errors.New("testttt")
},

View File

@ -18,6 +18,7 @@ type (
HTTPHandler
fmt.Stringer
New() Handler
Merge([]byte) (Handler, error)
Meta() FilterMeta
}

View File

@ -32,6 +32,10 @@ type (
MockRoundTripper func(*http.Request) (*http.Response, error)
)
func (h MockHandler) New() Handler {
return MockHandler{}
}
func (h MockHandler) String() string {
return "MockHandler"
}