mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(ses): add v2 PutAccountSuppressionAttributes (#853)
Implements PUT /v2/email/account/suppression so callers can change the account-level suppression list reasons (BOUNCE / COMPLAINT). Entries are persisted per region in ses-account-suppression.json via a new AccountSuppressionAttributes model. GetAccount's response is extended with a SuppressionAttributes object that carries the stored SuppressedReasons. The setting itself is metadata-only — floci does not synthesise bounce/complaint events so no auto-suppression is triggered; the configuration round-trips for SDK users and tooling that introspects account-level settings. Behaviour aligned with real-AWS verification: - SuppressedReasons accepts BOUNCE / COMPLAINT, validated against the AWS-canonical nested "Member must satisfy constraint: [Member must satisfy enum value set: [BOUNCE, COMPLAINT]]" wording (verbatim match against real AWS). - SuppressedReasons may be omitted (treated as empty list) or supplied as an empty array (clears the reasons) — both return 200. - Non-textual array members (JSON null, numeric, etc.) are rejected with BadRequestException. - Fresh regions report the AWS-default [BOUNCE, COMPLAINT] via GetAccount; an explicit PUT (including an empty list) overrides it. - The optional ValidationAttributes body field is accepted but not parsed (Tier S scope). Tests: - SesV2IntegrationTest gains nine cases covering store-and-list, clear-with-empty-array, missing field defaulting to empty, invalid Reason (with the AWS-canonical nested message asserted), non-array SuppressedReasons, JSON null array member, numeric array member, optional ValidationAttributes, and the default-on-fresh-region assertion in the existing getAccount case. - SesAccountSuppressionTest exercises the Java SDK round trip and an explicit empty list through SesV2Client; @BeforeAll captures the caller's existing SuppressedReasons and @AfterAll restores it with failures surfaced so a real-AWS run cannot silently leave the account with auto-suppression disabled.
This commit is contained in:
1 parent
6d36f66e5f
commit
010bbd15cd
8 files changed
+362
-2
No files matched your search
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.services.ses.model.AccountSuppressionAttributes;
|
||||
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntry;
|
||||
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntryResult;
|
||||
import io.github.hectorvent.floci.services.ses.model.ConfigurationSet;
|
||||
@@ -658,6 +659,7 @@ public class SesController {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
long sentCount = sesService.getSentEmailCount(region);
|
||||
boolean sendingEnabled = sesService.isAccountSendingEnabled(region);
|
||||
AccountSuppressionAttributes suppression = sesService.getAccountSuppressionAttributes(region);
|
||||
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
result.put("DedicatedIpAutoWarmupEnabled", false);
|
||||
@@ -670,9 +672,48 @@ public class SesController {
|
||||
sendQuota.put("MaxSendRate", 1.0);
|
||||
sendQuota.put("SentLast24Hours", (double) sentCount);
|
||||
|
||||
ObjectNode suppressionAttrs = result.putObject("SuppressionAttributes");
|
||||
ArrayNode reasons = suppressionAttrs.putArray("SuppressedReasons");
|
||||
for (String r : suppression.getSuppressedReasons()) {
|
||||
reasons.add(r);
|
||||
}
|
||||
|
||||
return Response.ok(result).build();
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/account/suppression")
|
||||
public Response putAccountSuppressionAttributes(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode reasonsNode = request.path("SuppressedReasons");
|
||||
List<String> reasons = new ArrayList<>();
|
||||
if (!reasonsNode.isMissingNode() && !reasonsNode.isNull()) {
|
||||
if (!reasonsNode.isArray()) {
|
||||
throw new AwsException("BadRequestException", "SuppressedReasons must be an array.", 400);
|
||||
}
|
||||
for (JsonNode r : reasonsNode) {
|
||||
if (r.isNull() || !r.isTextual()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"SuppressedReasons entries must be strings.", 400);
|
||||
}
|
||||
reasons.add(r.asText());
|
||||
}
|
||||
}
|
||||
sesService.putAccountSuppressionAttributes(region, reasons);
|
||||
LOG.infov("SES V2 PutAccountSuppressionAttributes: {0}", reasons);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (com.fasterxml.jackson.core.JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/account/sending")
|
||||
public Response putAccountSendingAttributes(@Context HttpHeaders headers, String body) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
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;
|
||||
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntry;
|
||||
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntryResult;
|
||||
import io.github.hectorvent.floci.services.ses.model.ConfigurationSet;
|
||||
@@ -56,6 +57,7 @@ public class SesService {
|
||||
private final StorageBackend<String, EmailTemplate> templateStore;
|
||||
private final StorageBackend<String, ConfigurationSet> configSetStore;
|
||||
private final StorageBackend<String, SuppressedDestination> suppressionStore;
|
||||
private final StorageBackend<String, AccountSuppressionAttributes> accountSuppressionStore;
|
||||
private final SmtpRelay smtpRelay;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@@ -73,6 +75,8 @@ public class SesService {
|
||||
new TypeReference<Map<String, ConfigurationSet>>() {});
|
||||
this.suppressionStore = storageFactory.create("ses", "ses-suppression.json",
|
||||
new TypeReference<Map<String, SuppressedDestination>>() {});
|
||||
this.accountSuppressionStore = storageFactory.create("ses", "ses-account-suppression.json",
|
||||
new TypeReference<Map<String, AccountSuppressionAttributes>>() {});
|
||||
this.smtpRelay = smtpRelay;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
@@ -83,6 +87,7 @@ public class SesService {
|
||||
StorageBackend<String, EmailTemplate> templateStore,
|
||||
StorageBackend<String, ConfigurationSet> configSetStore,
|
||||
StorageBackend<String, SuppressedDestination> suppressionStore,
|
||||
StorageBackend<String, AccountSuppressionAttributes> accountSuppressionStore,
|
||||
SmtpRelay smtpRelay,
|
||||
ObjectMapper objectMapper) {
|
||||
this.identityStore = identityStore;
|
||||
@@ -91,6 +96,7 @@ public class SesService {
|
||||
this.templateStore = templateStore;
|
||||
this.configSetStore = configSetStore;
|
||||
this.suppressionStore = suppressionStore;
|
||||
this.accountSuppressionStore = accountSuppressionStore;
|
||||
this.smtpRelay = smtpRelay;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
@@ -695,6 +701,39 @@ public class SesService {
|
||||
return new ResourceRef(parsed.region(), resource.substring(0, slash), resource.substring(slash + 1));
|
||||
}
|
||||
|
||||
// ──────────────────── Account-level suppression attributes ────────────────────
|
||||
|
||||
public AccountSuppressionAttributes getAccountSuppressionAttributes(String region) {
|
||||
return accountSuppressionStore.get(accountSuppressionKey(region))
|
||||
.orElseGet(SesService::defaultAccountSuppressionAttributes);
|
||||
}
|
||||
|
||||
private static AccountSuppressionAttributes defaultAccountSuppressionAttributes() {
|
||||
// Fresh SES accounts default to auto-suppression on both BOUNCE and COMPLAINT;
|
||||
// an explicit PUT (including an empty list) overrides this.
|
||||
AccountSuppressionAttributes attrs = new AccountSuppressionAttributes();
|
||||
attrs.setSuppressedReasons(new ArrayList<>(List.of("BOUNCE", "COMPLAINT")));
|
||||
return attrs;
|
||||
}
|
||||
|
||||
public void putAccountSuppressionAttributes(String region, List<String> suppressedReasons) {
|
||||
List<String> sanitized = new ArrayList<>();
|
||||
if (suppressedReasons != null) {
|
||||
for (String r : suppressedReasons) {
|
||||
validateSuppressionReason(r, "suppressedReasons", true);
|
||||
sanitized.add(r);
|
||||
}
|
||||
}
|
||||
AccountSuppressionAttributes attrs = new AccountSuppressionAttributes();
|
||||
attrs.setSuppressedReasons(sanitized);
|
||||
accountSuppressionStore.put(accountSuppressionKey(region), attrs);
|
||||
LOG.infov("Updated account suppression attributes for region {0}: {1}", region, sanitized);
|
||||
}
|
||||
|
||||
private static String accountSuppressionKey(String region) {
|
||||
return "account-suppression::" + region;
|
||||
}
|
||||
|
||||
// ──────────────────────────── Suppression list ────────────────────────────
|
||||
|
||||
public void putSuppressedDestination(String region, String emailAddress, String reason) {
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package io.github.hectorvent.floci.services.ses.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class AccountSuppressionAttributes {
|
||||
|
||||
@JsonProperty("SuppressedReasons")
|
||||
private List<String> suppressedReasons = new ArrayList<>();
|
||||
|
||||
public AccountSuppressionAttributes() {}
|
||||
|
||||
public List<String> getSuppressedReasons() { return suppressedReasons; }
|
||||
public void setSuppressedReasons(List<String> suppressedReasons) {
|
||||
this.suppressedReasons = suppressedReasons != null ? suppressedReasons : new ArrayList<>();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user