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 custom policy replacement handling in validateCustomPolicy method #12691

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,15 @@
if (clientIp != null) {
key = key.replaceAll("\\$clientIp", APIUtil.ipToBigInteger(clientIp).toString());
}
Object customPropertyObj = messageContext.getProperty(APIMgtGatewayConstants.CUSTOM_PROPERTY);

Check warning on line 1283 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/throttling/ThrottleHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/throttling/ThrottleHandler.java#L1283

Added line #L1283 was not covered by tests
if (customPropertyObj != null) {
Map<String, Object> customProperties = (Map<String, Object>) customPropertyObj;

Check warning on line 1285 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/throttling/ThrottleHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/throttling/ThrottleHandler.java#L1285

Added line #L1285 was not covered by tests
for (Map.Entry<String, Object> entry : customProperties.entrySet()) {
String customKey = "\\$customProperty\\." + entry.getKey();

Check warning on line 1287 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/throttling/ThrottleHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/throttling/ThrottleHandler.java#L1287

Added line #L1287 was not covered by tests
String customValue = entry.getValue() != null ? entry.getValue().toString() : "";
key = key.replaceAll(customKey, customValue);
}

Check warning on line 1290 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/throttling/ThrottleHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/throttling/ThrottleHandler.java#L1289-L1290

Added lines #L1289 - L1290 were not covered by tests
}
if (getThrottleDataHolder().isThrottled(key)) {
long timestamp = getThrottleDataHolder().getThrottleNextAccessTimestamp(key);
messageContext.setProperty(APIThrottleConstants.THROTTLED_NEXT_ACCESS_TIMESTAMP, timestamp);
Expand Down
Loading