mirror of
https://github.com/floci-io/floci.git
synced 2026-11-30 08:55:17 -05:00
refactor(ses): move ListTenantResources into SesTenantService and drop unused resolveSuppressionReason (#4978)
This commit is contained in:
1 parent
a95f4cee3d
commit
a68f8eab3a
7 files changed
+54
-89
No files matched your search
@@ -891,8 +891,9 @@ public class SesService {
|
||||
|
||||
// ──────────────────────── Tenants (multi-tenancy) ────────────────────────
|
||||
// Tenants live in SesTenantService, which the v2 controller calls directly for the tenant
|
||||
// record and its suppression attributes; the facade keeps the resource associations (they
|
||||
// check the identity, configuration set or template exists) and the delete cascade.
|
||||
// record, its suppression attributes and the tenant's resource list; the facade keeps the
|
||||
// association operations that check the identity, configuration set or template exists, and
|
||||
// the delete cascade.
|
||||
|
||||
public void deleteTenant(String tenantName, String region) {
|
||||
// The tenant-scoped suppression entries live in the suppression domain; the callback runs
|
||||
@@ -925,18 +926,8 @@ public class SesService {
|
||||
tenantService.disassociate(tenant, ref, region);
|
||||
}
|
||||
|
||||
// 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);
|
||||
SesTenantService.validateResourceTypeFilter(resourceTypeFilter);
|
||||
return tenantService.listTenantResources(tenant, resourceTypeFilter, region, paging, pageSize, nextToken);
|
||||
}
|
||||
|
||||
// Probe-confirmed order: the resource is resolved first, so a bad page on a missing resource is
|
||||
// the 404; the page size and token come last.
|
||||
public PaginatedResult<TenantResourceAssociation> listResourceTenants(String resourceArn, SesListPaging paging,
|
||||
Integer pageSize, String nextToken,
|
||||
String accountId, String region) {
|
||||
@@ -1239,7 +1230,7 @@ public class SesService {
|
||||
// TenantName sends the operation to that tenant's own list, which is fully separate from the
|
||||
// account list on AWS, and the reason and address validation still runs first, matching the
|
||||
// probed precedence where request validation precedes tenant existence. The send filters
|
||||
// (collectSuppressedReasons, resolveSuppressionReason) read entries back through the service.
|
||||
// (collectSuppressedReasons) read entries back through the service.
|
||||
|
||||
public void putSuppressedDestination(String region, String emailAddress, String reason,
|
||||
String tenantName) {
|
||||
@@ -1430,42 +1421,6 @@ public class SesService {
|
||||
return kept;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the suppression reason that applies to a given recipient in the given region
|
||||
* for sends using {@code configurationSetName}, or {@code null} if the recipient is not
|
||||
* suppressed. The recipient is suppressed only when it appears in the address-level
|
||||
* suppression list AND its stored reason intersects the effective {@code suppressedReasons}
|
||||
* — the configuration set's {@code SuppressionOptions} override if present, else the
|
||||
* account-level reasons. {@code configurationSetName} may be {@code null} or blank to
|
||||
* scope the check to account-level reasons only.
|
||||
*
|
||||
* <p>The returned value is one of {@code "BOUNCE"} / {@code "COMPLAINT"}, allowing
|
||||
* callers (publishSendEvents) to map the recipient to a synthetic Bounce / Complaint
|
||||
* event without consulting the store again. Both the per-address suppression entries
|
||||
* and the account-level / per-CS {@code suppressedReasons} go through reason validation
|
||||
* (in {@link SesSuppressionService} and {@link SesConfigurationSetService} respectively),
|
||||
* which enforces exact case-sensitive equality with the two canonical values, so
|
||||
* {@code entry.getReason()} is guaranteed to be canonical and downstream
|
||||
* {@code .equals("BOUNCE")} / {@code .equals("COMPLAINT")} checks are safe.
|
||||
*/
|
||||
String resolveSuppressionReason(String emailAddress, String configurationSetName, String region) {
|
||||
if (emailAddress == null || emailAddress.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
// Read through the suppression service so this shares its normalization and legacy-key
|
||||
// fallback with GET/DELETE (lookups can't drift apart from inserts).
|
||||
SuppressedDestination entry = suppressionService.findSuppressedDestination(region, emailAddress)
|
||||
.orElse(null);
|
||||
if (entry == null || entry.getReason() == null) {
|
||||
return null;
|
||||
}
|
||||
List<String> effective = getEffectiveSuppressedReasons(configurationSetName, region);
|
||||
if (effective == null || effective.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return effective.contains(entry.getReason()) ? entry.getReason() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Also called by the controller ahead of the tenant send gate: AWS reports an empty inline
|
||||
* template before it looks the tenant up (probe-confirmed), so the check must not stay behind
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.TreeSet;
|
||||
* rather than splitting one off, both stores move together into this service and the helper becomes
|
||||
* a private detail of it. The send path keeps its cross-domain orchestration
|
||||
* ({@code getEffectiveSuppressedReasons} reads a configuration set's options or falls back here;
|
||||
* {@code collectSuppressedReasons}/{@code resolveSuppressionReason} filter a send) in the
|
||||
* {@code collectSuppressedReasons} filters a send) in the
|
||||
* {@link SesService} facade, which reads entries back through {@link #findSuppressedDestination}.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
@@ -136,9 +136,9 @@ public class SesSuppressionService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a suppression entry without throwing, so the facade's send-path filters
|
||||
* ({@code collectSuppressedReasons} / {@code resolveSuppressionReason}) can look one up by raw
|
||||
* address and share this service's normalization and legacy-key fallback.
|
||||
* Reads a suppression entry without throwing, so the facade's send-path filter
|
||||
* ({@code collectSuppressedReasons}) can look one up by raw address and share this service's
|
||||
* normalization and legacy-key fallback.
|
||||
*/
|
||||
public Optional<SuppressedDestination> findSuppressedDestination(String region, String rawEmail) {
|
||||
if (rawEmail == null || rawEmail.isBlank()) {
|
||||
|
||||
@@ -34,10 +34,10 @@ import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAb
|
||||
|
||||
/**
|
||||
* SES V2 tenant endpoints ({@code /v2/email/tenants}, {@code /v2/email/tenant} and
|
||||
* {@code /v2/email/resources/tenants}). Tenant create, get, list and suppression attributes
|
||||
* call {@link SesTenantService} directly; the resource
|
||||
* associations and tenant delete go through the {@link SesService} facade, which checks the
|
||||
* associated identity, configuration set or template exists and cascades the tenant's
|
||||
* {@code /v2/email/resources/tenants}). Tenant create, get, list, suppression attributes and the
|
||||
* tenant's resource list call {@link SesTenantService} directly; association create and delete,
|
||||
* the resource's tenant list and tenant delete go through the {@link SesService} facade, which
|
||||
* checks the associated identity, configuration set or template exists and cascades the tenant's
|
||||
* suppression entries, work that spans several domains.
|
||||
*/
|
||||
@Path("/v2/email")
|
||||
@@ -230,9 +230,9 @@ public class SesTenantController {
|
||||
}
|
||||
Integer pageSize = intMemberOrAbsent(request, "PageSize");
|
||||
String nextToken = stringMemberOrAbsent(request, "NextToken");
|
||||
PaginatedResult<TenantResourceAssociation> page = sesService.listTenantResources(
|
||||
tenantName, resourceTypeFilter, SesListPaging.V2_LIST_TENANT_RESOURCES, pageSize, nextToken,
|
||||
region);
|
||||
PaginatedResult<TenantResourceAssociation> page = tenantService.listTenantResources(
|
||||
tenantName, resourceTypeFilter, region, SesListPaging.V2_LIST_TENANT_RESOURCES, pageSize,
|
||||
nextToken);
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
result.put("NextToken", page.nextToken());
|
||||
ArrayNode resources = result.putArray("TenantResources");
|
||||
|
||||
@@ -419,9 +419,13 @@ public class SesTenantService {
|
||||
ref.arn(), tenant.tenantName(), region);
|
||||
}
|
||||
|
||||
public PaginatedResult<TenantResourceAssociation> listTenantResources(Tenant tenant, String typeFilter,
|
||||
// Probe-confirmed order: the tenant 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 typeFilter,
|
||||
String region, SesListPaging paging,
|
||||
Integer pageSize, String nextToken) {
|
||||
Tenant tenant = tenantForAssociation(tenantName, region);
|
||||
validateResourceTypeFilter(typeFilter);
|
||||
return paging.page(region, tenant.tenantId() + "/" + Objects.toString(typeFilter, ""),
|
||||
listTenantResources(tenant, typeFilter, region), TenantResourceAssociation::resourceArn,
|
||||
pageSize, nextToken);
|
||||
|
||||
Reference in new issue
Block a user