mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(stepfunctions): paginate ListActivities results (#6181)
* fix(stepfunctions): paginate ListActivities results * fix(stepfunctions): validate ListActivities token length
This commit is contained in:
1 parent
2ecc01b3e5
commit
2d1fbf33eb
3 files changed
+152
-6
No files matched your search
+10
-6
@@ -552,15 +552,19 @@ public class StepFunctionsJsonHandler {
|
||||
}
|
||||
|
||||
private Response handleListActivities(JsonNode request, String region) {
|
||||
List<Activity> list = service.listActivities(region);
|
||||
PaginatedResult<Activity> page = service.listActivities(region,
|
||||
parseOptionalInt(request, "maxResults"), optionalText(request, "nextToken"));
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode array = response.putArray("activities");
|
||||
for (Activity a : list) {
|
||||
for (Activity a : page.items()) {
|
||||
ObjectNode item = array.addObject();
|
||||
item.put("activityArn", a.getActivityArn());
|
||||
item.put("name", a.getName());
|
||||
item.put("creationDate", a.getCreationDate());
|
||||
}
|
||||
if (page.nextToken() != null) {
|
||||
response.put("nextToken", page.nextToken());
|
||||
}
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
@@ -696,9 +700,9 @@ public class StepFunctionsJsonHandler {
|
||||
|
||||
/**
|
||||
* Reads an optional integer field from the JSON request, rejecting wrong types
|
||||
* with a typed ValidationException. JsonNode.asInt() silently coerces strings,
|
||||
* fractional numbers, and explicit nulls to 0, which would let invalid payloads
|
||||
* slip through as 0 (and thus be treated as "use default" by the service).
|
||||
* with a typed ValidationException. JsonNode.intValue() silently truncates
|
||||
* out-of-range integers, while asInt() also coerces wrong types to 0; either
|
||||
* can make an invalid value look like "use default" to the service.
|
||||
* Returns null when the field is absent or explicitly null in the JSON.
|
||||
*/
|
||||
private static Integer parseOptionalInt(JsonNode request, String fieldName) {
|
||||
@@ -706,7 +710,7 @@ public class StepFunctionsJsonHandler {
|
||||
if (node == null || node.isNull()) {
|
||||
return null;
|
||||
}
|
||||
if (!node.isIntegralNumber()) {
|
||||
if (!node.isIntegralNumber() || !node.canConvertToInt()) {
|
||||
throw new AwsException("ValidationException",
|
||||
"Value '" + node + "' at '" + fieldName
|
||||
+ "' failed to satisfy constraint: Member must be an integer.", 400);
|
||||
|
||||
+13
@@ -1144,6 +1144,19 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
|
||||
return activityStore.scan(k -> k.startsWith(prefix) && k.contains(":activity:"));
|
||||
}
|
||||
|
||||
public PaginatedResult<Activity> listActivities(String region, Integer maxResults, String nextToken) {
|
||||
if (maxResults != null && (maxResults < 0 || maxResults > 1000)) {
|
||||
throw new AwsException("ValidationException", "maxResults must be between 0 and 1000.", 400);
|
||||
}
|
||||
if (nextToken != null && (nextToken.isEmpty() || nextToken.length() > 1024)) {
|
||||
throw new AwsException("ValidationException", "nextToken length must be between 1 and 1024.", 400);
|
||||
}
|
||||
int pageSize = maxResults == null || maxResults == 0 ? 100 : maxResults;
|
||||
return Pagination.paginate(listActivities(region), Activity::getActivityArn, pageSize, nextToken,
|
||||
"states:activities:" + region,
|
||||
token -> new AwsException("InvalidToken", "Invalid nextToken.", 400));
|
||||
}
|
||||
|
||||
public void deleteActivity(String arn) {
|
||||
activityStore.delete(arn);
|
||||
activityQueues.remove(arn);
|
||||
|
||||
Reference in new issue
Block a user