Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable verbosity #59

Merged
merged 4 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ default_cache:
url: 'olric:3320' # Olric server
regex:
exclude: 'ARegexHere' # Regex to exclude from cache
log_level: INFO # Logs verbosity [ DEBUG, INFO, WARN, ERROR, DPANIC, PANIC, FATAL, debug, info, warn, error, dpanic, panic, fatal ]
ssl_providers: # The {providers}.json to use
- traefik
urls:
Expand All @@ -89,19 +90,20 @@ urls:
- 'Content-Type'
```

| Key | Description | Value example |
|:------------------------------------:|:--------------------------------------------------------------------------:|:----------------------------------------------------------------------------:|
| `api.basepath` | BasePath for all APIs to avoid conflicts | `/your-non-conflicting-route`<br/><br/>`(default: /souin-api)` |
| `api.{api}.enable` | Enable the new API with related routes | `true`<br/><br/>`(default: false)` |
| `api.security.secret` | JWT secret key | `Any_charCanW0rk123` |
| `api.security.users` | Array of authorized users with username x password combo | `- username: admin`<br/><br/>` password: admin` |
| `api.souin.security` | Enable JWT validation to access the resource | `true`<br/><br/>`(default: false)` |
| `default_cache.headers` | List of headers to include to the cache | `- Authorization`<br/><br/>`- Content-Type`<br/><br/>`- X-Additional-Header` |
| `default_cache.regex.exclude` | The regex used to prevent paths being cached | `^[A-z]+.*$` |
| `ssl_providers` | List of your providers handling certificates | `- traefik`<br/><br/>`- nginx`<br/><br/>`- apache` |
| `urls.{your url or regex}` | List of your custom configuration depending each URL or regex | 'https:\/\/yourdomain.com' |
| `urls.{your url or regex}.ttl` | Override the default TTL if defined | 99999 |
| `urls.{your url or regex}.headers` | Override the default headers if defined | `- Authorization`<br/><br/>`- 'Content-Type'` |
| Key | Description | Value example |
|:----------------------------------:|:-------------------------------------------------------------:|:-----------------------------------------------------------------------------:|
| `api.basepath` | BasePath for all APIs to avoid conflicts | `/your-non-conflicting-route`<br/><br/>`(default: /souin-api)` |
| `api.{api}.enable` | Enable the new API with related routes | `true`<br/><br/>`(default: false)` |
| `api.security.secret` | JWT secret key | `Any_charCanW0rk123` |
| `api.security.users` | Array of authorized users with username x password combo | `- username: admin`<br/><br/>` password: admin` |
| `api.souin.security` | Enable JWT validation to access the resource | `true`<br/><br/>`(default: false)` |
| `default_cache.headers` | List of headers to include to the cache | `- Authorization`<br/><br/>`- Content-Type`<br/><br/>`- X-Additional-Header` |
| `default_cache.regex.exclude` | The regex used to prevent paths being cached | `^[A-z]+.*$` |
| `log_level` | The log level | `One of DEBUG, INFO, WARN, ERROR, DPANIC, PANIC, FATAL it's case insensitive` |
| `ssl_providers` | List of your providers handling certificates | `- traefik`<br/><br/>`- nginx`<br/><br/>`- apache` |
| `urls.{your url or regex}` | List of your custom configuration depending each URL or regex | 'https:\/\/yourdomain.com' |
| `urls.{your url or regex}.ttl` | Override the default TTL if defined | 99999 |
| `urls.{your url or regex}.headers` | Override the default headers if defined | `- Authorization`<br/><br/>`- 'Content-Type'` |

## APIs
All endpoints are accessible through the `api.basepath` configuration line or by default through `/souin-api` to avoid named route conflicts. Be sure to define an unused route to not break your existing application.
Expand Down
18 changes: 18 additions & 0 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package configuration

import (
"github.com/darkweak/souin/configurationtypes"
"go.uber.org/zap"
"gopkg.in/yaml.v3"
"io/ioutil"
"log"
Expand All @@ -14,6 +15,8 @@ type Configuration struct {
ReverseProxyURL string `yaml:"reverse_proxy_url"`
SSLProviders []string `yaml:"ssl_providers"`
URLs map[string]configurationtypes.URL `yaml:"urls"`
LogLevel string `yaml:"log_level"`
logger *zap.Logger
}

func readFile(path string) []byte {
Expand Down Expand Up @@ -57,6 +60,21 @@ func (c *Configuration) GetAPI() configurationtypes.API {
return c.API
}

// GetLogLevel get the log level
func (c *Configuration) GetLogLevel() string {
return c.LogLevel
}

// GetLogger get the logger
func (c *Configuration) GetLogger() *zap.Logger {
return c.logger
}

// SetLogger set the logger
func (c *Configuration) SetLogger(l *zap.Logger) {
c.logger = l
}

// GetConfiguration allow to retrieve Souin configuration through yaml file
func GetConfiguration() *Configuration {
data := readFile("./configuration/configuration.yml")
Expand Down
1 change: 1 addition & 0 deletions configuration/configuration.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ default_cache: # Required part
regex: # Regex configuration
exclude: 'ARegexHere' # Regex to exclude from cache
ttl: 10 # Default TTL
log_level: INFO # Logs verbosity [ DEBUG, INFO, WARN, ERROR, DPANIC, PANIC, FATAL, debug, info, warn, error, dpanic, panic, fatal ]
reverse_proxy_url: 'http://traefik' # If it's in the same network you can use http://your-service. Then just use https://yourdomain.com
ssl_providers: # The {providers}.json to usee
- traefik
Expand Down
1 change: 1 addition & 0 deletions configuration/configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ default_cache:
regex:
exclude: 'ARegexHere'
ttl: 10
log_level: debug
reverse_proxy_url: 'http://traefik'
ssl_providers:
- traefik
Expand Down
5 changes: 5 additions & 0 deletions configurationtypes/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package configurationtypes

import "go.uber.org/zap"

// Port config
type Port struct {
Web string `yaml:"web"`
Expand Down Expand Up @@ -105,4 +107,7 @@ type AbstractConfigurationInterface interface {
GetUrls() map[string]URL
GetDefaultCache() DefaultCacheInterface
GetAPI() API
GetLogLevel() string
GetLogger() *zap.Logger
SetLogger(*zap.Logger)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ go 1.15

require (
github.com/buraksezer/olric v0.3.6
github.com/caddyserver/caddy/v2 v2.3.0 // indirect
github.com/dgraph-io/ristretto v0.0.3
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/fsnotify/fsnotify v1.4.9
github.com/pquerna/cachecontrol v0.0.0-20200921180117-858c6e7e6b7e
go.uber.org/zap v1.16.0
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 // indirect
Expand Down
Loading