feat(ses): paginate the identity, configuration set and custom verification template lists (#4781)

* feat(ses): paginate the identity, configuration set and custom verification template lists

Move paging into the SES services, so each resource's cursor lives with its
list and the v1 and v2 operations of the same resource share it. Page
ListIdentities/ListEmailIdentities, ListConfigurationSets (v1 and v2) and
ListCustomVerificationEmailTemplates (v1 and v2) with the probed defaults,
bounds and messages: identities default to 25 on v2, configuration sets and
custom verification templates to 50, and a v1 page size outside the bound is
served the probed size instead of refused.

* fix(ses): refuse a list token replayed in another region

A list token carried only the resource kind and the cursor, so the same list
in another region read it as a position and could answer an empty last page.
Real SES refuses such a token with the operation's unreadable-token error
(probed on the identity and configuration-set lists), so the token namespace
now includes the region. The v1 and v2 lists of one resource still share
tokens within a region.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-09-30 23:29:35 -05:00
1 parent 275d874fed
commit ea41b775aa
26 files changed
+1099 -85

No files matched your search

@@ -6,6 +6,7 @@ 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.core.common.RegionResolver;
import io.github.hectorvent.floci.services.ses.model.ArchivingOptions;
import io.github.hectorvent.floci.services.ses.model.ConfigurationSet;
@@ -26,6 +27,7 @@ import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;
@@ -143,14 +145,18 @@ public class SesConfigurationSetController {
@GET
@Path("/configuration-sets")
public Response listConfigurationSets(@Context HttpHeaders headers) {
public Response listConfigurationSets(@Context HttpHeaders headers,
@QueryParam("PageSize") String pageSize,
@QueryParam("NextToken") String nextToken) {
String region = regionResolver.resolveRegion(headers);
List<ConfigurationSet> all = configSetService.list(region);
PaginatedResult<ConfigurationSet> page = configSetService.list(region,
SesListPaging.V2_LIST_CONFIGURATION_SETS, SesListPaging.parseQueryPageSize(pageSize), nextToken);
ObjectNode result = objectMapper.createObjectNode();
ArrayNode arr = result.putArray("ConfigurationSets");
for (ConfigurationSet cs : all) {
for (ConfigurationSet cs : page.items()) {
arr.add(cs.getName());
}
result.put("NextToken", page.nextToken());
return Response.ok(result).build();
}
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.ses;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.ses.model.ArchivingOptions;
@@ -128,14 +129,17 @@ public class SesConfigurationSetService {
"Configuration set <" + name + "> does not exist.", 400));
}
public PaginatedResult<ConfigurationSet> list(String region, SesListPaging paging, Integer pageSize,
String nextToken) {
return paging.page(region, list(region), ConfigurationSet::getName, pageSize, nextToken);
}
/** By name, as SES lists them; the paged lists resume on the same order. */
public List<ConfigurationSet> list(String region) {
String prefix = "configSet::" + region + "::";
List<ConfigurationSet> all = new ArrayList<>(configSetStore.scan(k -> k.startsWith(prefix)));
all.sort(Comparator.comparing(ConfigurationSet::getCreatedTimestamp,
Comparator.nullsLast(Comparator.naturalOrder()))
.thenComparing(ConfigurationSet::getName,
Comparator.nullsLast(Comparator.naturalOrder())));
return all;
return configSetStore.scan(k -> k.startsWith(prefix)).stream()
.sorted(Comparator.comparing(ConfigurationSet::getName))
.toList();
}
/** The raw removal; existence and the tenant delete-guard are the facade's orchestration. */
@@ -6,6 +6,7 @@ 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.core.common.RegionResolver;
import io.github.hectorvent.floci.services.ses.model.CustomVerificationEmailTemplate;
import jakarta.inject.Inject;
@@ -17,13 +18,13 @@ import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.jboss.logging.Logger;
import java.util.List;
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
@@ -79,15 +80,19 @@ public class SesCvetController {
@GET
@Path("/custom-verification-email-templates")
public Response listCustomVerificationEmailTemplates(@Context HttpHeaders headers) {
public Response listCustomVerificationEmailTemplates(@Context HttpHeaders headers,
@QueryParam("PageSize") String pageSize,
@QueryParam("NextToken") String nextToken) {
String region = regionResolver.resolveRegion(headers);
PaginatedResult<CustomVerificationEmailTemplate> page = cvetService.listCustomVerificationEmailTemplates(
region, SesListPaging.V2_LIST_CUSTOM_VERIFICATION_EMAIL_TEMPLATES,
SesListPaging.parseQueryPageSize(pageSize), nextToken);
ObjectNode result = objectMapper.createObjectNode();
ArrayNode items = result.putArray("CustomVerificationEmailTemplates");
List<CustomVerificationEmailTemplate> templates =
cvetService.listCustomVerificationEmailTemplates(region);
for (CustomVerificationEmailTemplate t : templates) {
for (CustomVerificationEmailTemplate t : page.items()) {
items.add(cvetJson(t, false));
}
result.put("NextToken", page.nextToken());
return Response.ok(result).build();
}
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.ses;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.ses.model.CustomVerificationEmailTemplate;
@@ -72,6 +73,13 @@ public class SesCvetService {
return cvetStore.get(cvetKey(region, templateName)).orElseThrow(() -> cvetNotFound(templateName));
}
public PaginatedResult<CustomVerificationEmailTemplate> listCustomVerificationEmailTemplates(
String region, SesListPaging paging, Integer pageSize, String nextToken) {
return paging.page(region, listCustomVerificationEmailTemplates(region),
CustomVerificationEmailTemplate::getTemplateName, pageSize, nextToken);
}
/** By name; SES's own order could not be observed, since creating one needs a verified sender. */
public List<CustomVerificationEmailTemplate> listCustomVerificationEmailTemplates(String region) {
String prefix = "cvet::" + region + "::";
return cvetStore.scan(k -> k.startsWith(prefix)).stream()
@@ -107,10 +107,8 @@ public class SesExportJobController {
String jobStatus = stringMemberOrAbsent(request, "JobStatus");
Integer pageSize = intMemberOrAbsent(request, "PageSize");
String nextToken = stringMemberOrAbsent(request, "NextToken");
PaginatedResult<ExportJob> page = SesListPaging.V2_LIST_EXPORT_JOBS.page(
exportJobService.listExportJobs(region, sourceType, jobStatus),
job -> SesListPaging.newestFirst(job.getCreatedTimestamp(), job.getJobId()),
pageSize, nextToken);
PaginatedResult<ExportJob> page = exportJobService.listExportJobs(region, sourceType, jobStatus,
SesListPaging.V2_LIST_EXPORT_JOBS, pageSize, nextToken);
ObjectNode result = objectMapper.createObjectNode();
ArrayNode jobs = result.putArray("ExportJobs");
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.RequestScopes;
import io.github.hectorvent.floci.core.common.Resettable;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
@@ -26,6 +27,7 @@ import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -376,6 +378,14 @@ public class SesExportJobService implements Resettable {
PRESIGNED_URL_EXPIRY_SECONDS, job.getRegion()));
}
/** Floci validates the filters before the page size and token. */
public PaginatedResult<ExportJob> listExportJobs(String region, String sourceType, String jobStatus,
SesListPaging paging, Integer pageSize, String nextToken) {
return paging.page(region, listExportJobs(region, sourceType, jobStatus), SesExportJobService::cursor,
pageSize, nextToken);
}
/** Newest first, as SES lists them; the paged list resumes on the same order. */
public List<ExportJob> listExportJobs(String region, String sourceType, String jobStatus) {
if (sourceType != null && !SOURCE_TYPES.contains(sourceType)) {
throw new AwsException("BadRequestException",
@@ -392,9 +402,14 @@ public class SesExportJobService implements Resettable {
return exportJobStore.scan(k -> k.startsWith(keyPrefix(region))).stream()
.filter(job -> sourceType == null || sourceType.equals(job.getExportSourceType()))
.filter(job -> jobStatus == null || jobStatus.equals(job.getJobStatus()))
.sorted(Comparator.comparing(SesExportJobService::cursor))
.toList();
}
private static String cursor(ExportJob job) {
return SesListPaging.newestFirst(job.getCreatedTimestamp(), job.getJobId());
}
public void cancelExportJob(String region, String jobId) {
synchronized (createLock) {
ExportJob job = getExportJob(region, jobId);
@@ -6,6 +6,7 @@ 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.core.common.RegionResolver;
import io.github.hectorvent.floci.services.ses.model.Identity;
import io.github.hectorvent.floci.services.ses.model.Tag;
@@ -18,6 +19,7 @@ import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;
@@ -121,13 +123,16 @@ public class SesIdentityController {
@GET
@Path("/identities")
public Response listEmailIdentities(@Context HttpHeaders headers) {
public Response listEmailIdentities(@Context HttpHeaders headers,
@QueryParam("PageSize") String pageSize,
@QueryParam("NextToken") String nextToken) {
String region = regionResolver.resolveRegion(headers);
List<Identity> identities = identityService.listIdentities(null, region);
PaginatedResult<Identity> page = identityService.listIdentities(null, region,
SesListPaging.V2_LIST_EMAIL_IDENTITIES, SesListPaging.parseQueryPageSize(pageSize), nextToken);
ObjectNode result = objectMapper.createObjectNode();
ArrayNode items = result.putArray("EmailIdentities");
for (Identity id : identities) {
for (Identity id : page.items()) {
// Only a not-yet-verified domain can still transition (via its DKIM records),
// so refresh just those; refreshing every identity would scan Route53 per call.
Identity current = id;
@@ -145,6 +150,7 @@ public class SesIdentityController {
item.put("VerificationStatus", toV2Status(current.getVerificationStatus()));
items.add(item);
}
result.put("NextToken", page.nextToken());
return Response.ok(result).build();
}
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.ses;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.route53.Route53Service;
@@ -18,6 +19,7 @@ import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
@@ -185,13 +187,23 @@ public class SesIdentityService {
return id != null && "Success".equals(id.getVerificationStatus());
}
/**
* The cursor is the identity name and carries no type filter: a token taken with
* {@code IdentityType=Domain} continues the unfiltered list when reused without the filter, as
* on SES.
*/
public PaginatedResult<Identity> listIdentities(String identityType, String region, SesListPaging paging,
Integer pageSize, String nextToken) {
return paging.page(region, listIdentities(identityType, region), Identity::getIdentity, pageSize,
nextToken);
}
/** By name, the order Floci settles on where SES's own varies between calls. */
public List<Identity> listIdentities(String identityType, String region) {
List<Identity> all = identityStore.scan(k -> k.startsWith(keyPrefix(region)));
if (identityType == null || identityType.isBlank()) {
return all;
}
return all.stream()
.filter(i -> identityType.equals(i.getIdentityType()))
return identityStore.scan(k -> k.startsWith(keyPrefix(region))).stream()
.filter(i -> identityType == null || identityType.isBlank()
|| identityType.equals(i.getIdentityType()))
.sorted(Comparator.comparing(Identity::getIdentity))
.toList();
}
@@ -3,33 +3,65 @@ package io.github.hectorvent.floci.services.ses;
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.services.ses.model.EmailTemplate;
import java.time.Instant;
import java.util.List;
import java.util.function.Function;
/**
* Paging rules of the SES list operations. Probe-confirmed against real SES (2026-09-25): the
* page-size bound, both error messages and the treatment of an empty token differ per operation,
* while the token itself belongs to the kind of resource listed, so the v1 and v2 lists of the
* same resources accept each other's tokens and refuse any other list's. Without a page size the
* template lists serve 10 (probed 2026-09-26); the export-job default is not documented or
* measured and is taken to be the bound.
* Paging rules of the SES list operations. Probe-confirmed against real SES (2026-09-25 to
* 2026-09-27): the default page size, the bound, both error messages, what a v1 out-of-range
* value is served and the treatment of an empty token differ per operation, while the token itself
* belongs to the kind of resource listed, so the v1 and v2 lists of the same resources accept each
* other's tokens and refuse any other list's. A token is also bound to the region it was issued in:
* replayed in another region (probed 2026-10-01 on the identity and configuration-set lists), it
* is refused with the operation's unreadable-token error. Defaults nobody could measure are noted
* per constant.
*/
enum SesListPaging {
public enum SesListPaging {
V2_LIST_EMAIL_TEMPLATES(Namespace.TEMPLATE, 10, 100,
size -> badRequest("The page size must be between 1 and 100"),
token -> badRequest("Invalid PageToken <" + token + ">."),
false),
/** v1 serves a page of the bound for an out-of-range {@code MaxItems} instead of refusing it. */
V1_LIST_TEMPLATES(Namespace.TEMPLATE, 10, 100,
null,
V1_LIST_TEMPLATES(Namespace.TEMPLATE, 10, 100, 100,
token -> invalidParameterValue("Invalid PageToken <" + token + ">."),
false),
V2_LIST_EMAIL_IDENTITIES(Namespace.IDENTITY, 25, 1000,
size -> badRequest("Value " + size + " for parameter PageSize is invalid. "
+ "PageSize must be between 1 and 1000."),
token -> badRequest("Invalid NextToken <" + token + ">."),
false),
/** 195 identities came back whole without a MaxItems, so the default is taken to be the bound. */
V1_LIST_IDENTITIES(Namespace.IDENTITY, 1000, 1000,
size -> invalidParameterValue("Value " + size + " for parameter MaxItems is invalid. "
+ "MaxItems must be between 1 and 1000."),
token -> invalidParameterValue("Invalid NextToken <" + token + ">."),
false),
V2_LIST_CONFIGURATION_SETS(Namespace.CONFIGURATION_SET, 50, 1000,
size -> badRequest("The page size must be between 1 and 1000"),
token -> badRequest("invalid nextToken " + token),
false),
/** 1001 was served the default, so the bound is taken to be 1000; SES never refuses a value. */
V1_LIST_CONFIGURATION_SETS(Namespace.CONFIGURATION_SET, 50, 1000, 50,
token -> new AwsException("InvalidParameterValue", null, 400),
false),
V2_LIST_CUSTOM_VERIFICATION_EMAIL_TEMPLATES(Namespace.CUSTOM_VERIFICATION_EMAIL_TEMPLATE, 50, 50,
size -> badRequest("The page size must be between 1 and 50"),
token -> badRequest("Invalid nextToken <" + token + ">."),
false),
V1_LIST_CUSTOM_VERIFICATION_EMAIL_TEMPLATES(Namespace.CUSTOM_VERIFICATION_EMAIL_TEMPLATE, 50, 50, 50,
token -> invalidParameterValue("Invalid nextToken <" + token + ">."),
false),
/** AWS documents no default; it is taken to be the bound. */
V2_LIST_EXPORT_JOBS(Namespace.EXPORT_JOB, 100, 100,
size -> badRequest("PageSize must be between 1 and 100"),
token -> badRequest("Failed to deserialize token. "),
@@ -37,6 +69,9 @@ enum SesListPaging {
private static final class Namespace {
static final String TEMPLATE = "template";
static final String IDENTITY = "identity";
static final String CONFIGURATION_SET = "configuration-set";
static final String CUSTOM_VERIFICATION_EMAIL_TEMPLATE = "custom-verification-email-template";
static final String EXPORT_JOB = "export-job";
}
@@ -44,27 +79,41 @@ enum SesListPaging {
private final int defaultPageSize;
private final int maxPageSize;
private final Function<Integer, AwsException> outOfRange;
private final int servedWhenOutOfRange;
private final Function<String, AwsException> invalidToken;
private final boolean emptyTokenInvalid;
SesListPaging(String namespace, int defaultPageSize, int maxPageSize,
Function<Integer, AwsException> outOfRange, Function<String, AwsException> invalidToken,
boolean emptyTokenInvalid) {
this(namespace, defaultPageSize, maxPageSize, outOfRange, 0, invalidToken, emptyTokenInvalid);
}
SesListPaging(String namespace, int defaultPageSize, int maxPageSize, int servedWhenOutOfRange,
Function<String, AwsException> invalidToken, boolean emptyTokenInvalid) {
this(namespace, defaultPageSize, maxPageSize, null, servedWhenOutOfRange, invalidToken,
emptyTokenInvalid);
}
SesListPaging(String namespace, int defaultPageSize, int maxPageSize,
Function<Integer, AwsException> outOfRange, int servedWhenOutOfRange,
Function<String, AwsException> invalidToken, boolean emptyTokenInvalid) {
this.namespace = namespace;
this.defaultPageSize = defaultPageSize;
this.maxPageSize = maxPageSize;
this.outOfRange = outOfRange;
this.servedWhenOutOfRange = servedWhenOutOfRange;
this.invalidToken = invalidToken;
this.emptyTokenInvalid = emptyTokenInvalid;
}
<T> PaginatedResult<T> page(List<T> all, Function<T, String> cursorOf, Integer pageSize,
<T> PaginatedResult<T> page(String region, List<T> all, Function<T, String> cursorOf, Integer pageSize,
String nextToken) {
int limit = pageSize(pageSize);
if (nextToken != null && nextToken.isEmpty() && emptyTokenInvalid) {
throw invalidToken.apply(nextToken);
}
return Pagination.paginate(all, cursorOf, limit, nextToken, namespace, invalidToken);
return Pagination.paginate(all, cursorOf, limit, nextToken, namespace + "@" + region, invalidToken);
}
int pageSize(Integer requested) {
@@ -73,7 +122,7 @@ enum SesListPaging {
}
if (requested < 1 || requested > maxPageSize) {
if (outOfRange == null) {
return maxPageSize;
return servedWhenOutOfRange;
}
throw outOfRange.apply(requested);
}
@@ -86,10 +135,6 @@ enum SesListPaging {
return descending + "#" + id;
}
static String templateCursor(EmailTemplate template) {
return newestFirst(template.getCreatedTimestamp(), template.getTemplateName());
}
/** A REST JSON query-string page size; a value that is not an int is a serialization error. */
static Integer parseQueryPageSize(String raw) {
if (raw == null || raw.isEmpty()) {
@@ -127,7 +127,7 @@ public class SesQueryHandler {
case "GetCustomVerificationEmailTemplate" ->
handleGetCustomVerificationEmailTemplate(params, region);
case "ListCustomVerificationEmailTemplates" ->
handleListCustomVerificationEmailTemplates(region);
handleListCustomVerificationEmailTemplates(params, region);
case "UpdateCustomVerificationEmailTemplate" ->
handleUpdateCustomVerificationEmailTemplate(params, region);
case "DeleteCustomVerificationEmailTemplate" ->
@@ -136,7 +136,7 @@ public class SesQueryHandler {
handleSendCustomVerificationEmail(params, region);
case "CreateConfigurationSet" -> handleCreateConfigurationSet(params, region);
case "DescribeConfigurationSet" -> handleDescribeConfigurationSet(params, region);
case "ListConfigurationSets" -> handleListConfigurationSets(region);
case "ListConfigurationSets" -> handleListConfigurationSets(params, region);
case "DeleteConfigurationSet" -> handleDeleteConfigurationSet(params, region);
case "CreateConfigurationSetEventDestination" ->
handleCreateConfigurationSetEventDestination(params, region);
@@ -207,13 +207,17 @@ public class SesQueryHandler {
private Response handleListIdentities(MultivaluedMap<String, String> params, String region) {
String identityType = getParam(params, "IdentityType");
List<Identity> identities = identityService.listIdentities(identityType, region);
PaginatedResult<Identity> page = identityService.listIdentities(identityType, region,
SesListPaging.V1_LIST_IDENTITIES,
SesListPaging.parseQueryProtocolPageSize(getParam(params, "MaxItems")),
getParam(params, "NextToken"));
var xml = new XmlBuilder().start("Identities");
for (Identity id : identities) {
XmlBuilder xml = new XmlBuilder().start("Identities");
for (Identity id : page.items()) {
xml.elem("member", id.getIdentity());
}
xml.end("Identities");
xml.elem("NextToken", page.nextToken());
return Response.ok(AwsQueryResponse.envelope("ListIdentities", AwsNamespaces.SES, xml.build())).build();
}
@@ -587,8 +591,8 @@ public class SesQueryHandler {
}
private Response handleListTemplates(MultivaluedMap<String, String> params, String region) {
PaginatedResult<EmailTemplate> page = SesListPaging.V1_LIST_TEMPLATES.page(
templateService.listTemplates(region), SesListPaging::templateCursor,
PaginatedResult<EmailTemplate> page = templateService.listTemplates(region,
SesListPaging.V1_LIST_TEMPLATES,
SesListPaging.parseQueryProtocolPageSize(getParam(params, "MaxItems")),
getParam(params, "NextToken"));
XmlBuilder xml = new XmlBuilder().start("TemplatesMetadata");
@@ -691,11 +695,14 @@ public class SesQueryHandler {
"GetCustomVerificationEmailTemplate", AwsNamespaces.SES, xml)).build();
}
private Response handleListCustomVerificationEmailTemplates(String region) {
private Response handleListCustomVerificationEmailTemplates(MultivaluedMap<String, String> params,
String region) {
PaginatedResult<CustomVerificationEmailTemplate> page = cvetService.listCustomVerificationEmailTemplates(
region, SesListPaging.V1_LIST_CUSTOM_VERIFICATION_EMAIL_TEMPLATES,
SesListPaging.parseQueryProtocolPageSize(getParam(params, "MaxResults")),
getParam(params, "NextToken"));
XmlBuilder xml = new XmlBuilder().start("CustomVerificationEmailTemplates");
List<CustomVerificationEmailTemplate> templates =
cvetService.listCustomVerificationEmailTemplates(region);
for (CustomVerificationEmailTemplate t : templates) {
for (CustomVerificationEmailTemplate t : page.items()) {
xml.start("member")
.elem("TemplateName", t.getTemplateName())
.elem("FromEmailAddress", t.getFromEmailAddress())
@@ -705,6 +712,7 @@ public class SesQueryHandler {
.end("member");
}
xml.end("CustomVerificationEmailTemplates");
xml.elem("NextToken", page.nextToken());
return Response.ok(AwsQueryResponse.envelope(
"ListCustomVerificationEmailTemplates", AwsNamespaces.SES, xml.build())).build();
}
@@ -928,13 +936,17 @@ public class SesQueryHandler {
}
}
private Response handleListConfigurationSets(String region) {
List<ConfigurationSet> all = configSetService.list(region);
private Response handleListConfigurationSets(MultivaluedMap<String, String> params, String region) {
PaginatedResult<ConfigurationSet> page = configSetService.list(region,
SesListPaging.V1_LIST_CONFIGURATION_SETS,
SesListPaging.parseQueryProtocolPageSize(getParam(params, "MaxItems")),
getParam(params, "NextToken"));
XmlBuilder xml = new XmlBuilder().start("ConfigurationSets");
for (ConfigurationSet cs : all) {
for (ConfigurationSet cs : page.items()) {
xml.start("member").elem("Name", cs.getName()).end("member");
}
xml.end("ConfigurationSets");
xml.elem("NextToken", page.nextToken());
return Response.ok(AwsQueryResponse.envelope("ListConfigurationSets", AwsNamespaces.SES, xml.build())).build();
}
@@ -91,9 +91,8 @@ public class SesTemplateController {
@QueryParam("PageSize") String pageSize,
@QueryParam("NextToken") String nextToken) {
String region = regionResolver.resolveRegion(headers);
PaginatedResult<EmailTemplate> page = SesListPaging.V2_LIST_EMAIL_TEMPLATES.page(
templateService.listTemplates(region), SesListPaging::templateCursor,
SesListPaging.parseQueryPageSize(pageSize), nextToken);
PaginatedResult<EmailTemplate> page = templateService.listTemplates(region,
SesListPaging.V2_LIST_EMAIL_TEMPLATES, SesListPaging.parseQueryPageSize(pageSize), nextToken);
ObjectNode result = objectMapper.createObjectNode();
ArrayNode items = result.putArray("TemplatesMetadata");
for (EmailTemplate t : page.items()) {
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.ses.model.EmailContent;
@@ -20,6 +21,7 @@ import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.HexFormat;
import java.util.List;
@@ -123,9 +125,21 @@ public class SesTemplateService {
LOG.infov("Deleted SES template: {0} in region {1}", templateName, region);
}
public PaginatedResult<EmailTemplate> listTemplates(String region, SesListPaging paging, Integer pageSize,
String nextToken) {
return paging.page(region, listTemplates(region), SesTemplateService::cursor, pageSize, nextToken);
}
/** Newest first, as SES lists them; the paged lists resume on the same order. */
public List<EmailTemplate> listTemplates(String region) {
String prefix = "template::" + region + "::";
return templateStore.scan(k -> k.startsWith(prefix));
return templateStore.scan(k -> k.startsWith(prefix)).stream()
.sorted(Comparator.comparing(SesTemplateService::cursor))
.toList();
}
private static String cursor(EmailTemplate template) {
return SesListPaging.newestFirst(template.getCreatedTimestamp(), template.getTemplateName());
}
/**