Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for evaluation window for rate limit #639

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ dependencies {
implementation 'com.google.guava:guava:23.0'
implementation 'com.psddev:dari-util:3.3.607-xe0f27a'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0'
implementation enforcedPlatform('software.amazon.awssdk:bom:2.24.6')
implementation enforcedPlatform('software.amazon.awssdk:bom:2.25.5')
implementation 'software.amazon.awssdk:apache-client'
implementation 'software.amazon.awssdk:apigatewayv2'
implementation 'software.amazon.awssdk:autoscaling'
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/gyro/aws/wafv2/RateBasedStatementResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import gyro.core.validation.CollectionMax;
import gyro.core.validation.Min;
import gyro.core.validation.Required;
import gyro.core.validation.ValidNumbers;
import gyro.core.validation.ValidStrings;
import gyro.core.validation.ValidationError;
import software.amazon.awssdk.services.wafv2.model.RateBasedStatement;
Expand All @@ -39,6 +40,7 @@ public class RateBasedStatementResource extends Diffable implements Copyable<Rat
private StatementResource scopeDownStatement;
private Set<RateBasedStatementCustomKeyResource> customKeys;
private RateLimitForwardedIpConfigResource forwardedIpConfig;
private Long evaluationWindow;

/**
* The aggregate key type for the rate based statement. Defaults to ``IP``.
Expand Down Expand Up @@ -113,6 +115,23 @@ public void setForwardedIpConfig(RateLimitForwardedIpConfigResource forwardedIpC
this.forwardedIpConfig = forwardedIpConfig;
}

/**
* The evaluation window in sec for the rate based statement. Defaults to ``300``.
*/
@Updatable
@ValidNumbers({ 60, 120, 300, 600 })
public Long getEvaluationWindow() {
if (evaluationWindow == null) {
evaluationWindow = 300L;
}

return evaluationWindow;
}

public void setEvaluationWindow(Long evaluationWindow) {
this.evaluationWindow = evaluationWindow;
}

@Override
public String primaryKey() {
return String.format(
Expand Down Expand Up @@ -152,12 +171,15 @@ public void copyFrom(RateBasedStatement rateBasedStatement) {
forwardedIpConfig.copyFrom(rateBasedStatement.forwardedIPConfig());
setForwardedIpConfig(forwardedIpConfig);
}

setEvaluationWindow(rateBasedStatement.evaluationWindowSec());
}

RateBasedStatement toRateBasedStatement() {
RateBasedStatement.Builder builder = RateBasedStatement.builder()
.aggregateKeyType(getAggregateKeyType())
.limit(getLimit());
.limit(getLimit())
.evaluationWindowSec(getEvaluationWindow());

if (getScopeDownStatement() != null) {
builder = builder.scopeDownStatement(getScopeDownStatement().toStatement());
Expand Down
Loading