Skip to content

Commit d12869f

Browse files
authored
fix(plugins): handle stringified array from traefik configuration loader (#333)
1 parent 195397f commit d12869f

29 files changed

+1351
-1798
lines changed

plugins/traefik/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ prepare: vendor ## Prepare traefik plugin
2525
# TODO find another way to do that
2626
replace: ## Replace sources in the vendor folder deeper than the go mod replace
2727
$(MAKE) copy-to base=$(CACHE) target=coalescing
28-
$(MAKE) copy-to base=$(CACHE) target=providers
2928
$(MAKE) copy-to base=$(SOUIN) target=context
3029
$(MAKE) copy-file-to base=$(PKG) target=surrogate/providers/common.go
3130
$(MAKE) copy-file-to base=$(CACHE) target=types/layerStorage.go

plugins/traefik/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.19
55
require (
66
github.com/akyoto/cache v1.0.6
77
github.com/darkweak/souin v1.6.36
8-
github.com/patrickmn/go-cache v2.1.0+incompatible
98
github.com/pquerna/cachecontrol v0.1.0
109
go.uber.org/zap v1.21.0
1110
)

plugins/traefik/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,8 +898,6 @@ github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5h
898898
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
899899
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
900900
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
901-
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
902-
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
903901
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
904902
github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY=
905903
github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=

plugins/traefik/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,21 @@ func parseConfiguration(c map[string]interface{}) Configuration {
201201
// parseStringSlice returns the string slice corresponding to the given interface.
202202
// The interface can be of type string which contains a comma separated list of values (e.g. foo,bar) or of type []string.
203203
func parseStringSlice(i interface{}) []string {
204+
if value, ok := i.([]string); ok {
205+
return value
206+
}
207+
if value, ok := i.([]interface{}); ok {
208+
var arr []string
209+
for _, v := range value {
210+
arr = append(arr, v.(string))
211+
}
212+
return arr
213+
}
214+
204215
if value, ok := i.(string); ok {
216+
if strings.HasPrefix(value, "║24║") {
217+
return strings.Split(strings.TrimPrefix(value, "║24║"), "║")
218+
}
205219
return strings.Split(value, ",")
206220
}
207221

plugins/traefik/override/middleware/middleware.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,6 @@ type handlerFunc = func(http.ResponseWriter, *http.Request) error
179179

180180
func (s *SouinBaseHandler) ServeHTTP(rw http.ResponseWriter, rq *http.Request, next handlerFunc) error {
181181
b, handler := s.HandleInternally(rq)
182-
fmt.Println("AFTER")
183-
fmt.Println("AFTER b", b)
184182
if b {
185183
handler(rw, rq)
186184
return nil
@@ -193,13 +191,11 @@ func (s *SouinBaseHandler) ServeHTTP(rw http.ResponseWriter, rq *http.Request, n
193191
return next(rw, rq)
194192
}
195193

196-
fmt.Println("RESPONSE 1")
197194
if !rq.Context().Value(context.SupportedMethod).(bool) {
198195
rw.Header().Set("Cache-Status", cacheName+"; fwd=uri-miss; detail=UNSUPPORTED-METHOD")
199196

200197
return next(rw, rq)
201198
}
202-
fmt.Println("RESPONSE 2")
203199

204200
requestCc, coErr := cacheobject.ParseRequestCacheControl(rq.Header.Get("Cache-Control"))
205201

plugins/traefik/override/providers/abstractProvider.go

Lines changed: 0 additions & 58 deletions
This file was deleted.

plugins/traefik/override/providers/abstractProvider_test.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

plugins/traefik/override/providers/cacheProvider.go

Lines changed: 0 additions & 110 deletions
This file was deleted.

plugins/traefik/override/storage/cacheProvider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func (provider *Cache) Get(key string) []byte {
4747
// Prefix method returns the populated response if exists, empty response then
4848
func (provider *Cache) Prefix(key string, req *http.Request) []byte {
4949
var result []byte
50+
5051
provider.Cache.Range(func(k, v interface{}) bool {
5152
if k == key {
5253
result = v.([]byte)

plugins/traefik/override/ykeys/ykey.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package ykeys
22

33
import (
44
"fmt"
5-
"github.com/patrickmn/go-cache"
65
"net/http"
76
"regexp"
87
"strings"
98
"time"
109

10+
"github.com/akyoto/cache"
11+
1112
"github.com/darkweak/souin/configurationtypes"
1213
)
1314

@@ -47,7 +48,7 @@ func InitializeYKeys(keys map[string]configurationtypes.SurrogateKeys) *YKeyStor
4748
return nil
4849
}
4950

50-
c := cache.New(1*time.Second, 2*time.Second)
51+
c := cache.New(1 * time.Second)
5152

5253
for key := range keys {
5354
c.Set(key, "", 1)

0 commit comments

Comments
 (0)