mirror of
https://github.com/floci-io/floci.git
synced 2026-12-06 11:38:06 -05:00
fix(apigateway): page GetDomainNames with limit and position (#10261)
GetDomainNames ignored limit and position and returned every custom domain name at once. Page it with the shared pageById helper the other REST API listings use: domain names sorted by name, 25 per page by default, up to 500, and a position that is the last domain name of the previous page. Closes #9023
This commit is contained in:
1 parent
19dd82f06e
commit
df066dabcb
4 files changed
+64
-13
No files matched your search
@@ -210,6 +210,12 @@ A nonterminal page includes `position`; the final page omits it. An unknown or b
|
||||
is a `BadRequestException`. `includeValues` applies to every page. `name` keeps the keys whose
|
||||
name starts with it and `customerId` the keys of that customer; both apply before paging.
|
||||
|
||||
### Domain Name Pagination
|
||||
|
||||
`GetDomainNames` accepts `limit` and `position`, returns 25 domain names by default and caps pages
|
||||
at 500. A nonterminal page includes `position`; the final page omits it. An unknown or blank
|
||||
`position` is a `BadRequestException`.
|
||||
|
||||
### Base Path Mapping Pagination
|
||||
|
||||
`GetBasePathMappings` accepts `limit` and `position`, returns 25 mappings by default,
|
||||
|
||||
@@ -1329,6 +1329,7 @@ public class ApiGatewayController {
|
||||
@GET
|
||||
@Path("/domainnames")
|
||||
public Response getDomainNames(@Context HttpHeaders headers,
|
||||
@QueryParam("limit") String limit, @QueryParam("position") String position,
|
||||
@Context UriInfo uriInfo) {
|
||||
String resourceOwner = uriInfo.getQueryParameters().getFirst("resourceOwner");
|
||||
List<String> owners = List.of("SELF", "OTHER_ACCOUNTS");
|
||||
@@ -1337,11 +1338,9 @@ public class ApiGatewayController {
|
||||
SmithyValidationErrors.notInEnum(resourceOwner, "resourceOwner", owners));
|
||||
}
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
List<CustomDomain> domains = service.getDomainNames(region);
|
||||
ObjectNode root = objectMapper.createObjectNode();
|
||||
ArrayNode items = root.putArray("item");
|
||||
domains.forEach(d -> items.add(toDomainNode(region, d)));
|
||||
return Response.ok(root.toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
PaginatedResult<CustomDomain> page =
|
||||
service.getDomainNamePage(region, pageLimit(limit), requestedPosition(position, uriInfo));
|
||||
return pageResponse(page, domain -> toDomainNode(region, domain));
|
||||
}
|
||||
|
||||
@GET
|
||||
|
||||
@@ -3070,6 +3070,10 @@ public class ApiGatewayService implements ResourceProvider, Resettable, PassedRo
|
||||
return domainStore.scan(k -> k.startsWith(prefix));
|
||||
}
|
||||
|
||||
public PaginatedResult<CustomDomain> getDomainNamePage(String region, Integer limit, String position) {
|
||||
return pageById(getDomainNames(region), CustomDomain::getDomainName, limit, position);
|
||||
}
|
||||
|
||||
public void deleteDomainName(String region, String domainName) {
|
||||
synchronized (domainNameLock) {
|
||||
getDomainName(region, domainName);
|
||||
|
||||
+50
-8
@@ -7,6 +7,8 @@ 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.DomainName;
|
||||
import software.amazon.awssdk.services.apigateway.model.GetDomainNamesResponse;
|
||||
import software.amazon.awssdk.services.apigateway.model.GetRestApisResponse;
|
||||
import software.amazon.awssdk.services.apigateway.model.RestApi;
|
||||
|
||||
@@ -14,6 +16,8 @@ import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
@@ -31,6 +35,19 @@ class ApiGatewayRestApiPagingIntegrationTest {
|
||||
Apache5HttpClient.builder());
|
||||
}
|
||||
|
||||
/** The ids on {@code first} and on every page after it, following each page's position. */
|
||||
private static <P> List<String> idsFrom(P first, Function<P, List<String>> idsOf, Function<P, String> positionOf,
|
||||
Function<String, P> pageAt) {
|
||||
List<String> seen = new ArrayList<>(idsOf.apply(first));
|
||||
String position = positionOf.apply(first);
|
||||
while (position != null) {
|
||||
P page = pageAt.apply(position);
|
||||
seen.addAll(idsOf.apply(page));
|
||||
position = positionOf.apply(page);
|
||||
}
|
||||
return seen;
|
||||
}
|
||||
|
||||
@Test
|
||||
void getRestApisPagesWithLimitAndTheDefaultPageSize() {
|
||||
try (ApiGatewayClient client = client()) {
|
||||
@@ -52,14 +69,8 @@ class ApiGatewayRestApiPagingIntegrationTest {
|
||||
assertEquals(25, defaultPage.items().size());
|
||||
assertNotNull(defaultPage.position());
|
||||
|
||||
List<String> seen = new ArrayList<>(defaultPage.items().stream().map(RestApi::id).toList());
|
||||
String position = defaultPage.position();
|
||||
while (position != null) {
|
||||
String next = position;
|
||||
GetRestApisResponse page = client.getRestApis(r -> r.position(next));
|
||||
seen.addAll(page.items().stream().map(RestApi::id).toList());
|
||||
position = page.position();
|
||||
}
|
||||
List<String> seen = idsFrom(defaultPage, page -> page.items().stream().map(RestApi::id).toList(),
|
||||
GetRestApisResponse::position, position -> client.getRestApis(r -> r.position(position)));
|
||||
assertEquals(seen.size(), new HashSet<>(seen).size());
|
||||
assertTrue(seen.containsAll(created));
|
||||
|
||||
@@ -71,6 +82,36 @@ class ApiGatewayRestApiPagingIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void getDomainNamesPagesWithLimitAndTheDefaultPageSize() {
|
||||
try (ApiGatewayClient client = client()) {
|
||||
List<String> created = IntStream.range(0, 26).mapToObj(i -> "paged-" + i + ".example.com").toList();
|
||||
created.forEach(name -> client.createDomainName(r -> r.domainName(name)));
|
||||
try {
|
||||
GetDomainNamesResponse first = client.getDomainNames(r -> r.limit(1));
|
||||
assertEquals(1, first.items().size());
|
||||
assertNotNull(first.position());
|
||||
GetDomainNamesResponse second = client.getDomainNames(r -> r.limit(1).position(first.position()));
|
||||
assertEquals(1, second.items().size());
|
||||
assertNotEquals(first.items().get(0).domainName(), second.items().get(0).domainName());
|
||||
|
||||
GetDomainNamesResponse defaultPage = client.getDomainNames();
|
||||
assertEquals(25, defaultPage.items().size());
|
||||
assertNotNull(defaultPage.position());
|
||||
List<String> seen = idsFrom(defaultPage,
|
||||
page -> page.items().stream().map(DomainName::domainName).toList(),
|
||||
GetDomainNamesResponse::position, position -> client.getDomainNames(r -> r.position(position)));
|
||||
assertEquals(seen.size(), new HashSet<>(seen).size());
|
||||
assertTrue(seen.containsAll(created));
|
||||
|
||||
assertThrows(BadRequestException.class,
|
||||
() -> client.getDomainNames(r -> r.limit(1).position("missing.example.com")));
|
||||
} finally {
|
||||
created.forEach(name -> client.deleteDomainName(r -> r.domainName(name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void everyCollectionRefusesAnEmptyOrBlankPosition() {
|
||||
try (ApiGatewayClient client = client()) {
|
||||
@@ -89,6 +130,7 @@ class ApiGatewayRestApiPagingIntegrationTest {
|
||||
"/restapis/" + apiId + "/documentation/parts",
|
||||
"/usageplans",
|
||||
"/usageplans/" + planId + "/keys",
|
||||
"/domainnames",
|
||||
"/domainnames/" + domainName + "/basepathmappings",
|
||||
"/vpclinks");
|
||||
for (String collection : collections) {
|
||||
|
||||
Reference in new issue
Block a user