feat(ses): paginate the contact, dedicated IP pool, suppressed destination and receipt rule set lists (#4877)

* feat(ses): paginate the contact, dedicated IP pool, suppressed destination and receipt rule set lists

Page ListContactLists, ListContacts, ListDedicatedIpPools, GetDedicatedIps,
ListSuppressedDestinations and v1 ListReceiptRuleSets with the probed bounds
and messages. ListContacts serves 50 by default and receipt rule sets 100, the
figure the model documents; the lists whose default could not be measured
serve up to 1000. Where SES's own order is not stable Floci keeps the order
its unpaged lists already had. A suppressed-destination token is bound to the
reason filter and tenant it was taken with, as on SES.

* test(ses): isolate the contact paging compat test and cover v1 receipt rule set paging on the wire

The contact paging compatibility test cleared every contact list in the
account before and after it ran; it now runs as its own account and removes
only the list it created. A new integration test pages 101 receipt rule sets
through the Query API, where the earlier coverage only reached the service.

* docs(ses): note that SES lists receipt rule sets by name

Floci pages ListReceiptRuleSets in the creation order its unpaged list already
had; the paging paragraph now says SES lists them by name.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-10-02 17:10:06 -05:00
1 parent 3e2d310eae
commit bb3dd2de92
22 files changed
+989 -52

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.Contact;
import io.github.hectorvent.floci.services.ses.model.ContactList;
@@ -21,20 +22,24 @@ 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 jakarta.ws.rs.core.UriInfo;
import org.jboss.logging.Logger;
import java.util.ArrayList;
import java.util.List;
import static io.github.hectorvent.floci.services.ses.SesV2Json.coerceBoolean;
import static io.github.hectorvent.floci.services.ses.SesV2Json.intMemberOrAbsent;
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;
import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;
import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAbsent;
import static io.github.hectorvent.floci.services.ses.SesV2Json.unexpectedStartError;
/**
@@ -90,15 +95,21 @@ public class SesContactController {
@GET
@Path("/contact-lists")
public Response listContactLists(@Context HttpHeaders headers) {
public Response listContactLists(@Context HttpHeaders headers,
@QueryParam("PageSize") String pageSize,
@Context UriInfo uriInfo) {
String region = regionResolver.resolveRegion(headers);
String nextToken = SesListPaging.queryToken(uriInfo);
PaginatedResult<ContactList> page = contactService.listContactLists(region,
SesListPaging.V2_LIST_CONTACT_LISTS, SesListPaging.parseQueryPageSize(pageSize), nextToken);
ObjectNode result = objectMapper.createObjectNode();
ArrayNode lists = result.putArray("ContactLists");
for (ContactList cl : contactService.listContactLists(region)) {
for (ContactList cl : page.items()) {
ObjectNode item = lists.addObject();
item.put("ContactListName", cl.getContactListName());
putTimestamp(item, "LastUpdatedTimestamp", cl.getLastUpdatedTimestamp());
}
result.put("NextToken", page.nextToken());
return Response.ok(result).build();
}
@@ -226,21 +237,25 @@ public class SesContactController {
@Path("/contact-lists/{contactListName}/contacts/list")
public Response listContacts(@Context HttpHeaders headers,
@PathParam("contactListName") String contactListName, String body) {
// AWS uses POST .../contacts/list with Filter/PageSize/NextToken in the body; Floci returns
// all contacts (filtering/pagination not yet implemented) but still rejects a malformed or
// non-object body like the other v2 endpoints.
// AWS uses POST .../contacts/list with Filter/PageSize/NextToken in the body; Floci pages
// the contacts (filtering not yet implemented) and rejects a malformed or non-object body
// like the other v2 endpoints.
String region = regionResolver.resolveRegion(headers);
try {
if (body != null && !body.isBlank()) {
requireJsonObject(objectMapper.readTree(body));
}
SesContactService.ContactsWithList listed =
contactService.listContacts(contactListName, region);
JsonNode request = (body == null || body.isBlank())
? objectMapper.createObjectNode()
: objectMapper.readTree(body);
requireJsonObject(request);
Integer pageSize = intMemberOrAbsent(request, "PageSize");
String nextToken = stringMemberOrAbsent(request, "NextToken");
SesContactService.ContactPage listed = contactService.listContacts(contactListName, region,
SesListPaging.V2_LIST_CONTACTS, pageSize, nextToken);
ObjectNode result = objectMapper.createObjectNode();
ArrayNode arr = result.putArray("Contacts");
for (Contact c : listed.contacts()) {
for (Contact c : listed.contacts().items()) {
arr.add(contactJson(c, listed.list(), false));
}
result.put("NextToken", listed.contacts().nextToken());
return Response.ok(result).build();
} catch (AwsException e) {
throw remapV1Exception(e);
@@ -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.Contact;
@@ -151,6 +152,12 @@ public class SesContactService {
"No ContactList present with name: " + name, 404);
}
public PaginatedResult<ContactList> listContactLists(String region, SesListPaging paging, Integer pageSize,
String nextToken) {
return paging.page(region, listContactLists(region), ContactList::getContactListName, pageSize,
nextToken);
}
public List<ContactList> listContactLists(String region) {
String prefix = "contactList::" + region + "::";
return contactListStore.scan(k -> k.startsWith(prefix)).stream()
@@ -351,14 +358,33 @@ public class SesContactService {
return new ContactWithList(contact, list);
}
public record ContactPage(PaginatedResult<Contact> contacts, ContactList list) {
}
/** SES reads the page size and the token before it looks the list up. */
public ContactPage listContacts(String listName, String region, SesListPaging paging, Integer pageSize,
String nextToken) {
ContactList list = contactListStore.get(contactListKey(region, listName)).orElse(null);
List<Contact> contacts = list == null ? List.of() : contactsOf(listName, region);
PaginatedResult<Contact> page = paging.page(region, contacts, Contact::getEmailAddress, pageSize,
nextToken);
if (list == null) {
throw contactListNotFound(listName);
}
return new ContactPage(page, list);
}
public ContactsWithList listContacts(String listName, String region) {
ContactList list = getContactList(listName, region);
return new ContactsWithList(contactsOf(listName, region), list);
}
private List<Contact> contactsOf(String listName, String region) {
String prefix = "contact::" + region + "::" + listName + "::";
List<Contact> contacts = contactStore.scan(k -> k.startsWith(prefix)).stream()
return contactStore.scan(k -> k.startsWith(prefix)).stream()
.sorted(Comparator.comparing(Contact::getEmailAddress,
Comparator.nullsFirst(Comparator.naturalOrder())))
.toList();
return new ContactsWithList(contacts, list);
}
public Contact updateContact(String listName, String emailAddress, List<TopicPreference> topicPreferences,
@@ -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.DedicatedIpPool;
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;
@@ -92,11 +94,16 @@ public class SesDedicatedIpController {
@GET
@Path("/dedicated-ip-pools")
public Response listDedicatedIpPools(@Context HttpHeaders headers) {
public Response listDedicatedIpPools(@Context HttpHeaders headers,
@QueryParam("PageSize") String pageSize,
@QueryParam("NextToken") String nextToken) {
String region = regionResolver.resolveRegion(headers);
PaginatedResult<String> page = dedicatedIpService.listDedicatedIpPools(region,
SesListPaging.V2_LIST_DEDICATED_IP_POOLS, SesListPaging.parseQueryPageSize(pageSize), nextToken);
ObjectNode result = objectMapper.createObjectNode();
ArrayNode pools = result.putArray("DedicatedIpPools");
dedicatedIpService.listDedicatedIpPools(region).forEach(pools::add);
page.items().forEach(pools::add);
result.put("NextToken", page.nextToken());
return Response.ok(result).build();
}
@@ -144,12 +151,16 @@ public class SesDedicatedIpController {
@GET
@Path("/dedicated-ips")
public Response getDedicatedIps(@Context HttpHeaders headers) {
regionResolver.resolveRegion(headers);
public Response getDedicatedIps(@Context HttpHeaders headers,
@QueryParam("PageSize") String pageSize,
@QueryParam("NextToken") String nextToken) {
String region = regionResolver.resolveRegion(headers);
// Floci does not model leased dedicated IPs, so the account has none.
PaginatedResult<String> page = dedicatedIpService.listDedicatedIps(region,
SesListPaging.V2_GET_DEDICATED_IPS, SesListPaging.parseQueryPageSize(pageSize), nextToken);
ObjectNode result = objectMapper.createObjectNode();
result.putArray("DedicatedIps");
result.putNull("NextToken");
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.DedicatedIpPool;
@@ -15,6 +16,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
/**
* Dedicated IP pools (the {@code dedicatedIpPoolStore}), extracted from {@link SesService} as part of
@@ -79,6 +81,12 @@ public class SesDedicatedIpService {
return dedicatedIpPoolStore.get(dedicatedIpPoolKey(region, poolName)).isPresent();
}
public PaginatedResult<String> listDedicatedIpPools(String region, SesListPaging paging, Integer pageSize,
String nextToken) {
return paging.page(region, listDedicatedIpPools(region), Function.identity(), pageSize, nextToken);
}
/** By name, the order Floci settles on where SES's own changes with the page size. */
public List<String> listDedicatedIpPools(String region) {
String prefix = "dedicatedIpPool::" + region + "::";
return dedicatedIpPoolStore.scan(k -> k.startsWith(prefix)).stream()
@@ -150,6 +158,12 @@ public class SesDedicatedIpService {
// IP-targeted operation reports the IP as not found, matching real AWS for an
// account with no leased IPs (verified 2026-06-21).
/** Always empty (see the section note above), but the page size and token are still checked. */
public PaginatedResult<String> listDedicatedIps(String region, SesListPaging paging, Integer pageSize,
String nextToken) {
return paging.page(region, List.<String>of(), Function.identity(), pageSize, nextToken);
}
private AwsException dedicatedIpNotFound(String ip) {
return new AwsException("NotFoundException",
"Could not find dedicated IP <" + ip + "> under this account.", 404);
@@ -3,6 +3,7 @@ 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 jakarta.ws.rs.core.UriInfo;
import java.time.Instant;
import java.util.List;
@@ -84,7 +85,44 @@ public enum SesListPaging {
* ListImportJobs refuses sandbox accounts, so nothing about it could be probed; it is modelled
* on the tenant lists, which share its Smithy-generated validation.
*/
V2_LIST_IMPORT_JOBS(Namespace.IMPORT_JOB);
V2_LIST_IMPORT_JOBS(Namespace.IMPORT_JOB),
/** SES holds one contact list per region, so no default could be measured; it is taken to be the bound. */
V2_LIST_CONTACT_LISTS(Namespace.CONTACT_LIST, 1000, 1000,
size -> badRequest("The page size must be between 1 and 1000"),
token -> badRequest("Provided NextToken is invalid"),
true),
V2_LIST_CONTACTS(Namespace.CONTACT, 50, 1000,
size -> badRequest("The page size must be between 1 and 1000"),
token -> badRequest("Provided NextToken is invalid"),
true),
/** 12 pools came back whole without a PageSize, so the default is taken to be the bound. */
V2_LIST_DEDICATED_IP_POOLS(Namespace.DEDICATED_IP_POOL, 1000, 1000,
size -> badRequest("The page size must be in [1, 1000] range."),
token -> badRequest("Invalid next token."),
false),
/** Unmeasurable without leased IPs; modelled on the pool list, whose messages it shares. */
V2_GET_DEDICATED_IPS(Namespace.DEDICATED_IP, 1000, 1000,
size -> badRequest("The page size must be in [1, 1000] range."),
token -> badRequest("Invalid next token."),
false),
/** 24 destinations came back whole without a PageSize, so the default is taken to be the bound. */
V2_LIST_SUPPRESSED_DESTINATIONS(Namespace.SUPPRESSED_DESTINATION, 1000, 1000,
size -> badRequest("Page size " + size + " is invalid, expected a number between 1 and 1000"),
token -> new AwsException("InvalidNextTokenException", "Token is invalid.", 400),
true),
/**
* The request has no size member; the model documents "up to 100 receipt rule sets at a time".
* SES allows 40 rule sets per region, so a second page could not be observed.
*/
V1_LIST_RECEIPT_RULE_SETS(Namespace.RECEIPT_RULE_SET, 100, 100, 100,
token -> invalidParameterValue("Invalid page token: " + token),
false);
private static final class Namespace {
static final String TEMPLATE = "template";
@@ -96,6 +134,12 @@ public enum SesListPaging {
static final String TENANT_RESOURCE = "tenant-resource";
static final String RESOURCE_TENANT = "resource-tenant";
static final String IMPORT_JOB = "import-job";
static final String CONTACT_LIST = "contact-list";
static final String CONTACT = "contact";
static final String DEDICATED_IP_POOL = "dedicated-ip-pool";
static final String DEDICATED_IP = "dedicated-ip";
static final String SUPPRESSED_DESTINATION = "suppressed-destination";
static final String RECEIPT_RULE_SET = "receipt-rule-set";
}
/** What the tenant lists share, and ListImportJobs borrows: the bound and Smithy's messages. */
@@ -228,6 +272,14 @@ public enum SesListPaging {
return time + "#" + id;
}
/**
* The NextToken of a REST JSON query string, for a list that refuses an empty token: a
* {@code @QueryParam} binds an empty value as null, which would read as an absent token.
*/
static String queryToken(UriInfo uriInfo) {
return uriInfo.getQueryParameters().getFirst("NextToken");
}
/** 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()) {
@@ -158,7 +158,7 @@ public class SesQueryHandler {
handlePutConfigurationSetDeliveryOptions(params, region);
case "CreateReceiptRuleSet" -> handleCreateReceiptRuleSet(params, region);
case "DescribeReceiptRuleSet" -> handleDescribeReceiptRuleSet(params, region);
case "ListReceiptRuleSets" -> handleListReceiptRuleSets(region);
case "ListReceiptRuleSets" -> handleListReceiptRuleSets(params, region);
case "DeleteReceiptRuleSet" -> handleDeleteReceiptRuleSet(params, region);
case "SetActiveReceiptRuleSet" -> handleSetActiveReceiptRuleSet(params, region);
case "DescribeActiveReceiptRuleSet" -> handleDescribeActiveReceiptRuleSet(region);
@@ -1087,14 +1087,17 @@ public class SesQueryHandler {
"DescribeReceiptRuleSet", AwsNamespaces.SES, xml.build())).build();
}
private Response handleListReceiptRuleSets(String region) {
private Response handleListReceiptRuleSets(MultivaluedMap<String, String> params, String region) {
PaginatedResult<ReceiptRuleSet> page = receiptRuleService.listReceiptRuleSets(region,
SesListPaging.V1_LIST_RECEIPT_RULE_SETS, getParam(params, "NextToken"));
XmlBuilder xml = new XmlBuilder().start("RuleSets");
for (ReceiptRuleSet rs : receiptRuleService.listReceiptRuleSets(region)) {
for (ReceiptRuleSet rs : page.items()) {
xml.start("member");
writeReceiptRuleSetMetadataFields(xml, rs);
xml.end("member");
}
xml.end("RuleSets");
xml.elem("NextToken", page.nextToken());
return Response.ok(AwsQueryResponse.envelope(
"ListReceiptRuleSets", AwsNamespaces.SES, xml.build())).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.lambda.LambdaService;
@@ -128,12 +129,19 @@ public class SesReceiptRuleService {
.orElseThrow(() -> ruleSetDoesNotExist(name));
}
public PaginatedResult<ReceiptRuleSet> listReceiptRuleSets(String region, SesListPaging paging,
String nextToken) {
return paging.page(region, listReceiptRuleSets(region), SesReceiptRuleService::cursor, null, nextToken);
}
private static String cursor(ReceiptRuleSet ruleSet) {
return SesListPaging.oldestFirst(ruleSet.getCreatedTimestamp(), ruleSet.getName());
}
public List<ReceiptRuleSet> listReceiptRuleSets(String region) {
String prefix = "receiptRuleSet::" + region + "::";
List<ReceiptRuleSet> all = new ArrayList<>(receiptRuleSetStore.scan(k -> k.startsWith(prefix)));
all.sort(Comparator.comparing(ReceiptRuleSet::getCreatedTimestamp,
Comparator.nullsLast(Comparator.naturalOrder()))
.thenComparing(ReceiptRuleSet::getName, Comparator.nullsLast(Comparator.naturalOrder())));
all.sort(Comparator.comparing(SesReceiptRuleService::cursor));
return all;
}
@@ -1282,6 +1282,19 @@ public class SesService {
});
}
public PaginatedResult<SuppressedDestination> listSuppressedDestinations(
String region, List<String> reasonFilters, String tenantName, SesListPaging paging, Integer pageSize,
String nextToken) {
if (tenantName == null) {
return suppressionService.listSuppressedDestinations(region, reasonFilters, paging, pageSize,
nextToken);
}
SesSuppressionService.validateReasonFilters(reasonFilters);
return tenantService.runWithTenant(tenantName, region, tenant ->
suppressionService.listTenantSuppressedDestinations(region, tenant.tenantId(),
reasonFilters, paging, pageSize, nextToken));
}
public List<SuppressedDestination> listSuppressedDestinations(String region,
List<String> reasonFilters,
String tenantName) {
@@ -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.SuppressedDestination;
import jakarta.inject.Inject;
@@ -21,6 +22,7 @@ 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 jakarta.ws.rs.core.UriInfo;
import org.jboss.logging.Logger;
import java.util.List;
@@ -121,23 +123,29 @@ public class SesSuppressionController {
@Path("/suppression/addresses")
public Response listSuppressedDestinations(@Context HttpHeaders headers,
@QueryParam("Reason") List<String> reasons,
@QueryParam("TenantName") String tenantName) {
@QueryParam("TenantName") String tenantName,
@QueryParam("PageSize") String pageSize,
@Context UriInfo uriInfo) {
String region = regionResolver.resolveRegion(headers);
List<SuppressedDestination> entries;
String nextToken = SesListPaging.queryToken(uriInfo);
PaginatedResult<SuppressedDestination> page;
try {
entries = sesService.listSuppressedDestinations(region, reasons, tenantName);
page = sesService.listSuppressedDestinations(region, reasons, tenantName,
SesListPaging.V2_LIST_SUPPRESSED_DESTINATIONS, SesListPaging.parseQueryPageSize(pageSize),
nextToken);
} catch (AwsException e) {
throw remapV1Exception(e);
}
ObjectNode result = objectMapper.createObjectNode();
ArrayNode summaries = result.putArray("SuppressedDestinationSummaries");
for (SuppressedDestination s : entries) {
for (SuppressedDestination s : page.items()) {
ObjectNode item = objectMapper.createObjectNode();
item.put("EmailAddress", s.getEmailAddress());
item.put("Reason", s.getReason());
putTimestamp(item, "LastUpdateTime", s.getLastUpdateTime());
summaries.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.ses.model.AccountSuppressionAttributes;
@@ -19,6 +20,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
/**
* Suppression: the account-level suppression attributes and the per-address suppression list,
@@ -172,20 +174,39 @@ public class SesSuppressionService {
return Optional.empty();
}
/**
* SES binds the token to the filter it was taken with, so a token replayed with other reasons is
* refused; its own order is not stable between calls, so Floci keeps oldest first.
*/
public PaginatedResult<SuppressedDestination> listSuppressedDestinations(
String region, List<String> reasonFilters, SesListPaging paging, Integer pageSize, String nextToken) {
Set<String> filters = validateReasonFilters(reasonFilters);
String prefix = "suppression::" + region + "::";
return paging.page(region, tokenScope("", filters),
oldestFirst(suppressionStore.scan(k -> k.startsWith(prefix)), filters),
SesSuppressionService::cursor, pageSize, nextToken);
}
private static String tokenScope(String tenantId, Set<String> filters) {
return tenantId + "/" + String.join(",", new TreeSet<>(filters));
}
private static String cursor(SuppressedDestination destination) {
return SesListPaging.oldestFirst(destination.getLastUpdateTime(), destination.getEmailAddress());
}
private static List<SuppressedDestination> oldestFirst(List<SuppressedDestination> entries,
Set<String> filters) {
return entries.stream()
.filter(s -> filters.isEmpty() || filters.contains(s.getReason()))
.sorted(Comparator.comparing(SesSuppressionService::cursor))
.toList();
}
public List<SuppressedDestination> listSuppressedDestinations(String region, List<String> reasonFilters) {
Set<String> filters = validateReasonFilters(reasonFilters);
String prefix = "suppression::" + region + "::";
List<SuppressedDestination> all = new ArrayList<>(suppressionStore.scan(k -> k.startsWith(prefix)));
all.sort(Comparator.comparing(SuppressedDestination::getLastUpdateTime,
Comparator.nullsLast(Comparator.naturalOrder()))
.thenComparing(SuppressedDestination::getEmailAddress,
Comparator.nullsLast(Comparator.naturalOrder())));
if (filters.isEmpty()) {
return all;
}
return all.stream()
.filter(s -> filters.contains(s.getReason()))
.toList();
return oldestFirst(suppressionStore.scan(k -> k.startsWith(prefix)), filters);
}
private static String suppressionKey(String region, String emailAddress) {
@@ -230,22 +251,21 @@ public class SesSuppressionService {
LOG.infov("Removed tenant suppression entry for {0} in region {1}", normalized, region);
}
public PaginatedResult<SuppressedDestination> listTenantSuppressedDestinations(
String region, String tenantId, List<String> reasonFilters, SesListPaging paging, Integer pageSize,
String nextToken) {
Set<String> filters = validateReasonFilters(reasonFilters);
String prefix = tenantSuppressionKeyPrefix(region, tenantId);
return paging.page(region, tokenScope(tenantId, filters),
oldestFirst(tenantSuppressionStore.scan(k -> k.startsWith(prefix)), filters),
SesSuppressionService::cursor, pageSize, nextToken);
}
public List<SuppressedDestination> listTenantSuppressedDestinations(String region, String tenantId,
List<String> reasonFilters) {
Set<String> filters = validateReasonFilters(reasonFilters);
String prefix = tenantSuppressionKeyPrefix(region, tenantId);
List<SuppressedDestination> all =
new ArrayList<>(tenantSuppressionStore.scan(k -> k.startsWith(prefix)));
all.sort(Comparator.comparing(SuppressedDestination::getLastUpdateTime,
Comparator.nullsLast(Comparator.naturalOrder()))
.thenComparing(SuppressedDestination::getEmailAddress,
Comparator.nullsLast(Comparator.naturalOrder())));
if (filters.isEmpty()) {
return all;
}
return all.stream()
.filter(s -> filters.contains(s.getReason()))
.toList();
return oldestFirst(tenantSuppressionStore.scan(k -> k.startsWith(prefix)), filters);
}
/** DeleteTenant's cascade for this domain, run from inside the tenant lock. */