Skip to content

Commit

Permalink
feat: add enabled config option
Browse files Browse the repository at this point in the history
Signed-off-by: nscuro <[email protected]>
  • Loading branch information
nscuro committed Oct 5, 2021
1 parent 11bb06c commit 14a26eb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .traefik.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ type: middleware
import: github.com/nscuro/traefik-plugin-geoblock
summary: Description of what my plugin is doing
testData:
enabled: true
database_file: IP2LOCATION-LITE-DB1.IPV6.BIN
allowed_countries: [ "CH", "DE" ]
allowed_countries: [ "CH", "DE" ]
allow_private: true
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ http:
geoblock:
plugin:
geoblock:
enabled: true
database_file: /plugins-local/src/github.com/nscuro/traefik-plugin-geoblock/IP2LOCATION-LITE-DB1.IPV6.BIN
allowed_countries: [ "AT", "CH", "DE" ]
allow_private: true
Expand Down
6 changes: 6 additions & 0 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

type Config struct {
Enabled bool `yaml:"enabled"`
DatabaseFilePath string `yaml:"database_file"`
AllowedCountries []string `yaml:"allowed_countries"`
AllowPrivate bool `yaml:"allow_private"`
Expand Down Expand Up @@ -43,6 +44,11 @@ func New(_ context.Context, next http.Handler, cfg *Config, name string) (http.H
}

func (p Plugin) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
if !p.cfg.Enabled {
p.next.ServeHTTP(rw, req)
return
}

ips := p.GetRemoteIPs(req)

for _, ip := range ips {
Expand Down

0 comments on commit 14a26eb

Please sign in to comment.