Skip to content

Commit

Permalink
Fix missing key configuration for traefik plugin (#354)
Browse files Browse the repository at this point in the history
* add cache key config for traefik

* improve

* update

* fix

* improve

* cast bool

* Revert "cast bool"

This reverts commit 82e984c.

* update parsebool
  • Loading branch information
yongzhang authored Jun 16, 2023
1 parent 03e1575 commit b470be2
Show file tree
Hide file tree
Showing 13 changed files with 1,921 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plugins/traefik/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PKG=$(SOUIN)/pkg
API=$(SOUIN)/api
PKG_API=$(PKG)/api
CACHE=$(SOUIN)/cache
DC=docker-compose -f docker-compose.yml.test
DC=docker-compose -f docker-compose.yml.test

copy-to: ## Copy from to
rm -rf $(base)/$(target)
Expand Down
1 change: 1 addition & 0 deletions plugins/traefik/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ require (
github.com/prometheus/procfs v0.9.0 // indirect
github.com/redis/go-redis/v9 v9.0.2 // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/spf13/cast v1.5.1
github.com/tidwall/btree v1.6.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/redcon v1.6.2 // indirect
Expand Down
5 changes: 4 additions & 1 deletion plugins/traefik/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ github.com/envoyproxy/protoc-gen-validate v0.9.1/go.mod h1:OKNgG7TCp5pF4d6XftA0+
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
Expand Down Expand Up @@ -843,8 +844,8 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down Expand Up @@ -972,6 +973,8 @@ github.com/spf13/afero v1.3.3/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY52
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
github.com/spf13/afero v1.9.2/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA=
github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48=
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
Expand Down
42 changes: 41 additions & 1 deletion plugins/traefik/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import (
"encoding/json"
"fmt"
"net/http"
"regexp"
"strings"
"time"

"github.com/spf13/cast"

"github.com/darkweak/souin/configurationtypes"
"github.com/darkweak/souin/pkg/middleware"
)
Expand All @@ -27,6 +30,28 @@ func CreateConfig() *TestConfiguration {
return &TestConfiguration{}
}

func configCacheKey(keyConfiguration map[string]interface{}) configurationtypes.Key {
key := configurationtypes.Key{}
for keyK, keyV := range keyConfiguration {
switch keyK {
case "disable_body":
key.DisableBody = cast.ToBool(keyV)
case "disable_host":
key.DisableHost = cast.ToBool(keyV)
case "disable_method":
key.DisableMethod = cast.ToBool(keyV)
case "disable_query":
key.DisableQuery = cast.ToBool(keyV)
case "headers":
key.Headers = parseStringSlice(keyV)
case "hide":
key.Hide = cast.ToBool(keyV)
}
}

return key
}

func parseConfiguration(c map[string]interface{}) Configuration {
configuration := Configuration{}

Expand Down Expand Up @@ -71,6 +96,19 @@ func parseConfiguration(c map[string]interface{}) Configuration {
}
}
configuration.API = a
case "cache_keys":
cacheKeys := make(configurationtypes.CacheKeys, 0)
cacheKeyConfiguration := v.(map[string]interface{})
for cacheKeyConfigurationK, cacheKeyConfigurationV := range cacheKeyConfiguration {
cacheKeyK := configurationtypes.RegValue{
Regexp: regexp.MustCompile(cacheKeyConfigurationK),
}
cacheKeyV := configCacheKey(cacheKeyConfigurationV.(map[string]interface{}))
cacheKeys = append(cacheKeys, configurationtypes.CacheKey{
cacheKeyK: cacheKeyV,
})
}
configuration.CacheKeys = cacheKeys
case "default_cache":
dc := configurationtypes.DefaultCache{
Distributed: false,
Expand Down Expand Up @@ -99,7 +137,7 @@ func parseConfiguration(c map[string]interface{}) Configuration {
case "api_key":
cdn.APIKey = cdnV.(string)
case "dynamic":
cdn.Dynamic = cdnV.(bool)
cdn.Dynamic = cast.ToBool(cdnV)
case "email":
cdn.Email = cdnV.(string)
case "hostname":
Expand All @@ -119,6 +157,8 @@ func parseConfiguration(c map[string]interface{}) Configuration {
dc.CDN = cdn
case "headers":
dc.Headers = parseStringSlice(defaultCacheV)
case "key":
dc.Key = configCacheKey(defaultCacheV.(map[string]interface{}))
case "regex":
exclude := defaultCacheV.(map[string]interface{})["exclude"].(string)
if exclude != "" {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions plugins/traefik/vendor/github.com/spf13/cast/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions plugins/traefik/vendor/github.com/spf13/cast/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions plugins/traefik/vendor/github.com/spf13/cast/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions plugins/traefik/vendor/github.com/spf13/cast/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b470be2

Please sign in to comment.