mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(globalaccelerator): paginate accelerator listings (#6522)
* fix(globalaccelerator): paginate accelerator listings * fix(globalaccelerator): validate pagination field types
This commit is contained in:
1 parent
57257e198f
commit
3aa8149d08
5 files changed
+259
-4
No files matched your search
+21
-1
@@ -6,6 +6,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.Accelerator;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.EndpointGroup;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.PortOverride;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.PortRange;
|
||||
@@ -57,7 +59,25 @@ public class GlobalAcceleratorJsonHandler {
|
||||
service.deleteAccelerator(text(request, "AcceleratorArn"));
|
||||
yield Response.ok(Map.of()).build();
|
||||
}
|
||||
case "ListAccelerators" -> Response.ok(Map.of("Accelerators", service.listAccelerators())).build();
|
||||
case "ListAccelerators" -> {
|
||||
JsonNode maxResults = request.get("MaxResults");
|
||||
if (maxResults != null && !maxResults.isNull()
|
||||
&& (!maxResults.isIntegralNumber() || !maxResults.canConvertToInt())) {
|
||||
throw new AwsException("InvalidArgumentException", "MaxResults must be between 1 and 100", 400);
|
||||
}
|
||||
JsonNode nextToken = request.get("NextToken");
|
||||
if (nextToken != null && !nextToken.isNull() && !nextToken.isTextual()) {
|
||||
throw new AwsException("InvalidNextTokenException", "Invalid NextToken", 400);
|
||||
}
|
||||
PaginatedResult<Accelerator> page = service.listAccelerators(
|
||||
integer(request, "MaxResults"), text(request, "NextToken"));
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("Accelerators", page.items());
|
||||
if (page.nextToken() != null) {
|
||||
result.put("NextToken", page.nextToken());
|
||||
}
|
||||
yield Response.ok(result).build();
|
||||
}
|
||||
case "DescribeAcceleratorAttributes" -> Response.ok(Map.of("AcceleratorAttributes",
|
||||
service.describeAcceleratorAttributes(text(request, "AcceleratorArn")))).build();
|
||||
case "UpdateAcceleratorAttributes" -> Response.ok(Map.of("AcceleratorAttributes",
|
||||
|
||||
+15
@@ -3,6 +3,8 @@ package io.github.hectorvent.floci.services.globalaccelerator;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.Pagination;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
@@ -188,6 +190,19 @@ public class GlobalAcceleratorService {
|
||||
return accelerators.scan(key -> true);
|
||||
}
|
||||
|
||||
public PaginatedResult<Accelerator> listAccelerators(Integer maxResults, String nextToken) {
|
||||
int limit = maxResults != null ? maxResults : 10;
|
||||
if (limit < 1 || limit > 100) {
|
||||
throw new AwsException("InvalidArgumentException", "MaxResults must be between 1 and 100", 400);
|
||||
}
|
||||
if (nextToken != null && nextToken.length() > 255) {
|
||||
throw new AwsException("InvalidNextTokenException", "Invalid NextToken", 400);
|
||||
}
|
||||
String namespace = "ListAccelerators:" + regionResolver.getPartition() + ":" + regionResolver.getAccountId();
|
||||
return Pagination.paginate(listAccelerators(), Accelerator::getAcceleratorArn, limit, nextToken, namespace,
|
||||
token -> new AwsException("InvalidNextTokenException", "Invalid NextToken", 400));
|
||||
}
|
||||
|
||||
public AcceleratorAttributes describeAcceleratorAttributes(String acceleratorArn) {
|
||||
describeAccelerator(acceleratorArn);
|
||||
return acceleratorAttributes.get(acceleratorArn).orElseGet(GlobalAcceleratorService::defaultAttributes);
|
||||
|
||||
Reference in new issue
Block a user