diff --git a/pkg/middleware/middleware.go b/pkg/middleware/middleware.go index 55009a295..147ef946e 100644 --- a/pkg/middleware/middleware.go +++ b/pkg/middleware/middleware.go @@ -644,7 +644,8 @@ func (s *SouinBaseHandler) ServeHTTP(rw http.ResponseWriter, rq *http.Request, n fresh, stale = currentStorer.GetMultiLevel(finalKey, req, validator) if fresh != nil || stale != nil { - s.Configuration.GetLogger().Debugf("Found at least one valid response in the %s storage", currentStorer.Name()) + storerName = currentStorer.Name() + s.Configuration.GetLogger().Debugf("Found at least one valid response in the %s storage", storerName) break } } diff --git a/plugins/traefik/override/storage/abstractProvider_test.go b/plugins/traefik/override/storage/abstractProvider_test.go deleted file mode 100644 index a3905bbc6..000000000 --- a/plugins/traefik/override/storage/abstractProvider_test.go +++ /dev/null @@ -1,16 +0,0 @@ -package storage - -import ( - "testing" - - "github.com/darkweak/souin/tests" -) - -func TestInitializeProvider(t *testing.T) { - c := tests.MockConfiguration(tests.BaseConfiguration) - p := InitializeProvider(c) - err := p.Init() - if nil != err { - t.Error("Init shouldn't crash") - } -} diff --git a/plugins/traefik/override/surrogate/providers/common.go b/plugins/traefik/override/surrogate/providers/common.go index 5ae49c91b..1c9c5816e 100644 --- a/plugins/traefik/override/surrogate/providers/common.go +++ b/plugins/traefik/override/surrogate/providers/common.go @@ -12,6 +12,7 @@ import ( "github.com/darkweak/souin/configurationtypes" "github.com/darkweak/souin/pkg/storage" "github.com/darkweak/souin/pkg/storage/types" + "github.com/darkweak/souin/pkg/surrogate/providers" ) const ( @@ -73,7 +74,7 @@ type keysRegexpInner struct { } type baseStorage struct { - parent SurrogateInterface + parent providers.SurrogateInterface Storage types.Storer Keys map[string]configurationtypes.SurrogateKeys keysRegexp map[string]keysRegexpInner diff --git a/plugins/traefik/vendor/github.com/darkweak/souin/pkg/storage/abstractProvider_test.go b/plugins/traefik/vendor/github.com/darkweak/souin/pkg/storage/abstractProvider_test.go deleted file mode 100644 index a3905bbc6..000000000 --- a/plugins/traefik/vendor/github.com/darkweak/souin/pkg/storage/abstractProvider_test.go +++ /dev/null @@ -1,16 +0,0 @@ -package storage - -import ( - "testing" - - "github.com/darkweak/souin/tests" -) - -func TestInitializeProvider(t *testing.T) { - c := tests.MockConfiguration(tests.BaseConfiguration) - p := InitializeProvider(c) - err := p.Init() - if nil != err { - t.Error("Init shouldn't crash") - } -} diff --git a/plugins/traefik/vendor/github.com/darkweak/souin/pkg/surrogate/providers/common.go b/plugins/traefik/vendor/github.com/darkweak/souin/pkg/surrogate/providers/common.go index 5ae49c91b..1c9c5816e 100644 --- a/plugins/traefik/vendor/github.com/darkweak/souin/pkg/surrogate/providers/common.go +++ b/plugins/traefik/vendor/github.com/darkweak/souin/pkg/surrogate/providers/common.go @@ -12,6 +12,7 @@ import ( "github.com/darkweak/souin/configurationtypes" "github.com/darkweak/souin/pkg/storage" "github.com/darkweak/souin/pkg/storage/types" + "github.com/darkweak/souin/pkg/surrogate/providers" ) const ( @@ -73,7 +74,7 @@ type keysRegexpInner struct { } type baseStorage struct { - parent SurrogateInterface + parent providers.SurrogateInterface Storage types.Storer Keys map[string]configurationtypes.SurrogateKeys keysRegexp map[string]keysRegexpInner diff --git a/plugins/traefik/vendor/github.com/darkweak/souin/tests/mock.go b/plugins/traefik/vendor/github.com/darkweak/souin/tests/mock.go deleted file mode 100644 index d88e6f532..000000000 --- a/plugins/traefik/vendor/github.com/darkweak/souin/tests/mock.go +++ /dev/null @@ -1,523 +0,0 @@ -package tests - -import ( - "fmt" - "log" - "os" - - "github.com/darkweak/souin/configurationtypes" - "github.com/darkweak/storages/core" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" - "gopkg.in/yaml.v3" -) - -// DOMAIN is the domain constant -const DOMAIN = "domain.com" - -// PATH is the path constant -const PATH = "/testing" - -type testConfiguration struct { - DefaultCache *configurationtypes.DefaultCache `yaml:"default_cache"` - CacheKeys configurationtypes.CacheKeys `yaml:"cache_keys"` - API configurationtypes.API `yaml:"api"` - ReverseProxyURL string `yaml:"reverse_proxy_url"` - SSLProviders []string `yaml:"ssl_providers"` - URLs map[string]configurationtypes.URL `yaml:"urls"` - LogLevel string `yaml:"log_level"` - logger core.Logger - PluginName string - Ykeys map[string]configurationtypes.SurrogateKeys `yaml:"ykeys"` - SurrogateKeys map[string]configurationtypes.SurrogateKeys `yaml:"surrogate_keys"` -} - -// GetUrls get the urls list in the configuration -func (c *testConfiguration) GetUrls() map[string]configurationtypes.URL { - return c.URLs -} - -// GetReverseProxyURL get the reverse proxy url -func (c *testConfiguration) GetReverseProxyURL() string { - return c.ReverseProxyURL -} - -// GetSSLProviders get the ssl providers -func (c *testConfiguration) GetSSLProviders() []string { - return c.SSLProviders -} - -// GetPluginName get the plugin name -func (c *testConfiguration) GetPluginName() string { - return c.PluginName -} - -// GetDefaultCache get the default cache -func (c *testConfiguration) GetDefaultCache() configurationtypes.DefaultCacheInterface { - return c.DefaultCache -} - -// GetAPI get the default cache -func (c *testConfiguration) GetAPI() configurationtypes.API { - return c.API -} - -// GetLogLevel get the log level -func (c *testConfiguration) GetLogLevel() string { - return c.LogLevel -} - -// GetLogger get the logger -func (c *testConfiguration) GetLogger() core.Logger { - return c.logger -} - -// SetLogger set the logger -func (c *testConfiguration) SetLogger(l core.Logger) { - c.logger = l -} - -// GetYkeys get the ykeys list -func (c *testConfiguration) GetYkeys() map[string]configurationtypes.SurrogateKeys { - return c.Ykeys -} - -// GetSurrogateKeys get the surrogate keys list -func (c *testConfiguration) GetSurrogateKeys() map[string]configurationtypes.SurrogateKeys { - return c.SurrogateKeys -} - -// GetCacheKeys get the cache keys rules to override -func (c *testConfiguration) GetCacheKeys() configurationtypes.CacheKeys { - return c.CacheKeys -} - -var _ configurationtypes.AbstractConfigurationInterface = (*testConfiguration)(nil) - -// BaseConfiguration is the legacy configuration -func BaseConfiguration() string { - return ` -api: - basepath: /souin-api - security: - secret: your_secret_key - enable: true - users: - - username: user1 - password: test - souin: - enable: true -default_cache: - headers: - - Authorization - port: - web: 80 - tls: 443 - regex: - exclude: 'ARegexHere' - ttl: 1000s -reverse_proxy_url: 'http://domain.com:81' -urls: - 'domain.com/': - ttl: 1000s - headers: - - Authorization - 'mysubdomain.domain.com': - ttl: 50s - headers: - - Authorization - - 'Content-Type' -ykeys: - The_First_Test: - headers: - Authorization: '.+' - Content-Type: '.+' - The_Second_Test: - url: 'the/second/.+' - The_Third_Test: -` -} - -// CDNConfiguration is the CDN configuration -func CDNConfiguration() string { - return ` -api: - basepath: /souin-api - souin: - enable: true -default_cache: - ttl: 1000s - cdn: - dynamic: true - strategy: hard -` -} - -// BadgerConfiguration simulate the configuration for the Badger storage -func BadgerConfiguration() string { - return ` -api: - basepath: /souin-api - security: - secret: your_secret_key - enable: true - users: - - username: user1 - password: test - souin: - enable: true -default_cache: - badger: - configuration: - syncWrites: true - readOnly: false - inMemory: false - metricsEnabled: true - distributed: true - headers: - - Authorization - port: - web: 80 - tls: 443 - regex: - exclude: 'ARegexHere' - ttl: 1000s -reverse_proxy_url: 'http://domain.com:81' -ssl_providers: - - traefik -urls: - 'domain.com/': - ttl: 1000s - headers: - - Authorization - 'mysubdomain.domain.com': - ttl: 50s - headers: - - Authorization - - 'Content-Type' -` -} - -// OtterConfiguration simulate the configuration for the Otter storage -func OtterConfiguration() string { - return ` -api: - basepath: /souin-api - security: - secret: your_secret_key - enable: true - users: - - username: user1 - password: test - souin: - enable: true -default_cache: - otter: - configuration: {} - headers: - - Authorization - port: - web: 80 - tls: 443 - regex: - exclude: 'ARegexHere' - ttl: 1000s -reverse_proxy_url: 'http://domain.com:81' -ssl_providers: - - traefik -urls: - 'domain.com/': - ttl: 1000s - headers: - - Authorization - 'mysubdomain.domain.com': - ttl: 50s - headers: - - Authorization - - 'Content-Type' -` -} - -// NutsConfiguration simulate the configuration for the Nuts storage -func NutsConfiguration() string { - return ` -api: - basepath: /souin-api - security: - secret: your_secret_key - enable: true - users: - - username: user1 - password: test - souin: - enable: true -default_cache: - nuts: - path: "./nuts" - headers: - - Authorization - port: - web: 80 - tls: 443 - regex: - exclude: 'ARegexHere' - ttl: 1000s -reverse_proxy_url: 'http://domain.com:81' -ssl_providers: - - traefik -urls: - 'domain.com/': - ttl: 1000s - headers: - - Authorization - 'mysubdomain.domain.com': - ttl: 50s - headers: - - Authorization - - 'Content-Type' -` -} - -// EtcdConfiguration simulate the configuration for the Nuts storage -func EtcdConfiguration() string { - return ` -api: - basepath: /souin-api - security: - secret: your_secret_key - enable: true - users: - - username: user1 - password: test - souin: - enable: true -default_cache: - etcd: - configuration: - endpoints: - - http://etcd:2379 - distributed: true - headers: - - Authorization - port: - web: 80 - tls: 443 - regex: - exclude: 'ARegexHere' - ttl: 1000s -reverse_proxy_url: 'http://domain.com:81' -ssl_providers: - - traefik -urls: - 'domain.com/': - ttl: 1000s - headers: - - Authorization - 'mysubdomain.domain.com': - ttl: 50s - headers: - - Authorization - - 'Content-Type' -` -} - -// RedisConfiguration simulate the configuration for the Nuts storage -func RedisConfiguration() string { - return ` -api: - basepath: /souin-api - security: - secret: your_secret_key - enable: true - users: - - username: user1 - password: test - souin: - enable: true -default_cache: - redis: - url: redis:6379 - distributed: true - headers: - - Authorization - port: - web: 80 - tls: 443 - regex: - exclude: 'ARegexHere' - ttl: 1000s -reverse_proxy_url: 'http://domain.com:81' -ssl_providers: - - traefik -urls: - 'domain.com/': - ttl: 1000s - headers: - - Authorization - 'mysubdomain.domain.com': - ttl: 50s - headers: - - Authorization - - 'Content-Type' -` -} - -func baseEmbeddedOlricConfiguration(path string) string { - return fmt.Sprintf(` -api: - basepath: /souin-api - security: - secret: your_secret_key - enable: true - users: - - username: user1 - password: test - souin: - enable: true -default_cache: - distributed: true - headers: - - Authorization - olric: - %s - port: - web: 80 - tls: 443 - regex: - exclude: 'ARegexHere' - ttl: 1000s -reverse_proxy_url: 'http://domain.com:81' -ssl_providers: - - traefik -urls: - 'domain.com/': - ttl: 1000s - headers: - - Authorization - 'mysubdomain.domain.com': - ttl: 50s - headers: - - Authorization - - 'Content-Type' -`, path) -} - -// OlricConfiguration is the olric included configuration -func OlricConfiguration() string { - return baseEmbeddedOlricConfiguration(fmt.Sprintf("url: '%s'", "olric:3320")) -} - -// EmbeddedOlricPlainConfigurationWithoutAdditionalYAML simulate the configuration for the embedded Olric storage -func EmbeddedOlricPlainConfigurationWithoutAdditionalYAML() string { - return baseEmbeddedOlricConfiguration(` - configuration: - olricd: - bindAddr: "0.0.0.0" - bindPort: 3320 - serializer: "msgpack" - keepAlivePeriod: "20s" - bootstrapTimeout: "5s" - partitionCount: 271 - replicaCount: 2 - writeQuorum: 1 - readQuorum: 1 - readRepair: false - replicationMode: 1 # sync mode. for async, set 1 - tableSize: 1048576 # 1MB in bytes - memberCountQuorum: 1 - - logging: - verbosity: 6 - level: "DEBUG" - output: "stderr" - - memberlist: - environment: "local" - bindAddr: "0.0.0.0" - bindPort: 3322 - enableCompression: false - joinRetryInterval: "10s" - maxJoinAttempts: 2 - - storageEngines: - config: - kvstore: - tableSize: 4096 -`) -} - -// EmbeddedOlricConfiguration is the olric included configuration -func EmbeddedOlricConfiguration() string { - path := "/tmp/olric.yml" - _ = os.WriteFile( - path, - []byte( - ` -olricd: - bindAddr: "0.0.0.0" - bindPort: 3320 - serializer: "msgpack" - keepAlivePeriod: "300s" - bootstrapTimeout: "5s" - partitionCount: 271 - replicaCount: 2 - writeQuorum: 1 - readQuorum: 1 - readRepair: false - replicationMode: 1 # sync mode. for async, set 1 - tableSize: 1048576 # 1MB in bytes - memberCountQuorum: 1 - -logging: - verbosity: 6 - level: "DEBUG" - output: "stderr" - -memberlist: - environment: "local" - bindAddr: "0.0.0.0" - bindPort: 3322 - enableCompression: false - joinRetryInterval: "1s" - maxJoinAttempts: 10 - -storageEngines: - config: - kvstore: - tableSize: 4096 -`), - 0600, - ) - - return baseEmbeddedOlricConfiguration(fmt.Sprintf("path: '%s'", path)) -} - -// MockConfiguration is an helper to mock the configuration -func MockConfiguration(configurationToLoad func() string) *testConfiguration { - var config testConfiguration - if e := yaml.Unmarshal([]byte(configurationToLoad()), &config); e != nil { - log.Fatal(e) - } - cfg := zap.Config{ - Encoding: "json", - Level: zap.NewAtomicLevelAt(zapcore.DebugLevel), - OutputPaths: []string{"stderr"}, - ErrorOutputPaths: []string{"stderr"}, - EncoderConfig: zapcore.EncoderConfig{ - MessageKey: "message", - - LevelKey: "level", - EncodeLevel: zapcore.CapitalLevelEncoder, - - TimeKey: "time", - EncodeTime: zapcore.ISO8601TimeEncoder, - - CallerKey: "caller", - EncodeCaller: zapcore.ShortCallerEncoder, - }, - } - logger, _ := cfg.Build() - config.SetLogger(logger.Sugar()) - - return &config -} diff --git a/plugins/traefik/vendor/modules.txt b/plugins/traefik/vendor/modules.txt index 625170d7d..9fe09e17b 100644 --- a/plugins/traefik/vendor/modules.txt +++ b/plugins/traefik/vendor/modules.txt @@ -80,7 +80,6 @@ github.com/darkweak/souin/pkg/storage github.com/darkweak/souin/pkg/storage/types github.com/darkweak/souin/pkg/surrogate github.com/darkweak/souin/pkg/surrogate/providers -github.com/darkweak/souin/tests # github.com/darkweak/storages/core v0.0.7 ## explicit; go 1.22.1 github.com/darkweak/storages/core