Browse Source
Add rate limiting allowed burst field to settings
feature/add-rate-limiting
Fabian Vowie
3 years ago
No known key found for this signature in database
GPG Key ID: C27317C33B27C410
3 changed files with
20 additions and
9 deletions
-
main.go
-
settings/settings.go
-
settings/settings_test.go
|
|
@ -61,7 +61,7 @@ func main() { |
|
|
|
pipes := pipelines.LoadPipelines() |
|
|
|
|
|
|
|
authMiddleware := middlewares.CreateAuthenticationMiddleware(appSettings.Token) |
|
|
|
rateLimiterMiddleware, err := middlewares.CreateRateLimiterMiddleware(appSettings.RequestsPerMinute, 0) |
|
|
|
rateLimiterMiddleware, err := middlewares.CreateRateLimiterMiddleware(appSettings.RateLimiter.RequestsPerMinute, appSettings.RateLimiter.AllowedBurst) |
|
|
|
if err != nil { |
|
|
|
panic(err) |
|
|
|
} |
|
|
|
|
|
@ -17,7 +17,7 @@ type FileSystemType int |
|
|
|
type Settings struct { |
|
|
|
Endpoint string `json:"endpoint"` |
|
|
|
Token string `json:"token"` |
|
|
|
RequestsPerMinute int `json:"requests_per_minute"` |
|
|
|
RateLimiter RateLimiterSettings `json:"rate_limiter"` |
|
|
|
StorageProvider StorageSettings `json:"storage_provider"` |
|
|
|
} |
|
|
|
|
|
|
@ -26,6 +26,11 @@ type StorageSettings struct { |
|
|
|
BasePath string `json:"base_path"` |
|
|
|
} |
|
|
|
|
|
|
|
type RateLimiterSettings struct { |
|
|
|
RequestsPerMinute int `json:"requests_per_minute"` |
|
|
|
AllowedBurst int `json:"allowed_burst"` |
|
|
|
} |
|
|
|
|
|
|
|
func parseSettings(data []byte) Settings { |
|
|
|
settings := Settings{} |
|
|
|
|
|
|
@ -52,7 +57,10 @@ func LoadSettings(fileSystem afero.Fs) (Settings, error) { |
|
|
|
defaultSettings := Settings{ |
|
|
|
Endpoint: "127.0.0.1:8000", |
|
|
|
Token: "changeme", |
|
|
|
RateLimiter: RateLimiterSettings{ |
|
|
|
RequestsPerMinute: 20, |
|
|
|
AllowedBurst: 5, |
|
|
|
}, |
|
|
|
StorageProvider: StorageSettings{ |
|
|
|
Type: Local, |
|
|
|
BasePath: "assets", |
|
|
|
|
|
@ -13,7 +13,10 @@ func TestSettingsParsing(t *testing.T) { |
|
|
|
const file string = `{ |
|
|
|
"endpoint": "0.0.0.0:8000", |
|
|
|
"token": "foobar", |
|
|
|
"rate_limiter": { |
|
|
|
"requests_per_minute": 20, |
|
|
|
"allowed_burst": 5 |
|
|
|
}, |
|
|
|
"storage_provider": { |
|
|
|
"type": 0, |
|
|
|
"base_path": "assets" |
|
|
|