mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
feat(ses): paginate the tenant and import job lists (#4819)
* feat(ses): paginate the tenant and import job lists Page ListTenants, ListTenantResources, ListResourceTenants and ListImportJobs on the shared SES paging, each with its own token namespace, and delete SesTenantService.validateListPaging. The tenant lists answer the probed SES rules: PageSize 1 to 100 with the Smithy validation messages, an empty NextToken refused with its Smithy message before the tenant or resource is looked up, an unreadable token answered "Invalid Next Token", tenants listed by name, a tenant's resources by ARN and a resource's tenants in association order. ListImportJobs could not be probed and is modelled on the tenant lists, keeping Floci's oldest-first order. Without a PageSize all four lists serve up to 100, a Floci assumption where nothing could be measured. * fix(ses): follow the probed order, aggregation and token binding on the tenant lists A second probe of real SES showed three differences on ListTenantResources and ListResourceTenants: the tenant or resource is looked up, and the filter checked, before the page size and token; a page size outside the bound and an empty NextToken are reported together in one validation message; and a token is refused once the tenant, resource or filter changes. ListImportJobs, which cannot be probed, follows the same rules. The service docs keep the per-list paging detail and gain a paragraph for these four lists.
This commit is contained in:
1 parent
bcf1045536
commit
a22e65f993
14 files changed
+988
-91
No files matched your search
@@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.ObjectReader;
|
||||
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.ImportJob;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -23,8 +24,6 @@ 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.intMemberOrAbsent;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.readRequiredStringField;
|
||||
@@ -139,14 +138,14 @@ public class SesImportJobController {
|
||||
String destinationType = stringMemberOrAbsent(request, "ImportDestinationType");
|
||||
Integer pageSize = intMemberOrAbsent(request, "PageSize");
|
||||
String nextToken = stringMemberOrAbsent(request, "NextToken");
|
||||
List<ImportJob> jobs = importJobService.listImportJobs(region, destinationType, pageSize, nextToken);
|
||||
PaginatedResult<ImportJob> page = importJobService.listImportJobs(region, destinationType,
|
||||
SesListPaging.V2_LIST_IMPORT_JOBS, pageSize, nextToken);
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
ArrayNode items = result.putArray("ImportJobs");
|
||||
for (ImportJob job : jobs) {
|
||||
for (ImportJob job : page.items()) {
|
||||
writeSummary(items.addObject(), job);
|
||||
}
|
||||
// AWS renders NextToken as an explicit null on the last (here: only) page.
|
||||
result.putNull("NextToken");
|
||||
result.put("NextToken", page.nextToken());
|
||||
return Response.ok(result).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.ses;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
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.common.RequestScopes;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
@@ -366,20 +367,29 @@ public class SesImportJobService implements Resettable {
|
||||
"Import job " + jobId + " does not exist.", 404));
|
||||
}
|
||||
|
||||
public List<ImportJob> listImportJobs(String region, String destinationType, Integer pageSize,
|
||||
String nextToken) {
|
||||
/** The filter is checked before the page size and token, and a token is bound to it, as on the tenant lists. */
|
||||
public PaginatedResult<ImportJob> listImportJobs(String region, String destinationType,
|
||||
SesListPaging paging, Integer pageSize, String nextToken) {
|
||||
return paging.page(region, "/" + destinationType, listImportJobs(region, destinationType),
|
||||
SesImportJobService::cursor, pageSize, nextToken);
|
||||
}
|
||||
|
||||
/** Oldest first, Floci's own order since SES's could not be observed; the paged list resumes on it. */
|
||||
public List<ImportJob> listImportJobs(String region, String destinationType) {
|
||||
if (destinationType != null && !DESTINATION_TYPES.contains(destinationType)) {
|
||||
throw validationError("importDestinationType",
|
||||
"Member must satisfy enum value set: [SUPPRESSION_LIST, CONTACT_LIST]");
|
||||
}
|
||||
SesTenantService.validateListPaging(pageSize, nextToken);
|
||||
return importJobStore.scan(k -> k.startsWith(keyPrefix(region))).stream()
|
||||
.filter(j -> destinationType == null || destinationType.equals(j.getDestinationType()))
|
||||
.sorted(Comparator.comparing(ImportJob::getCreatedTimestamp)
|
||||
.thenComparing(ImportJob::getJobId))
|
||||
.sorted(Comparator.comparing(SesImportJobService::cursor))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private static String cursor(ImportJob job) {
|
||||
return SesListPaging.oldestFirst(job.getCreatedTimestamp(), job.getJobId());
|
||||
}
|
||||
|
||||
// ──────────────────────────── Lifecycle ────────────────────────────
|
||||
|
||||
// Recovery happens in the constructor, and a normal-scoped bean is only built on first use, so
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.core.common.Pagination;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
@@ -65,7 +66,25 @@ public enum SesListPaging {
|
||||
V2_LIST_EXPORT_JOBS(Namespace.EXPORT_JOB, 100, 100,
|
||||
size -> badRequest("PageSize must be between 1 and 100"),
|
||||
token -> badRequest("Failed to deserialize token. "),
|
||||
true);
|
||||
true),
|
||||
|
||||
/**
|
||||
* The three tenant lists answer Smithy's own validation messages, reporting a bad page size and
|
||||
* an empty token together, and bind a token to the request it came from (probed 2026-10-02).
|
||||
* Their default page size could not be measured (it needs more than 100 tenants) and is taken
|
||||
* to be the bound.
|
||||
*/
|
||||
V2_LIST_TENANTS(Namespace.TENANT),
|
||||
|
||||
V2_LIST_TENANT_RESOURCES(Namespace.TENANT_RESOURCE),
|
||||
|
||||
V2_LIST_RESOURCE_TENANTS(Namespace.RESOURCE_TENANT),
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
private static final class Namespace {
|
||||
static final String TEMPLATE = "template";
|
||||
@@ -73,6 +92,42 @@ public enum SesListPaging {
|
||||
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";
|
||||
static final String TENANT = "tenant";
|
||||
static final String TENANT_RESOURCE = "tenant-resource";
|
||||
static final String RESOURCE_TENANT = "resource-tenant";
|
||||
static final String IMPORT_JOB = "import-job";
|
||||
}
|
||||
|
||||
/** What the tenant lists share, and ListImportJobs borrows: the bound and Smithy's messages. */
|
||||
private static final class TenantLists {
|
||||
static final int BOUND = 100;
|
||||
static final String EMPTY_TOKEN = "Value '' at 'nextToken' failed to satisfy constraint: "
|
||||
+ "Member must have length greater than or equal to 1";
|
||||
|
||||
static String pageSizeViolation(int pageSize) {
|
||||
String constraint = pageSize < 1
|
||||
? "greater than or equal to 1"
|
||||
: "less than or equal to " + BOUND;
|
||||
return "Value '" + pageSize + "' at 'pageSize' failed to satisfy constraint: "
|
||||
+ "Member must have value " + constraint;
|
||||
}
|
||||
|
||||
static AwsException pageSizeError(int pageSize) {
|
||||
return badRequest("1 validation error detected: " + pageSizeViolation(pageSize));
|
||||
}
|
||||
|
||||
static AwsException tokenError(String token) {
|
||||
if (token.isEmpty()) {
|
||||
return badRequest("1 validation error detected: " + EMPTY_TOKEN);
|
||||
}
|
||||
return badRequest("Invalid Next Token");
|
||||
}
|
||||
|
||||
/** SES lists the token before the page size. */
|
||||
static AwsException bothError(int pageSize) {
|
||||
return badRequest("2 validation errors detected: " + EMPTY_TOKEN + "; "
|
||||
+ pageSizeViolation(pageSize));
|
||||
}
|
||||
}
|
||||
|
||||
private final String namespace;
|
||||
@@ -82,22 +137,29 @@ public enum SesListPaging {
|
||||
private final int servedWhenOutOfRange;
|
||||
private final Function<String, AwsException> invalidToken;
|
||||
private final boolean emptyTokenInvalid;
|
||||
private final Function<Integer, AwsException> sizeAndEmptyTokenInvalid;
|
||||
|
||||
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);
|
||||
this(namespace, defaultPageSize, maxPageSize, outOfRange, 0, invalidToken, emptyTokenInvalid, null);
|
||||
}
|
||||
|
||||
SesListPaging(String namespace, int defaultPageSize, int maxPageSize, int servedWhenOutOfRange,
|
||||
Function<String, AwsException> invalidToken, boolean emptyTokenInvalid) {
|
||||
this(namespace, defaultPageSize, maxPageSize, null, servedWhenOutOfRange, invalidToken,
|
||||
emptyTokenInvalid);
|
||||
emptyTokenInvalid, null);
|
||||
}
|
||||
|
||||
SesListPaging(String tenantStyleNamespace) {
|
||||
this(tenantStyleNamespace, TenantLists.BOUND, TenantLists.BOUND, TenantLists::pageSizeError, 0,
|
||||
TenantLists::tokenError, true, TenantLists::bothError);
|
||||
}
|
||||
|
||||
SesListPaging(String namespace, int defaultPageSize, int maxPageSize,
|
||||
Function<Integer, AwsException> outOfRange, int servedWhenOutOfRange,
|
||||
Function<String, AwsException> invalidToken, boolean emptyTokenInvalid) {
|
||||
Function<String, AwsException> invalidToken, boolean emptyTokenInvalid,
|
||||
Function<Integer, AwsException> sizeAndEmptyTokenInvalid) {
|
||||
this.namespace = namespace;
|
||||
this.defaultPageSize = defaultPageSize;
|
||||
this.maxPageSize = maxPageSize;
|
||||
@@ -105,15 +167,31 @@ public enum SesListPaging {
|
||||
this.servedWhenOutOfRange = servedWhenOutOfRange;
|
||||
this.invalidToken = invalidToken;
|
||||
this.emptyTokenInvalid = emptyTokenInvalid;
|
||||
this.sizeAndEmptyTokenInvalid = sizeAndEmptyTokenInvalid;
|
||||
}
|
||||
|
||||
<T> PaginatedResult<T> page(String region, List<T> all, Function<T, String> cursorOf, Integer pageSize,
|
||||
String nextToken) {
|
||||
return page(region, "", all, cursorOf, pageSize, nextToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code scope} names what else the request selected, a tenant or a filter, for the lists whose
|
||||
* tokens SES refuses once that changes.
|
||||
*/
|
||||
<T> PaginatedResult<T> page(String region, String scope, List<T> all, Function<T, String> cursorOf,
|
||||
Integer pageSize, String nextToken) {
|
||||
boolean emptyToken = nextToken != null && nextToken.isEmpty() && emptyTokenInvalid;
|
||||
if (emptyToken && sizeAndEmptyTokenInvalid != null && pageSize != null
|
||||
&& (pageSize < 1 || pageSize > maxPageSize)) {
|
||||
throw sizeAndEmptyTokenInvalid.apply(pageSize);
|
||||
}
|
||||
int limit = pageSize(pageSize);
|
||||
if (nextToken != null && nextToken.isEmpty() && emptyTokenInvalid) {
|
||||
if (emptyToken) {
|
||||
throw invalidToken.apply(nextToken);
|
||||
}
|
||||
return Pagination.paginate(all, cursorOf, limit, nextToken, namespace + "@" + region, invalidToken);
|
||||
return Pagination.paginate(all, cursorOf, limit, nextToken, namespace + "@" + region + scope,
|
||||
invalidToken);
|
||||
}
|
||||
|
||||
int pageSize(Integer requested) {
|
||||
@@ -135,6 +213,18 @@ public enum SesListPaging {
|
||||
return descending + "#" + id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Oldest first, as SES lists a resource's tenants; the id orders equal timestamps. The cursor
|
||||
* keeps the whole instant, so it orders exactly as a comparison of the instants does, and a
|
||||
* missing timestamp sorts last.
|
||||
*/
|
||||
static String oldestFirst(Instant created, String id) {
|
||||
String time = created == null
|
||||
? "~"
|
||||
: String.format(Locale.ROOT, "%019d.%09d", created.getEpochSecond(), created.getNano());
|
||||
return time + "#" + id;
|
||||
}
|
||||
|
||||
/** 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()) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsRegions;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntry;
|
||||
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntryResult;
|
||||
@@ -924,24 +925,25 @@ public class SesService {
|
||||
tenantService.disassociate(tenant, ref, region);
|
||||
}
|
||||
|
||||
public List<TenantResourceAssociation> listTenantResources(String tenantName,
|
||||
String resourceTypeFilter,
|
||||
Integer pageSize, String nextToken,
|
||||
String region) {
|
||||
SesTenantService.validateListPaging(pageSize, nextToken);
|
||||
SesTenantService.validateResourceTypeFilter(resourceTypeFilter);
|
||||
// Probe-confirmed order on both lists: the tenant or resource is resolved first and the filter is
|
||||
// checked next, so a bad page on a missing tenant is the 404; the page size and token come last.
|
||||
public PaginatedResult<TenantResourceAssociation> listTenantResources(String tenantName,
|
||||
String resourceTypeFilter,
|
||||
SesListPaging paging,
|
||||
Integer pageSize, String nextToken,
|
||||
String region) {
|
||||
Tenant tenant = tenantService.tenantForAssociation(tenantName, region);
|
||||
return tenantService.listTenantResources(tenant, resourceTypeFilter, region);
|
||||
SesTenantService.validateResourceTypeFilter(resourceTypeFilter);
|
||||
return tenantService.listTenantResources(tenant, resourceTypeFilter, region, paging, pageSize, nextToken);
|
||||
}
|
||||
|
||||
public List<TenantResourceAssociation> listResourceTenants(String resourceArn, Integer pageSize,
|
||||
String nextToken, String accountId,
|
||||
String region) {
|
||||
SesTenantService.validateListPaging(pageSize, nextToken);
|
||||
public PaginatedResult<TenantResourceAssociation> listResourceTenants(String resourceArn, SesListPaging paging,
|
||||
Integer pageSize, String nextToken,
|
||||
String accountId, String region) {
|
||||
SesTenantService.AssociationResource ref =
|
||||
SesTenantService.parseResourceArn(resourceArn, accountId, region);
|
||||
requireTenantResourceExists(ref, region);
|
||||
return tenantService.listResourceTenants(ref, region);
|
||||
return tenantService.listResourceTenants(ref, region, paging, pageSize, nextToken);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.Tag;
|
||||
import io.github.hectorvent.floci.services.ses.model.Tenant;
|
||||
@@ -118,26 +119,31 @@ public class SesTenantController {
|
||||
public Response listTenants(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
// Parse the body so a malformed request is rejected rather than silently accepted. Phase 1
|
||||
// returns every tenant in one page; PageSize/NextToken pagination is a follow-up.
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
Integer pageSize = intMemberOrAbsent(request, "PageSize");
|
||||
String nextToken = stringMemberOrAbsent(request, "NextToken");
|
||||
PaginatedResult<Tenant> page = tenantService.listTenants(region, SesListPaging.V2_LIST_TENANTS,
|
||||
pageSize, nextToken);
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
ArrayNode tenants = result.putArray("Tenants");
|
||||
for (Tenant t : page.items()) {
|
||||
// ListTenants returns the TenantInfo subset (no Tags / SendingStatus).
|
||||
ObjectNode item = tenants.addObject();
|
||||
item.put("TenantName", t.tenantName());
|
||||
item.put("TenantId", t.tenantId());
|
||||
item.put("TenantArn", t.tenantArn());
|
||||
putTimestamp(item, "CreatedTimestamp", t.createdTimestamp());
|
||||
}
|
||||
result.put("NextToken", page.nextToken());
|
||||
return Response.ok(result).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("SerializationException", null, 400);
|
||||
}
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
ArrayNode tenants = result.putArray("Tenants");
|
||||
for (Tenant t : tenantService.listTenants(region)) {
|
||||
// ListTenants returns the TenantInfo subset (no Tags / SendingStatus).
|
||||
ObjectNode item = tenants.addObject();
|
||||
item.put("TenantName", t.tenantName());
|
||||
item.put("TenantId", t.tenantId());
|
||||
item.put("TenantArn", t.tenantArn());
|
||||
putTimestamp(item, "CreatedTimestamp", t.createdTimestamp());
|
||||
}
|
||||
return Response.ok(result).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@@ -224,13 +230,13 @@ public class SesTenantController {
|
||||
}
|
||||
Integer pageSize = intMemberOrAbsent(request, "PageSize");
|
||||
String nextToken = stringMemberOrAbsent(request, "NextToken");
|
||||
List<TenantResourceAssociation> associations = sesService.listTenantResources(
|
||||
tenantName, resourceTypeFilter, pageSize, nextToken, region);
|
||||
PaginatedResult<TenantResourceAssociation> page = sesService.listTenantResources(
|
||||
tenantName, resourceTypeFilter, SesListPaging.V2_LIST_TENANT_RESOURCES, pageSize, nextToken,
|
||||
region);
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
// AWS renders NextToken as an explicit null on the last (here: only) page.
|
||||
result.putNull("NextToken");
|
||||
result.put("NextToken", page.nextToken());
|
||||
ArrayNode resources = result.putArray("TenantResources");
|
||||
for (TenantResourceAssociation a : associations) {
|
||||
for (TenantResourceAssociation a : page.items()) {
|
||||
ObjectNode item = resources.addObject();
|
||||
item.put("ResourceArn", a.resourceArn());
|
||||
item.put("ResourceType", a.resourceType());
|
||||
@@ -255,12 +261,13 @@ public class SesTenantController {
|
||||
String resourceArn = stringMemberOrAbsent(request, "ResourceArn");
|
||||
Integer pageSize = intMemberOrAbsent(request, "PageSize");
|
||||
String nextToken = stringMemberOrAbsent(request, "NextToken");
|
||||
List<TenantResourceAssociation> associations = sesService.listResourceTenants(
|
||||
resourceArn, pageSize, nextToken, regionResolver.getAccountId(), region);
|
||||
PaginatedResult<TenantResourceAssociation> page = sesService.listResourceTenants(
|
||||
resourceArn, SesListPaging.V2_LIST_RESOURCE_TENANTS, pageSize, nextToken,
|
||||
regionResolver.getAccountId(), region);
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
result.putNull("NextToken");
|
||||
result.put("NextToken", page.nextToken());
|
||||
ArrayNode tenants = result.putArray("ResourceTenants");
|
||||
for (TenantResourceAssociation a : associations) {
|
||||
for (TenantResourceAssociation a : page.items()) {
|
||||
// ResourceTenantMetadata has no TenantArn (probe-confirmed).
|
||||
ObjectNode item = tenants.addObject();
|
||||
item.put("TenantName", a.tenantName());
|
||||
|
||||
@@ -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.Tag;
|
||||
@@ -133,12 +134,16 @@ public class SesTenantService {
|
||||
.orElseThrow(() -> tenantNotFound(tenantName));
|
||||
}
|
||||
|
||||
public PaginatedResult<Tenant> listTenants(String region, SesListPaging paging, Integer pageSize,
|
||||
String nextToken) {
|
||||
return paging.page(region, listTenants(region), Tenant::tenantName, pageSize, nextToken);
|
||||
}
|
||||
|
||||
/** By name, as SES lists them; the paged list resumes on the same order. */
|
||||
public List<Tenant> listTenants(String region) {
|
||||
String prefix = tenantKeyPrefix(region);
|
||||
return tenantStore.scan(k -> k.startsWith(prefix)).stream()
|
||||
.sorted(Comparator.comparing(Tenant::createdTimestamp,
|
||||
Comparator.nullsLast(Comparator.naturalOrder()))
|
||||
.thenComparing(Tenant::tenantName, Comparator.nullsLast(Comparator.naturalOrder())))
|
||||
.sorted(Comparator.comparing(Tenant::tenantName))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@@ -413,7 +418,15 @@ public class SesTenantService {
|
||||
ref.arn(), tenant.tenantName(), region);
|
||||
}
|
||||
|
||||
/** AWS returns the tenant's resources ordered by ARN. */
|
||||
public PaginatedResult<TenantResourceAssociation> listTenantResources(Tenant tenant, String typeFilter,
|
||||
String region, SesListPaging paging,
|
||||
Integer pageSize, String nextToken) {
|
||||
return paging.page(region, "/" + tenant.tenantId() + "/" + typeFilter,
|
||||
listTenantResources(tenant, typeFilter, region), TenantResourceAssociation::resourceArn,
|
||||
pageSize, nextToken);
|
||||
}
|
||||
|
||||
/** AWS returns the tenant's resources ordered by ARN; the paged list resumes on the same order. */
|
||||
public List<TenantResourceAssociation> listTenantResources(Tenant tenant, String typeFilter,
|
||||
String region) {
|
||||
String prefix = associationKeyPrefix(region, tenant.tenantId());
|
||||
@@ -428,7 +441,14 @@ public class SesTenantService {
|
||||
// itself contain the "::" delimiter (Floci barely restricts identity and template names), so a
|
||||
// suffix match on the key could alias one resource's associations to another's.
|
||||
|
||||
/** AWS returns a resource's tenants ordered by association time. */
|
||||
public PaginatedResult<TenantResourceAssociation> listResourceTenants(AssociationResource ref, String region,
|
||||
SesListPaging paging, Integer pageSize,
|
||||
String nextToken) {
|
||||
return paging.page(region, "/" + ref.arn(), listResourceTenants(ref, region),
|
||||
SesTenantService::associationCursor, pageSize, nextToken);
|
||||
}
|
||||
|
||||
/** AWS returns a resource's tenants ordered by association time; the paged list resumes on the same order. */
|
||||
public List<TenantResourceAssociation> listResourceTenants(AssociationResource ref, String region) {
|
||||
String regionPrefix = "tenantAssoc::" + region + "::";
|
||||
return associationStore.scan(k -> k.startsWith(regionPrefix)).stream()
|
||||
@@ -440,6 +460,10 @@ public class SesTenantService {
|
||||
.toList();
|
||||
}
|
||||
|
||||
private static String associationCursor(TenantResourceAssociation association) {
|
||||
return SesListPaging.oldestFirst(association.associatedTimestamp(), association.tenantName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds any association for the given resource, for the facade's delete guards: AWS refuses to
|
||||
* delete an identity, configuration set, or template that still has tenant associations.
|
||||
@@ -467,21 +491,6 @@ public class SesTenantService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The list operations return everything in one page, so any client-supplied NextToken is invalid —
|
||||
* which is also what AWS answers for a token it cannot decrypt. PageSize is still range-checked.
|
||||
*/
|
||||
public static void validateListPaging(Integer pageSize, String nextToken) {
|
||||
if (pageSize != null && pageSize < 1) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"1 validation error detected: Value '" + pageSize + "' at 'pageSize' failed to "
|
||||
+ "satisfy constraint: Member must have value greater than or equal to 1", 400);
|
||||
}
|
||||
if (nextToken != null) {
|
||||
throw new AwsException("BadRequestException", "Invalid Next Token", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static String associationKey(String region, String tenantId, AssociationResource ref) {
|
||||
return associationKeyPrefix(region, tenantId) + ref.type() + "::" + ref.name();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user