mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(route53): honor hosted zone pagination markers (#6932)
* fix(route53): honor hosted zone pagination markers * test(route53): reuse shared SDK client fixture
This commit is contained in:
1 parent
b063f7ff8c
commit
dfefef2437
4 files changed
+149
-7
No files matched your search
@@ -143,9 +143,10 @@ public class Route53Controller {
|
||||
public Response listHostedZones(@QueryParam("marker") String marker,
|
||||
@QueryParam("maxitems") @DefaultValue("100") int maxItems) {
|
||||
try {
|
||||
List<HostedZone> zones = service.listHostedZones(marker, maxItems);
|
||||
long total = service.getHostedZoneCount();
|
||||
boolean truncated = zones.size() == maxItems && zones.size() < total;
|
||||
int lookaheadLimit = maxItems > 0 && maxItems < Integer.MAX_VALUE ? maxItems + 1 : maxItems;
|
||||
List<HostedZone> remaining = service.listHostedZones(marker, lookaheadLimit);
|
||||
boolean truncated = maxItems > 0 && remaining.size() > maxItems;
|
||||
List<HostedZone> zones = truncated ? remaining.subList(0, maxItems) : remaining;
|
||||
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("ListHostedZonesResponse", NS)
|
||||
@@ -156,8 +157,8 @@ public class Route53Controller {
|
||||
xml.end("HostedZones")
|
||||
.elem("Marker", marker != null ? marker : "")
|
||||
.elem("IsTruncated", String.valueOf(truncated));
|
||||
if (truncated && !zones.isEmpty()) {
|
||||
xml.elem("NextMarker", zones.get(zones.size() - 1).getId());
|
||||
if (truncated) {
|
||||
xml.elem("NextMarker", remaining.get(maxItems).getId());
|
||||
}
|
||||
xml.elem("MaxItems", String.valueOf(maxItems))
|
||||
.end("ListHostedZonesResponse");
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.security.SecureRandom;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -163,7 +164,7 @@ public class Route53Service implements Resettable {
|
||||
|
||||
public List<HostedZone> listHostedZones(String marker, int maxItems) {
|
||||
List<HostedZone> all = new ArrayList<>(zoneStore.scan(k -> true));
|
||||
all.sort((a, b) -> a.getName().compareTo(b.getName()));
|
||||
all.sort(Comparator.comparing(HostedZone::getName).thenComparing(HostedZone::getId));
|
||||
for (HostedZone zone : all) {
|
||||
zone.setResourceRecordSetCount(recordCount(zone.getId()));
|
||||
}
|
||||
@@ -171,7 +172,7 @@ public class Route53Service implements Resettable {
|
||||
int idx = 0;
|
||||
for (int i = 0; i < all.size(); i++) {
|
||||
if (all.get(i).getId().equals(marker)) {
|
||||
idx = i + 1;
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user