Skip to content

Commit

Permalink
Make rate limiting correlate optional (cloudflare#281)
Browse files Browse the repository at this point in the history
While looking into an issue in the Terraform provider, I've found that
the `correlate` values for rate limiting are always being sent
regardless of whether the value is set or not. This isn't really a big
deal as I'm assuming the API endpoint just disregard it but for the
Terraform provider, it does make the state management more difficult and
messy than what it needs to be due to the nested types.

Instead of always sending the value, I've updated the struct to allow
`nil` and to omit when the values are empty resulting in a fix for the
issues downstream.
  • Loading branch information
jacobbednarz authored and patryk committed Mar 26, 2019
1 parent b688e90 commit 796cf82
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion rate_limiting.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type RateLimit struct {
Threshold int `json:"threshold"`
Period int `json:"period"`
Action RateLimitAction `json:"action"`
Correlate RateLimitCorrelate `json:"correlate"`
Correlate *RateLimitCorrelate `json:"correlate,omitempty"`
}

// RateLimitTrafficMatcher contains the rules that will be used to apply a rate limit to traffic
Expand Down
2 changes: 1 addition & 1 deletion rate_limiting_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var exampleNewRateLimit = cloudflare.RateLimit{
Mode: "ban",
Timeout: 60,
},
Correlate: cloudflare.RateLimitCorrelate{
Correlate: &cloudflare.RateLimitCorrelate{
By: "nat",
},
}
Expand Down
6 changes: 3 additions & 3 deletions rate_limiting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var expectedRateLimitStruct = RateLimit{
Mode: "ban",
Timeout: 60,
},
Correlate: RateLimitCorrelate{
Correlate: &RateLimitCorrelate{
By: "nat",
},
}
Expand All @@ -89,7 +89,7 @@ var expectedRateLimitStructUpdated = RateLimit{
Mode: "ban",
Timeout: 60,
},
Correlate: RateLimitCorrelate{
Correlate: &RateLimitCorrelate{
By: "nat",
},
}
Expand Down Expand Up @@ -260,7 +260,7 @@ func TestCreateRateLimit(t *testing.T) {
Mode: "ban",
Timeout: 60,
},
Correlate: RateLimitCorrelate{
Correlate: &RateLimitCorrelate{
By: "nat",
},
}
Expand Down

0 comments on commit 796cf82

Please sign in to comment.