Skip to content

Commit 5a5d9c5

Browse files
committed
Allow disabling the start-up configuration output
1 parent f9b53b6 commit 5a5d9c5

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

.traefik.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import: github.com/PascalMinder/geoblock
66
summary: "block request based on their country of origin"
77

88
testData:
9+
silentStartUp: false
910
allowLocalRequests: false
1011
logLocalRequests: false
1112
logAllowedRequests: false

docker/traefik-config/dynamic-configuration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ http:
33
my-plugin:
44
plugin:
55
geoblock:
6+
silentStartUp: false
67
allowLocalRequests: true
78
logLocalRequests: false
89
logAllowedRequests: true

geoblock.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var (
3030

3131
// Config the plugin configuration.
3232
type Config struct {
33+
SilentStartUp bool `yaml:"silentStartUp"`
3334
AllowLocalRequests bool `yaml:"allowLocalRequests"`
3435
LogLocalRequests bool `yaml:"logLocalRequests"`
3536
LogAllowedRequests bool `yaml:"logAllowedRequests"`
@@ -59,6 +60,7 @@ func CreateConfig() *Config {
5960
// GeoBlock a Traefik plugin.
6061
type GeoBlock struct {
6162
next http.Handler
63+
silentStartUp bool
6264
allowLocalRequests bool
6365
logLocalRequests bool
6466
logAllowedRequests bool
@@ -111,19 +113,21 @@ func New(_ context.Context, next http.Handler, config *Config, name string) (htt
111113

112114
infoLogger.SetOutput(os.Stdout)
113115

114-
infoLogger.Printf("allow local IPs: %t", config.AllowLocalRequests)
115-
infoLogger.Printf("log local requests: %t", config.LogLocalRequests)
116-
infoLogger.Printf("log allowed requests: %t", config.LogAllowedRequests)
117-
infoLogger.Printf("log api requests: %t", config.LogAPIRequests)
118-
infoLogger.Printf("API uri: %s", config.API)
119-
infoLogger.Printf("API timeout: %d", config.APITimeoutMs)
120-
infoLogger.Printf("cache size: %d", config.CacheSize)
121-
infoLogger.Printf("force monthly update: %t", config.ForceMonthlyUpdate)
122-
infoLogger.Printf("allow unknown countries: %t", config.AllowUnknownCountries)
123-
infoLogger.Printf("unknown country api response: %s", config.UnknownCountryAPIResponse)
124-
infoLogger.Printf("blacklist mode: %t", config.BlackListMode)
125-
infoLogger.Printf("add country header: %t", config.AddCountryHeader)
126-
infoLogger.Printf("countries: %v", config.Countries)
116+
if !config.SilentStartUp {
117+
infoLogger.Printf("allow local IPs: %t", config.AllowLocalRequests)
118+
infoLogger.Printf("log local requests: %t", config.LogLocalRequests)
119+
infoLogger.Printf("log allowed requests: %t", config.LogAllowedRequests)
120+
infoLogger.Printf("log api requests: %t", config.LogAPIRequests)
121+
infoLogger.Printf("API uri: %s", config.API)
122+
infoLogger.Printf("API timeout: %d", config.APITimeoutMs)
123+
infoLogger.Printf("cache size: %d", config.CacheSize)
124+
infoLogger.Printf("force monthly update: %t", config.ForceMonthlyUpdate)
125+
infoLogger.Printf("allow unknown countries: %t", config.AllowUnknownCountries)
126+
infoLogger.Printf("unknown country api response: %s", config.UnknownCountryAPIResponse)
127+
infoLogger.Printf("blacklist mode: %t", config.BlackListMode)
128+
infoLogger.Printf("add country header: %t", config.AddCountryHeader)
129+
infoLogger.Printf("countries: %v", config.Countries)
130+
}
127131

128132
cache, err := lru.NewLRUCache(config.CacheSize)
129133
if err != nil {
@@ -132,6 +136,7 @@ func New(_ context.Context, next http.Handler, config *Config, name string) (htt
132136

133137
return &GeoBlock{
134138
next: next,
139+
silentStartUp: config.SilentStartUp,
135140
allowLocalRequests: config.AllowLocalRequests,
136141
logLocalRequests: config.LogLocalRequests,
137142
logAllowedRequests: config.LogAllowedRequests,

readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ http:
6060
geoblock-ch:
6161
plugin:
6262
geoblock:
63+
silentStartUp: false
6364
allowLocalRequests: true
6465
logLocalRequests: false
6566
logAllowedRequests: false
@@ -110,6 +111,7 @@ http:
110111
my-GeoBlock:
111112
plugin:
112113
GeoBlock:
114+
silentStartUp: false
113115
allowLocalRequests: true
114116
logLocalRequests: false
115117
logAllowedRequests: false
@@ -167,6 +169,7 @@ This configuration might not work. It's just to give you an idea how to configur
167169
my-GeoBlock:
168170
plugin:
169171
GeoBlock:
172+
silentStartUp: false
170173
allowLocalRequests: false
171174
logLocalRequests: false
172175
logAllowedRequests: false
@@ -433,6 +436,10 @@ my-GeoBlock:
433436

434437
## Configuration options
435438

439+
### Silent start-up: `silentStartUp`
440+
441+
If set to true, the configuration is not written to the output upon the start-up of the plugin.
442+
436443
### Allow local requests: `allowLocalRequests`
437444

438445
If set to true, will not block request from [Private IP Ranges](https://en.wikipedia.org/wiki/Private_network).

0 commit comments

Comments
 (0)