Skip to content

Commit effed86

Browse files
wwalexanderWill Alexander
andauthored
YAML configuration support (#44)
* 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]>
1 parent 37cbced commit effed86

37 files changed

+2026
-952
lines changed

cmd/guardian-cli/main.go

Lines changed: 380 additions & 110 deletions
Large diffs are not rendered by default.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "v0"
2+
kind: GlobalRateLimit
3+
name: GlobalRateLimit
4+
description: GlobalRateLimit
5+
globalRateLimitSpec:
6+
limit:
7+
count: 5
8+
duration: 1s
9+
enabled: true
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "v0"
2+
kind: GlobalSettings
3+
name: GlobalSettings
4+
description: GlobalSettings
5+
globalSettingsSpec:
6+
reportOnly: false
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "v0"
2+
kind: GlobalRateLimit
3+
name: GlobalRateLimit
4+
description: GlobalRateLimit
5+
globalRateLimitSpec:
6+
limit:
7+
count: 5
8+
duration: 1m
9+
enabled: false
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "v0"
2+
kind: GlobalSettings
3+
name: GlobalSettings
4+
description: GlobalSettings
5+
globalSettingsSpec:
6+
reportOnly: false
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version: "v0"
2+
kind: Jail
3+
name: "/foo/bar"
4+
description: "/foo/bar"
5+
jailSpec:
6+
limit:
7+
count: 10
8+
duration: 10s
9+
enabled: true
10+
conditions:
11+
path: "/foo/bar"
12+
banDuration: 30s # Keep this duration short as it's used in tests
13+
---
14+
version: "v0"
15+
kind: Jail
16+
name: "/foo/baz"
17+
description: "/foo/baz"
18+
jailSpec:
19+
limit:
20+
count: 5
21+
duration: 1m
22+
enabled: false
23+
conditions:
24+
path: "/foo/baz"
25+
banDuration: 30s # Keep this duration short as it's used in tests
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "v0"
2+
kind: GlobalRateLimit
3+
name: GlobalRateLimit
4+
description: GlobalRateLimit
5+
globalRateLimitSpec:
6+
limit:
7+
count: 5
8+
duration: 1m
9+
enabled: false
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "v0"
2+
kind: GlobalSettings
3+
name: GlobalSettings
4+
description: GlobalSettings
5+
globalSettingsSpec:
6+
reportOnly: false
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: "v0"
2+
kind: RateLimit
3+
name: "/foo/bar"
4+
description: "/foo/bar"
5+
rateLimitSpec:
6+
limit:
7+
count: 10
8+
duration: 1m
9+
enabled: true
10+
conditions:
11+
path: "/foo/bar"
12+
---
13+
version: "v0"
14+
kind: RateLimit
15+
name: "/foo/baz"
16+
description: "/foo/baz"
17+
rateLimitSpec:
18+
limit:
19+
count: 5
20+
duration: 1m
21+
enabled: false
22+
conditions:
23+
path: "/foo/baz"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "v0"
2+
kind: GlobalRateLimit
3+
name: GlobalRateLimit
4+
description: GlobalRateLimit
5+
globalRateLimitSpec:
6+
limit:
7+
count: 5
8+
duration: 1m
9+
enabled: true
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "v0"
2+
kind: GlobalSettings
3+
name: GlobalSettings
4+
description: GlobalSettings
5+
globalSettingsSpec:
6+
reportOnly: false
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "v0"
2+
kind: GlobalRateLimit
3+
name: GlobalRateLimit
4+
description: GlobalRateLimit
5+
globalRateLimitSpec:
6+
limit:
7+
count: 5
8+
duration: 1m
9+
enabled: false
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "v0"
2+
kind: GlobalSettings
3+
name: GlobalSettings
4+
description: GlobalSettings
5+
globalSettingsSpec:
6+
reportOnly: false

e2e/config/TestJails/jailconfig.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version: "v0"
2+
kind: Jail
3+
name: "/foo/bar"
4+
description: "/foo/bar"
5+
jailSpec:
6+
limit:
7+
count: 10
8+
duration: 10s
9+
enabled: true
10+
conditions:
11+
path: "/foo/bar"
12+
banDuration: 30s # Keep this duration short as it's used in tests
13+
---
14+
version: "v0"
15+
kind: Jail
16+
name: "/foo/baz"
17+
description: "/foo/baz"
18+
jailSpec:
19+
limit:
20+
count: 5
21+
duration: 1m
22+
enabled: false
23+
conditions:
24+
path: "/foo/baz"
25+
banDuration: 30s # Keep this duration short as it's used in tests

e2e/config/jailconfig.yml renamed to e2e/config/TestJailsDeprecated/jailconfig.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ jails:
55
duration: 10s
66
enabled: true
77
count: 10
8-
ban_duration: 30s # Keep this duration short as it's used in tests
8+
banDuration: 30s # Keep this duration short as it's used in tests
99
- route: "/foo/baz"
1010
jail:
1111
limit:
1212
duration: 1m
1313
enabled: false
1414
count: 5
15-
ban_duration: 30s # Keep this duration short as it's used in tests
15+
banDuration: 30s # Keep this duration short as it's used in tests
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "v0"
2+
kind: GlobalRateLimit
3+
name: GlobalRateLimit
4+
description: GlobalRateLimit
5+
globalRateLimitSpec:
6+
limit:
7+
count: 100
8+
duration: 1s
9+
enabled: false
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "v0"
2+
kind: GlobalSettings
3+
name: GlobalSettings
4+
description: GlobalSettings
5+
globalSettingsSpec:
6+
reportOnly: false
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: "v0"
2+
kind: RateLimit
3+
name: "/foo/bar"
4+
description: "/foo/bar"
5+
rateLimitSpec:
6+
limit:
7+
count: 10
8+
duration: 1m
9+
enabled: true
10+
conditions:
11+
path: "/foo/bar"
12+
---
13+
version: "v0"
14+
kind: RateLimit
15+
name: "/foo/baz"
16+
description: "/foo/baz"
17+
rateLimitSpec:
18+
limit:
19+
count: 5
20+
duration: 1m
21+
enabled: false
22+
conditions:
23+
path: "/foo/baz"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
jails:
2+
- route: "/foo/bar"
3+
jail:
4+
limit:
5+
duration: 10s
6+
enabled: true
7+
count: 10
8+
banDuration: 30s # Keep this duration short as it's used in tests
9+
- route: "/foo/baz"
10+
jail:
11+
limit:
12+
duration: 1m
13+
enabled: false
14+
count: 5
15+
banDuration: 30s # Keep this duration short as it's used in tests
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
route_rate_limits:
2+
- route: "/foo/bar"
3+
limit:
4+
duration: 1m
5+
enabled: true
6+
count: 10
7+
- route: "/foo/baz"
8+
limit:
9+
duration: 1m
10+
enabled: false
11+
count: 5
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
route_rate_limits:
2+
- route: "/foo/bar"
3+
limit:
4+
duration: 1m
5+
enabled: true
6+
count: 10
7+
- route: "/foo/baz"
8+
limit:
9+
duration: 1m
10+
enabled: false
11+
count: 5
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
jails:
2+
- route: "/foo/bar"
3+
jail:
4+
limit:
5+
duration: 10s
6+
enabled: true
7+
count: 10
8+
banDuration: 30s # Keep this duration short as it's used in tests
9+
- route: "/foo/baz"
10+
jail:
11+
limit:
12+
duration: 1m
13+
enabled: false
14+
count: 5
15+
banDuration: 30s # Keep this duration short as it's used in tests
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
route_rate_limits:
2+
- route: "/foo/bar"
3+
limit:
4+
duration: 1m
5+
enabled: true
6+
count: 10
7+
- route: "/foo/baz"
8+
limit:
9+
duration: 1m
10+
enabled: false
11+
count: 5
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "v0"
2+
kind: GlobalRateLimit
3+
name: GlobalRateLimit
4+
description: GlobalRateLimit
5+
globalRateLimitSpec:
6+
limit:
7+
count: 5
8+
duration: 1s
9+
enabled: true
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "v0"
2+
kind: GlobalSettings
3+
name: GlobalSettings
4+
description: GlobalSettings
5+
globalSettingsSpec:
6+
reportOnly: false

e2e/config/routeratelimitconfig.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)