mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(apigateway): page GetVpcLinks with limit and position (#9122)
This commit is contained in:
1 parent
334f7ad6e6
commit
a70aa5596c
3 files changed
+84
-5
No files matched your search
@@ -1649,12 +1649,13 @@ public class ApiGatewayController {
|
||||
|
||||
@GET
|
||||
@Path("/vpclinks")
|
||||
public Response getV1VpcLinks(@Context HttpHeaders headers) {
|
||||
public Response getV1VpcLinks(@Context HttpHeaders headers,
|
||||
@QueryParam("limit") String limit, @QueryParam("position") String position) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
ArrayNode items = result.putArray("item");
|
||||
service.getVpcLinks(region).forEach(l -> items.add(toV1VpcLinkNode(l)));
|
||||
return Response.ok(result.toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
// VpcLink clashes with the imported API Gateway v2 model
|
||||
PaginatedResult<io.floci.aws.services.apigateway.model.VpcLink> page =
|
||||
service.getVpcLinkPage(region, pageLimit(limit), position);
|
||||
return pageResponse(page, this::toV1VpcLinkNode);
|
||||
}
|
||||
|
||||
@GET
|
||||
|
||||
@@ -5276,6 +5276,10 @@ public class ApiGatewayService implements ResourceProvider, Resettable {
|
||||
return vpcLinkStore.scan(k -> k.startsWith(region + "::"));
|
||||
}
|
||||
|
||||
public PaginatedResult<VpcLink> getVpcLinkPage(String region, Integer limit, String position) {
|
||||
return pageById(getVpcLinks(region), VpcLink::getId, limit, position);
|
||||
}
|
||||
|
||||
/**
|
||||
* AWS's patch-operation table for a VPC link supports only {@code replace}, and only on
|
||||
* {@code /name} and {@code /description}. Applying anything else is an error rather than a
|
||||
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package io.floci.aws.services.apigateway;
|
||||
|
||||
import io.floci.aws.testing.AwsTestClients;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.http.apache5.Apache5HttpClient;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.apigateway.ApiGatewayClient;
|
||||
import software.amazon.awssdk.services.apigateway.model.BadRequestException;
|
||||
import software.amazon.awssdk.services.apigateway.model.GetVpcLinksResponse;
|
||||
import software.amazon.awssdk.services.apigateway.model.VpcLink;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayVpcLinkPagingIntegrationTest {
|
||||
|
||||
private static final String TARGET_ARN =
|
||||
"arn:aws:elasticloadbalancing:us-east-1:000000000000:loadbalancer/net/test/123";
|
||||
|
||||
private ApiGatewayClient client() {
|
||||
return AwsTestClients.create(ApiGatewayClient.builder(), "test", Region.US_EAST_1,
|
||||
Apache5HttpClient.builder());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getVpcLinksPagesWithLimitAndTheDefaultPageSize() {
|
||||
try (ApiGatewayClient client = client()) {
|
||||
Set<String> created = new HashSet<>();
|
||||
try {
|
||||
for (int i = 0; i < 26; i++) {
|
||||
String name = "PagedLink" + i;
|
||||
created.add(client.createVpcLink(r -> r.name(name).targetArns(TARGET_ARN)).id());
|
||||
}
|
||||
|
||||
GetVpcLinksResponse first = client.getVpcLinks(r -> r.limit(1));
|
||||
assertEquals(1, first.items().size());
|
||||
assertNotNull(first.position());
|
||||
GetVpcLinksResponse second = client.getVpcLinks(r -> r.limit(1).position(first.position()));
|
||||
assertEquals(1, second.items().size());
|
||||
assertNotEquals(first.items().get(0).id(), second.items().get(0).id());
|
||||
|
||||
GetVpcLinksResponse defaultPage = client.getVpcLinks();
|
||||
assertEquals(25, defaultPage.items().size());
|
||||
assertNotNull(defaultPage.position());
|
||||
|
||||
List<String> seen = new ArrayList<>(defaultPage.items().stream().map(VpcLink::id).toList());
|
||||
String position = defaultPage.position();
|
||||
while (position != null) {
|
||||
String next = position;
|
||||
GetVpcLinksResponse page = client.getVpcLinks(r -> r.position(next));
|
||||
seen.addAll(page.items().stream().map(VpcLink::id).toList());
|
||||
position = page.position();
|
||||
}
|
||||
assertEquals(seen.size(), new HashSet<>(seen).size());
|
||||
assertTrue(seen.containsAll(created));
|
||||
|
||||
assertThrows(BadRequestException.class,
|
||||
() -> client.getVpcLinks(r -> r.limit(1).position("missing")));
|
||||
} finally {
|
||||
created.forEach(id -> client.deleteVpcLink(r -> r.vpcLinkId(id)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user