Skip to content

Commit

Permalink
YAML configuration support (#44)
Browse files Browse the repository at this point in the history
* Add basic YAML configuration support

* Redo multi-document support and get tests running

* Fix incorrect config filename in tests

* Get tests passing

* Add deprecation message to get-* commands

* Remove set deprecation messages from get commands

* Get tests working with deprecated commands

* Don't apply global rate limit during Jails test

* Add full support for new config format

* Add changes to CLI

* Update unit tests to use new Deprecated method names

* Finish updating unit tests to use Deprecated method names

* Remove wayward Println

* Add JSON tags and flags to indicate if deprecated fields are in use

* Add deprecated to main.go function names

* Fix incorrect Kind in e2e jail config YAML

* Add deletion tests for new CLI

* Persist useDeprecated flags to Redis

* Separate config files per test

* Fix deprecated tests using wrong applyGuardianConfig()

* Set GlobalRateLimit and GlobalSettings for deprecated Set* tests

* Add GlobalRateLimit and GlobalSettings to more tests

* Avoid running E2E tests in parallel

* Update CLI help and fix get command bug

Added a deprecated note to the CLI help for the deprecated CLI interface.
Fixed Fetch*Configs() initializing slice with len instead of cap

* Implement easy CR changes and add working stdin `apply`

* Avoid using opaque structs as map keys

* Make unit tests use paths instead of URLs

* Fix get RateLimit not printing

* Use distinct YAML spec keys to simplify decoding

* Fix incorrect spec key for TestDeleteRateLimit

* Cycle through available Redis DBs when testing

* Remove deprecated RedisConfStore methods and fields and update unit tests

* Readability/style changes for CR

* Fix incorrect metric reporting method

Co-authored-by: Will Alexander <[email protected]>
  • Loading branch information
wwalexander and Will Alexander authored Jul 1, 2020
1 parent 37cbced commit effed86
Show file tree
Hide file tree
Showing 37 changed files with 2,026 additions and 952 deletions.
490 changes: 380 additions & 110 deletions cmd/guardian-cli/main.go

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions e2e/config/TestBlacklist/globalratelimitconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "v0"
kind: GlobalRateLimit
name: GlobalRateLimit
description: GlobalRateLimit
globalRateLimitSpec:
limit:
count: 5
duration: 1s
enabled: true
6 changes: 6 additions & 0 deletions e2e/config/TestBlacklist/globalsettingsconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "v0"
kind: GlobalSettings
name: GlobalSettings
description: GlobalSettings
globalSettingsSpec:
reportOnly: false
9 changes: 9 additions & 0 deletions e2e/config/TestDeleteJail/globalratelimitconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "v0"
kind: GlobalRateLimit
name: GlobalRateLimit
description: GlobalRateLimit
globalRateLimitSpec:
limit:
count: 5
duration: 1m
enabled: false
6 changes: 6 additions & 0 deletions e2e/config/TestDeleteJail/globalsettingsconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "v0"
kind: GlobalSettings
name: GlobalSettings
description: GlobalSettings
globalSettingsSpec:
reportOnly: false
25 changes: 25 additions & 0 deletions e2e/config/TestDeleteJail/jailconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "v0"
kind: Jail
name: "/foo/bar"
description: "/foo/bar"
jailSpec:
limit:
count: 10
duration: 10s
enabled: true
conditions:
path: "/foo/bar"
banDuration: 30s # Keep this duration short as it's used in tests
---
version: "v0"
kind: Jail
name: "/foo/baz"
description: "/foo/baz"
jailSpec:
limit:
count: 5
duration: 1m
enabled: false
conditions:
path: "/foo/baz"
banDuration: 30s # Keep this duration short as it's used in tests
9 changes: 9 additions & 0 deletions e2e/config/TestDeleteRateLimit/globalratelimitconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "v0"
kind: GlobalRateLimit
name: GlobalRateLimit
description: GlobalRateLimit
globalRateLimitSpec:
limit:
count: 5
duration: 1m
enabled: false
6 changes: 6 additions & 0 deletions e2e/config/TestDeleteRateLimit/globalsettingsconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "v0"
kind: GlobalSettings
name: GlobalSettings
description: GlobalSettings
globalSettingsSpec:
reportOnly: false
23 changes: 23 additions & 0 deletions e2e/config/TestDeleteRateLimit/ratelimitconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "v0"
kind: RateLimit
name: "/foo/bar"
description: "/foo/bar"
rateLimitSpec:
limit:
count: 10
duration: 1m
enabled: true
conditions:
path: "/foo/bar"
---
version: "v0"
kind: RateLimit
name: "/foo/baz"
description: "/foo/baz"
rateLimitSpec:
limit:
count: 5
duration: 1m
enabled: false
conditions:
path: "/foo/baz"
9 changes: 9 additions & 0 deletions e2e/config/TestGlobalRateLimit/globalratelimitconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "v0"
kind: GlobalRateLimit
name: GlobalRateLimit
description: GlobalRateLimit
globalRateLimitSpec:
limit:
count: 5
duration: 1m
enabled: true
6 changes: 6 additions & 0 deletions e2e/config/TestGlobalRateLimit/globalsettingsconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "v0"
kind: GlobalSettings
name: GlobalSettings
description: GlobalSettings
globalSettingsSpec:
reportOnly: false
9 changes: 9 additions & 0 deletions e2e/config/TestJails/globalratelimitconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "v0"
kind: GlobalRateLimit
name: GlobalRateLimit
description: GlobalRateLimit
globalRateLimitSpec:
limit:
count: 5
duration: 1m
enabled: false
6 changes: 6 additions & 0 deletions e2e/config/TestJails/globalsettingsconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "v0"
kind: GlobalSettings
name: GlobalSettings
description: GlobalSettings
globalSettingsSpec:
reportOnly: false
25 changes: 25 additions & 0 deletions e2e/config/TestJails/jailconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "v0"
kind: Jail
name: "/foo/bar"
description: "/foo/bar"
jailSpec:
limit:
count: 10
duration: 10s
enabled: true
conditions:
path: "/foo/bar"
banDuration: 30s # Keep this duration short as it's used in tests
---
version: "v0"
kind: Jail
name: "/foo/baz"
description: "/foo/baz"
jailSpec:
limit:
count: 5
duration: 1m
enabled: false
conditions:
path: "/foo/baz"
banDuration: 30s # Keep this duration short as it's used in tests
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ jails:
duration: 10s
enabled: true
count: 10
ban_duration: 30s # Keep this duration short as it's used in tests
banDuration: 30s # Keep this duration short as it's used in tests
- route: "/foo/baz"
jail:
limit:
duration: 1m
enabled: false
count: 5
ban_duration: 30s # Keep this duration short as it's used in tests
banDuration: 30s # Keep this duration short as it's used in tests
9 changes: 9 additions & 0 deletions e2e/config/TestRateLimit/globalratelimitconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "v0"
kind: GlobalRateLimit
name: GlobalRateLimit
description: GlobalRateLimit
globalRateLimitSpec:
limit:
count: 100
duration: 1s
enabled: false
6 changes: 6 additions & 0 deletions e2e/config/TestRateLimit/globalsettingsconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "v0"
kind: GlobalSettings
name: GlobalSettings
description: GlobalSettings
globalSettingsSpec:
reportOnly: false
23 changes: 23 additions & 0 deletions e2e/config/TestRateLimit/ratelimitconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "v0"
kind: RateLimit
name: "/foo/bar"
description: "/foo/bar"
rateLimitSpec:
limit:
count: 10
duration: 1m
enabled: true
conditions:
path: "/foo/bar"
---
version: "v0"
kind: RateLimit
name: "/foo/baz"
description: "/foo/baz"
rateLimitSpec:
limit:
count: 5
duration: 1m
enabled: false
conditions:
path: "/foo/baz"
15 changes: 15 additions & 0 deletions e2e/config/TestRemoveJailDeprecated/jailconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
jails:
- route: "/foo/bar"
jail:
limit:
duration: 10s
enabled: true
count: 10
banDuration: 30s # Keep this duration short as it's used in tests
- route: "/foo/baz"
jail:
limit:
duration: 1m
enabled: false
count: 5
banDuration: 30s # Keep this duration short as it's used in tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
route_rate_limits:
- route: "/foo/bar"
limit:
duration: 1m
enabled: true
count: 10
- route: "/foo/baz"
limit:
duration: 1m
enabled: false
count: 5
11 changes: 11 additions & 0 deletions e2e/config/TestRouteRateLimitDeprecated/routeratelimitconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
route_rate_limits:
- route: "/foo/bar"
limit:
duration: 1m
enabled: true
count: 10
- route: "/foo/baz"
limit:
duration: 1m
enabled: false
count: 5
15 changes: 15 additions & 0 deletions e2e/config/TestSetJailsDeprecated/jailconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
jails:
- route: "/foo/bar"
jail:
limit:
duration: 10s
enabled: true
count: 10
banDuration: 30s # Keep this duration short as it's used in tests
- route: "/foo/baz"
jail:
limit:
duration: 1m
enabled: false
count: 5
banDuration: 30s # Keep this duration short as it's used in tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
route_rate_limits:
- route: "/foo/bar"
limit:
duration: 1m
enabled: true
count: 10
- route: "/foo/baz"
limit:
duration: 1m
enabled: false
count: 5
9 changes: 9 additions & 0 deletions e2e/config/TestWhitelist/globalratelimitconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "v0"
kind: GlobalRateLimit
name: GlobalRateLimit
description: GlobalRateLimit
globalRateLimitSpec:
limit:
count: 5
duration: 1s
enabled: true
6 changes: 6 additions & 0 deletions e2e/config/TestWhitelist/globalsettingsconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "v0"
kind: GlobalSettings
name: GlobalSettings
description: GlobalSettings
globalSettingsSpec:
reportOnly: false
11 changes: 0 additions & 11 deletions e2e/config/routeratelimitconfig.yml

This file was deleted.

Loading

0 comments on commit effed86

Please sign in to comment.