mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(cloudtrail): validate LookupEvents MaxResults (#7183)
* fix(cloudtrail): validate LookupEvents MaxResults * fix(cloudtrail): handle huge LookupEvents numbers * test(cloudtrail): preserve large MaxResults behavior * fix(eventbridge): retry target dispatch scope failures * revert(eventbridge): separate retry fix from CloudTrail PR
This commit is contained in:
1 parent
8499581af3
commit
5556bbae58
2 files changed
+121
No files matched your search
+42
@@ -14,6 +14,7 @@ import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -242,11 +243,52 @@ public class CloudTrailJsonHandler {
|
||||
}
|
||||
|
||||
private Response lookupEvents(JsonNode req, String region) {
|
||||
validateMaxResults(req.path("MaxResults"));
|
||||
ObjectNode resp = mapper.createObjectNode();
|
||||
resp.putArray("Events");
|
||||
return Response.ok(resp).build();
|
||||
}
|
||||
|
||||
/** An omitted or null {@code MaxResults} is optional and takes the service default. */
|
||||
private static void validateMaxResults(JsonNode maxResults) {
|
||||
if (maxResults.isMissingNode() || maxResults.isNull()) {
|
||||
return;
|
||||
}
|
||||
int value;
|
||||
if (maxResults.isNumber()) {
|
||||
double doubleValue = maxResults.doubleValue();
|
||||
if (maxResults.isFloatingPointNumber() && !Double.isFinite(doubleValue)) {
|
||||
value = doubleValue > 0 ? Integer.MAX_VALUE : Integer.MIN_VALUE;
|
||||
} else {
|
||||
BigDecimal number = maxResults.decimalValue();
|
||||
value = number.compareTo(BigDecimal.valueOf(Integer.MIN_VALUE)) < 0
|
||||
? Integer.MIN_VALUE : number.compareTo(BigDecimal.valueOf(Integer.MAX_VALUE)) > 0
|
||||
? Integer.MAX_VALUE : number.intValue();
|
||||
}
|
||||
} else if (maxResults.isTextual()) {
|
||||
throw serialization("STRING_VALUE can not be converted to an Integer");
|
||||
} else if (maxResults.isArray()) {
|
||||
throw serialization("Start of list found where not expected");
|
||||
} else if (maxResults.isObject()) {
|
||||
throw serialization("Start of structure or map found where not expected.");
|
||||
} else {
|
||||
throw serialization((maxResults.booleanValue() ? "TRUE_VALUE" : "FALSE_VALUE")
|
||||
+ " can not be converted to an Integer");
|
||||
}
|
||||
if (value < 1) {
|
||||
throw invalidMaxResults(value);
|
||||
}
|
||||
}
|
||||
|
||||
private static AwsException invalidMaxResults(int value) {
|
||||
return new AwsException("InvalidMaxResultsException",
|
||||
"A max results value of " + value + " is invalid. Specify max results between 1 and 1000.", 400);
|
||||
}
|
||||
|
||||
private static AwsException serialization(String message) {
|
||||
return new AwsException("SerializationException", message, 400);
|
||||
}
|
||||
|
||||
private Response addTags(JsonNode req) {
|
||||
String resourceId = req.path("ResourceId").asText(null);
|
||||
service.addTags(resourceId, parseTagsList(req.path("TagsList")));
|
||||
|
||||
Reference in new issue
Block a user