mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(apigateway): honor limit and position on GetRequestValidators (#9060)
This commit is contained in:
1 parent
d37698ea71
commit
41aa3ba2eb
5 files changed
+129
-45
No files matched your search
@@ -67,6 +67,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Unified AWS API Gateway management endpoints (v1 REST and v2 HTTP).
|
||||
@@ -279,6 +280,16 @@ public class ApiGatewayController {
|
||||
return Pagination.parseMaxResults(limit, "limit", "BadRequestException");
|
||||
}
|
||||
|
||||
private <T> Response pageResponse(PaginatedResult<T> page, Function<T, JsonNode> toNode) {
|
||||
ObjectNode root = objectMapper.createObjectNode();
|
||||
ArrayNode items = root.putArray("item");
|
||||
page.items().forEach(item -> items.add(toNode.apply(item)));
|
||||
if (page.nextToken() != null) {
|
||||
root.put("position", page.nextToken());
|
||||
}
|
||||
return Response.ok(root.toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/restapis/{apiId}/authorizers")
|
||||
public Response getAuthorizers(@Context HttpHeaders headers, @PathParam("apiId") String apiId,
|
||||
@@ -286,13 +297,7 @@ public class ApiGatewayController {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
// Authorizer clashes with the imported API Gateway v2 model
|
||||
PaginatedResult<io.floci.aws.services.apigateway.model.Authorizer> page = service.getAuthorizerPage(region, apiId, pageLimit(limit), position);
|
||||
ObjectNode root = objectMapper.createObjectNode();
|
||||
ArrayNode items = root.putArray("item");
|
||||
page.items().forEach(a -> items.add(toAuthorizerNode(a)));
|
||||
if (page.nextToken() != null) {
|
||||
root.put("position", page.nextToken());
|
||||
}
|
||||
return Response.ok(root.toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
return pageResponse(page, this::toAuthorizerNode);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -1136,13 +1141,11 @@ public class ApiGatewayController {
|
||||
|
||||
@GET
|
||||
@Path("/restapis/{apiId}/requestvalidators")
|
||||
public Response getRequestValidators(@Context HttpHeaders headers, @PathParam("apiId") String apiId) {
|
||||
public Response getRequestValidators(@Context HttpHeaders headers, @PathParam("apiId") String apiId,
|
||||
@QueryParam("limit") String limit, @QueryParam("position") String position) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
List<RequestValidator> validators = service.getRequestValidators(region, apiId);
|
||||
ObjectNode root = objectMapper.createObjectNode();
|
||||
ArrayNode items = root.putArray("item");
|
||||
validators.forEach(v -> items.add(toRequestValidatorNode(v)));
|
||||
return Response.ok(root.toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
PaginatedResult<RequestValidator> page = service.getRequestValidatorPage(region, apiId, pageLimit(limit), position);
|
||||
return pageResponse(page, this::toRequestValidatorNode);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -1259,13 +1262,7 @@ public class ApiGatewayController {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
PaginatedResult<DocumentationPart> page = service.getDocumentationParts(region, apiId, type, name,
|
||||
path, locationStatus, pageLimit(limit), position);
|
||||
ObjectNode root = objectMapper.createObjectNode();
|
||||
ArrayNode items = root.putArray("item");
|
||||
page.items().forEach(part -> items.add(objectMapper.valueToTree(part)));
|
||||
if (page.nextToken() != null) {
|
||||
root.put("position", page.nextToken());
|
||||
}
|
||||
return Response.ok(root.toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
return pageResponse(page, part -> objectMapper.valueToTree(part));
|
||||
}
|
||||
|
||||
@GET
|
||||
|
||||
@@ -1267,18 +1267,16 @@ public class ApiGatewayService implements ResourceProvider, Resettable {
|
||||
|
||||
public PaginatedResult<Authorizer> getAuthorizerPage(String region, String apiId, Integer limit,
|
||||
String position) {
|
||||
List<Authorizer> authorizers = getAuthorizers(region, apiId).stream()
|
||||
.sorted(Comparator.comparing(Authorizer::getId))
|
||||
.toList();
|
||||
return pageById(authorizers, Authorizer::getId, limit, position);
|
||||
return pageById(getAuthorizers(region, apiId), Authorizer::getId, limit, position);
|
||||
}
|
||||
|
||||
/**
|
||||
* One page of a list already sorted by id. The token is the id of the last item returned, and
|
||||
* One page of a list, sorted by id here. The token is the id of the last item returned, and
|
||||
* an unrecognised token is a {@code BadRequestException}, as on AWS.
|
||||
*/
|
||||
private static <T> PaginatedResult<T> pageById(List<T> sorted, Function<T, String> idOf, Integer limit,
|
||||
private static <T> PaginatedResult<T> pageById(List<T> items, Function<T, String> idOf, Integer limit,
|
||||
String position) {
|
||||
List<T> sorted = items.stream().sorted(Comparator.comparing(idOf)).toList();
|
||||
int pageSize = resolvePageSize(limit);
|
||||
int start = 0;
|
||||
if (position != null && !position.isBlank()) {
|
||||
@@ -2371,6 +2369,11 @@ public class ApiGatewayService implements ResourceProvider, Resettable {
|
||||
return requestValidatorStore.scan(k -> k.startsWith(prefix));
|
||||
}
|
||||
|
||||
public PaginatedResult<RequestValidator> getRequestValidatorPage(String region, String apiId, Integer limit,
|
||||
String position) {
|
||||
return pageById(getRequestValidators(region, apiId), RequestValidator::getId, limit, position);
|
||||
}
|
||||
|
||||
public void deleteRequestValidator(String region, String apiId, String validatorId) {
|
||||
getRequestValidator(region, apiId, validatorId);
|
||||
requestValidatorStore.delete(requestValidatorKey(region, apiId, validatorId));
|
||||
@@ -2582,7 +2585,6 @@ public class ApiGatewayService implements ResourceProvider, Resettable {
|
||||
.filter(part -> name == null || name.equals(part.getLocation().get("name")))
|
||||
.filter(part -> path == null || path.equals(part.getLocation().get("path")))
|
||||
.filter(part -> !"UNDOCUMENTED".equals(locationStatus))
|
||||
.sorted(Comparator.comparing(DocumentationPart::getId))
|
||||
.toList();
|
||||
|
||||
return pageById(parts, DocumentationPart::getId, limit, position);
|
||||
|
||||
Reference in new issue
Block a user