Skip to content

Commit

Permalink
feat(configuration): Set enable property optional, default true (#188)
Browse files Browse the repository at this point in the history
* feat(configuration): Set enable property optional, default true

* Update documentation

* Deprecate the security endpoint

* Update caddy's README
  • Loading branch information
darkweak authored Feb 16, 2022
1 parent be46853 commit 9001cbc
Show file tree
Hide file tree
Showing 21 changed files with 140 additions and 188 deletions.
3 changes: 3 additions & 0 deletions .traefik.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ summary: 'Souin is a powerfull cache system as fast as Varnish but easier to con

# Refer to https://github.com/darkweak/Souin/blob/master/configuration/configuration.sample.yml for full configuration
testData:
api:
prometheus: {}
souin: {}
default_cache:
headers:
- Authorization
Expand Down
114 changes: 52 additions & 62 deletions README.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion api/auth/security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ api:
security:
basepath: /mybasepath
secret: your_secret_key
enable: true
users:
- username: user1
password: test
Expand Down
7 changes: 1 addition & 6 deletions cache/surrogate/providers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package providers
import (
"net/http"
"regexp"
"strconv"
"strings"

"github.com/darkweak/souin/configurationtypes"
Expand Down Expand Up @@ -91,11 +90,7 @@ func (s *baseStorage) init(config configurationtypes.AbstractConfigurationInterf
keysRegexp[key] = innerKey
}

s.dynamic = true
if config.GetDefaultCache().GetCDN().Dynamic != "" {
dynamic, e := strconv.ParseBool(config.GetDefaultCache().GetCDN().Dynamic)
s.dynamic = e != nil || dynamic
}
s.dynamic = config.GetDefaultCache().GetCDN().Dynamic
s.logger = config.GetLogger()
s.keysRegexp = keysRegexp
}
Expand Down
6 changes: 3 additions & 3 deletions configuration/configuration.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ api:
basepath: /souin-api # Default route basepath for every additional APIs to avoid conflicts with existing routes
security: # Secure your APIs
secret: your_secret_key # JWT secret key
enable: true # Required to enable the endpoints
users: # Users declaration
- username: user1
password: test
prometheus: # Prometheus exposed metrics
basepath: /anything-for-prometheus-metrics # Change the prometheus endpoint basepath
souin: # Souin listing keys and cache management
security: true # Enable JWT Authentication token
enable: true # Enable the endpoints
basepath: /anything-for-souin # Change the souin endpoint basepath
cdn: # If Souin is set after a CDN fill these informations
api_key: XXXX # Your provider API key if mandatory
provider: fastly # The provider placed before Souin (e.g. fastly, cloudflare, akamai, varnish)
Expand Down
11 changes: 2 additions & 9 deletions configuration/configuration.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
api:
basepath: /souin-api
security:
secret: your_secret_key
enable: true
users:
- username: user1
password: test
souin:
security: false
enable: true
prometheus: {}
souin: {}
cdn:
api_key: XXXX
provider: fastly
Expand Down
2 changes: 1 addition & 1 deletion configurationtypes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type CacheProvider struct {
// CDN config
type CDN struct {
APIKey string `json:"api_key,omitempty" yaml:"api_key,omitempty"`
Dynamic string `json:"dynamic,omitempty" yaml:"dynamic,omitempty"`
Dynamic bool `json:"dynamic,omitempty" yaml:"dynamic,omitempty"`
Email string `json:"email,omitempty" yaml:"email,omitempty"`
Hostname string `json:"hostname,omitempty" yaml:"hostname,omitempty"`
Network string `json:"network,omitempty" yaml:"network,omitempty"`
Expand Down
8 changes: 2 additions & 6 deletions plugins/caddy/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
}
cache {
api {
prometheus {
enable true
}
souin {
enable true
}
prometheus
souin
}
regex {
exclude /test2.*
Expand Down
62 changes: 31 additions & 31 deletions plugins/caddy/README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions plugins/caddy/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.16

require (
github.com/caddyserver/caddy/v2 v2.4.5
github.com/darkweak/souin v1.6.0
github.com/darkweak/souin v1.6.1
go.uber.org/zap v1.19.1
)

replace github.com/darkweak/souin v1.6.0 => ../..
replace github.com/darkweak/souin v1.6.1 => ../..
26 changes: 3 additions & 23 deletions plugins/caddy/httpcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"net/http"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -258,41 +257,22 @@ func parseCaddyfileGlobalOption(h *caddyfile.Dispenser, _ interface{}) (interfac
apiConfiguration.BasePath = h.RemainingArgs()[0]
case "prometheus":
apiConfiguration.Prometheus = configurationtypes.APIEndpoint{}
apiConfiguration.Prometheus.Enable = true
for nesting := h.Nesting(); h.NextBlock(nesting); {
directive := h.Val()
switch directive {
case "basepath":
apiConfiguration.Prometheus.BasePath = h.RemainingArgs()[0]
case "enable":
apiConfiguration.Prometheus.Enable, _ = strconv.ParseBool(h.RemainingArgs()[0])
case "security":
apiConfiguration.Prometheus.Security, _ = strconv.ParseBool(h.RemainingArgs()[0])
}
}
case "souin":
apiConfiguration.Souin = configurationtypes.APIEndpoint{}
apiConfiguration.Souin.Enable = true
for nesting := h.Nesting(); h.NextBlock(nesting); {
directive := h.Val()
switch directive {
case "basepath":
apiConfiguration.Souin.BasePath = h.RemainingArgs()[0]
case "enable":
apiConfiguration.Souin.Enable, _ = strconv.ParseBool(h.RemainingArgs()[0])
case "security":
apiConfiguration.Souin.Security, _ = strconv.ParseBool(h.RemainingArgs()[0])
}
}
case "security":
apiConfiguration.Security = configurationtypes.SecurityAPI{}
for nesting := h.Nesting(); h.NextBlock(nesting); {
directive := h.Val()
switch directive {
case "basepath":
apiConfiguration.Security.BasePath = h.RemainingArgs()[0]
case "enable":
apiConfiguration.Security.Enable, _ = strconv.ParseBool(h.RemainingArgs()[0])
case "secret":
apiConfiguration.Security.Secret = h.RemainingArgs()[0]
}
}
}
Expand All @@ -319,7 +299,7 @@ func parseCaddyfileGlobalOption(h *caddyfile.Dispenser, _ interface{}) (interfac
case "api_key":
cdn.APIKey = h.RemainingArgs()[0]
case "dynamic":
cdn.Dynamic = h.RemainingArgs()[0]
cdn.Dynamic = true
case "hostname":
cdn.Hostname = h.RemainingArgs()[0]
case "network":
Expand Down
4 changes: 2 additions & 2 deletions plugins/echo/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/darkweak/souin/plugins/echo
go 1.16

require (
github.com/darkweak/souin v1.6.0
github.com/darkweak/souin v1.6.1
github.com/labstack/echo/v4 v4.6.1
go.uber.org/zap v1.19.1
)

replace github.com/darkweak/souin v1.6.0 => ../..
replace github.com/darkweak/souin v1.6.1 => ../..
4 changes: 2 additions & 2 deletions plugins/gin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/darkweak/souin/plugins/gin
go 1.16

require (
github.com/darkweak/souin v1.6.0
github.com/darkweak/souin v1.6.1
github.com/gin-gonic/gin v1.7.7
github.com/go-playground/validator/v10 v10.10.0 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
Expand All @@ -14,4 +14,4 @@ require (
google.golang.org/protobuf v1.27.1 // indirect
)

replace github.com/darkweak/souin v1.6.0 => ../..
replace github.com/darkweak/souin v1.6.1 => ../..
4 changes: 2 additions & 2 deletions plugins/skipper/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/darkweak/souin/plugins/skipper
go 1.16

require (
github.com/darkweak/souin v1.6.0
github.com/darkweak/souin v1.6.1
github.com/zalando/skipper v0.13.174
go.uber.org/zap v1.19.1
)

replace github.com/darkweak/souin v1.6.0 => ../..
replace github.com/darkweak/souin v1.6.1 => ../..
4 changes: 2 additions & 2 deletions plugins/traefik/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module github.com/darkweak/souin/plugins/traefik
go 1.16

require (
github.com/darkweak/souin v1.6.0
github.com/darkweak/souin v1.6.1
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pquerna/cachecontrol v0.1.0
go.uber.org/zap v1.19.1
)

replace github.com/darkweak/souin v1.6.0 => ../..
replace github.com/darkweak/souin v1.6.1 => ../..
47 changes: 25 additions & 22 deletions plugins/traefik/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"encoding/json"
"net/http"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -45,47 +44,51 @@ func parseConfiguration(c map[string]interface{}) Configuration {
var a configurationtypes.API
var prometheusConfiguration, souinConfiguration, securityConfiguration map[string]interface{}
apiConfiguration := v.(map[string]interface{})
if apiConfiguration["prometheus"] != nil {
prometheusConfiguration = apiConfiguration["prometheus"].(map[string]interface{})
}
if apiConfiguration["souin"] != nil {
souinConfiguration = apiConfiguration["souin"].(map[string]interface{})
}
if apiConfiguration["security"] != nil {
securityConfiguration = apiConfiguration["security"].(map[string]interface{})
for apiK, apiV := range apiConfiguration {
switch apiK {
case "prometheus":
prometheusConfiguration = make(map[string]interface{})
if apiV != nil && len(apiV.(string)) != 0 {
prometheusConfiguration = apiV.(map[string]interface{})
}
case "souin":
souinConfiguration = make(map[string]interface{})
if apiV != nil && len(apiV.(string)) != 0 {
souinConfiguration = apiV.(map[string]interface{})
}
case "security":
securityConfiguration = make(map[string]interface{})
if apiV != nil && len(apiV.(string)) != 0 {
securityConfiguration = apiV.(map[string]interface{})
}
}
}
if prometheusConfiguration != nil {
a.Prometheus = configurationtypes.APIEndpoint{}
a.Prometheus.Enable = true
if prometheusConfiguration["basepath"] != nil {
a.Prometheus.BasePath = prometheusConfiguration["basepath"].(string)
}
if prometheusConfiguration["enable"] != nil {
a.Prometheus.Enable, _ = strconv.ParseBool(prometheusConfiguration["enable"].(string))
}
if securityConfiguration["enable"] != nil {
a.Prometheus.Security = securityConfiguration["enable"].(bool)
if prometheusConfiguration["security"] != nil {
a.Prometheus.Security = prometheusConfiguration["security"].(bool)
}
}
if souinConfiguration != nil {
a.Souin = configurationtypes.APIEndpoint{}
a.Souin.Enable = true
if souinConfiguration["basepath"] != nil {
a.Souin.BasePath = souinConfiguration["basepath"].(string)
}
if souinConfiguration["enable"] != nil {
a.Souin.Enable, _ = strconv.ParseBool(souinConfiguration["enable"].(string))
}
if securityConfiguration["enable"] != nil {
a.Souin.Security = securityConfiguration["enable"].(bool)
if souinConfiguration["security"] != nil {
a.Souin.Security = souinConfiguration["security"].(bool)
}
}
if securityConfiguration != nil {
a.Security = configurationtypes.SecurityAPI{}
a.Security.Enable = true
if securityConfiguration["basepath"] != nil {
a.Security.BasePath = securityConfiguration["basepath"].(string)
}
if securityConfiguration["enable"] != nil {
a.Security.Enable, _ = strconv.ParseBool(securityConfiguration["enable"].(string))
}
if securityConfiguration["users"] != nil {
a.Security.Users = securityConfiguration["users"].([]configurationtypes.User)
}
Expand Down
6 changes: 2 additions & 4 deletions plugins/traefik/souin-configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ http:
plugin:
souin-plugin:
api:
prometheus:
enable: true
souin:
enable: true
prometheus: {}
souin: {}
default_cache:
headers:
- Authorization
Expand Down

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

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

2 changes: 1 addition & 1 deletion plugins/traefik/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ github.com/buraksezer/olric/stats
github.com/cespare/xxhash
# github.com/cespare/xxhash/v2 v2.1.2
github.com/cespare/xxhash/v2
# github.com/darkweak/souin v1.6.0 => ../..
# github.com/darkweak/souin v1.6.1 => ../..
## explicit
github.com/darkweak/souin/api
github.com/darkweak/souin/api/auth
Expand Down
4 changes: 2 additions & 2 deletions plugins/tyk/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/TykTechnologies/gojsonschema v0.0.0-20170222154038-dcb3e4bb7990 // indirect
github.com/TykTechnologies/tyk v2.9.5+incompatible
github.com/clbanning/mxj v1.8.4 // indirect
github.com/darkweak/souin v1.6.0
github.com/darkweak/souin v1.6.1
github.com/franela/goblin v0.0.0-20211003143422-0a4f594942bf // indirect
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8 // indirect
github.com/hashicorp/terraform v1.0.1 // indirect
Expand All @@ -22,6 +22,6 @@ require (
)

replace (
github.com/darkweak/souin v1.6.0 => ../..
github.com/darkweak/souin v1.6.1 => ../..
github.com/hashicorp/terraform v1.0.1 => github.com/hashicorp/terraform v0.14.11
)

0 comments on commit 9001cbc

Please sign in to comment.