feat(ses): support v2 PutAccountDetails and GetAccount Details (#2498)

* feat(ses): support v2 PutAccountDetails and GetAccount Details

Add the SES v2 PutAccountDetails operation and surface its data under GetAccount's
Details. Details are per-region and present-when-set (like VdmAttributes): GetAccount
omits the block until PutAccountDetails is called for the region. MailType and
WebsiteURL are required, and their null violations are reported together (aggregated),
matching AWS; MailType/ContactLanguage are enum-constrained. Floci has no sandbox and
runs no production-access review, so ReviewDetails.Status is reported as GRANTED.

Add unit and integration tests, and document the operation.

* test(ses): cover ProductionAccessEnabled in account details

ProductionAccessEnabled is a GetAccount top-level member (not an
AccountDetails field), and Floci has no sandbox so it stays true
regardless of the value sent to PutAccountDetails. Add an integration
case asserting the top-level flag stays true and never appears inside
Details, and assert at the service layer that the value is still stored
as given.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-08-23 20:48:31 -04:00
1 parent 824701481c
commit 622ba0adbd
9 files changed
+621 -6

No files matched your search

@@ -1,23 +1,31 @@
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.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.ses.model.AccountDetails;
import io.github.hectorvent.floci.services.ses.model.AccountVdmAttributes;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Pattern;
/**
* Account-level SES settings, extracted from {@link SesService} as part of the store-based domain
* split. Reached through the {@code SesService} facade, which delegates here.
*
* <p>Owns the account sending-enabled flag ({@code accountSettingsStore}) and the VDM (Virtual
* Deliverability Manager) attributes ({@code accountVdmStore}). Account suppression is account-level
* too, but it shares {@code validateSuppressionReason} with the suppression list, so it lives in
* <p>Owns the account sending-enabled flag ({@code accountSettingsStore}), the VDM (Virtual
* Deliverability Manager) attributes ({@code accountVdmStore}), and the provisioning details
* ({@code accountDetailsStore}). Account suppression is account-level too, but it shares
* {@code validateSuppressionReason} with the suppression list, so it lives in
* {@link SesSuppressionService} instead.
*/
@ApplicationScoped
@@ -27,6 +35,7 @@ public class SesAccountService {
private final StorageBackend<String, Boolean> accountSettingsStore;
private final StorageBackend<String, AccountVdmAttributes> accountVdmStore;
private final StorageBackend<String, AccountDetails> accountDetailsStore;
@Inject
public SesAccountService(StorageFactory storageFactory) {
@@ -34,12 +43,16 @@ public class SesAccountService {
new TypeReference<Map<String, Boolean>>() {});
this.accountVdmStore = storageFactory.create("ses", "ses-account-vdm.json",
new TypeReference<Map<String, AccountVdmAttributes>>() {});
this.accountDetailsStore = storageFactory.create("ses", "ses-account-details.json",
new TypeReference<Map<String, AccountDetails>>() {});
}
SesAccountService(StorageBackend<String, Boolean> accountSettingsStore,
StorageBackend<String, AccountVdmAttributes> accountVdmStore) {
StorageBackend<String, AccountVdmAttributes> accountVdmStore,
StorageBackend<String, AccountDetails> accountDetailsStore) {
this.accountSettingsStore = accountSettingsStore;
this.accountVdmStore = accountVdmStore;
this.accountDetailsStore = accountDetailsStore;
}
public boolean isAccountSendingEnabled(String region) {
@@ -67,4 +80,118 @@ public class SesAccountService {
private static String accountVdmKey(String region) {
return "account-vdm::" + region;
}
// Provisioning details are opt-in and per region, like VDM: GetAccount omits Details entirely
// until PutAccountDetails is called for the region, so this returns empty for an unconfigured
// region.
public Optional<AccountDetails> findAccountDetails(String region) {
return accountDetailsStore.get(accountDetailsKey(region));
}
// Owns the domain behavior for account details so it can't be bypassed by another caller: it
// validates the modeled constraints, mints the synthetic review/case (Floci has no sandbox and
// runs no production-access review, so the review is always GRANTED), and persists the record. The
// controller only parses the REST JSON and rejects wrong JSON types before calling this.
public AccountDetails putAccountDetails(String region, String mailType, String websiteUrl,
String contactLanguage, String useCaseDescription,
List<String> additionalContacts, boolean productionAccessEnabled) {
validateAccountDetails(mailType, websiteUrl, contactLanguage, useCaseDescription, additionalContacts);
AccountDetails details = new AccountDetails(mailType, websiteUrl, contactLanguage,
useCaseDescription, additionalContacts, productionAccessEnabled, "GRANTED",
syntheticCaseId(region, mailType, websiteUrl));
accountDetailsStore.put(accountDetailsKey(region), details);
LOG.infov("Updated account details for region {0}: mailType={1}, productionAccess={2}",
region, mailType, productionAccessEnabled);
return details;
}
private static String accountDetailsKey(String region) {
return "account-details::" + region;
}
// A stable, region-scoped synthetic case id (kept constant across GetAccount reads for the same
// input). Floci has no real review case; the value only matches AWS's numeric-string shape.
private static String syntheticCaseId(String region, String mailType, String websiteUrl) {
return String.valueOf(1_000_000_000L
+ Math.floorMod((region + "::" + mailType + "::" + websiteUrl).hashCode(), 1_000_000_000));
}
private static final Set<String> MAIL_TYPES = Set.of("MARKETING", "TRANSACTIONAL");
private static final Set<String> CONTACT_LANGUAGES = Set.of("EN", "JA");
// Modeled constraint bounds (from the SES v2 SDK model, probe-confirmed against real AWS).
private static final int WEBSITE_URL_MAX = 1000;
private static final int USE_CASE_DESCRIPTION_MAX = 5000;
private static final int CONTACTS_MAX = 4;
private static final int CONTACT_MIN = 6;
private static final int CONTACT_MAX = 254;
private static final Pattern CONTACT_PATTERN = Pattern.compile("^(.+)@(.+)$");
// AWS aggregates every modeled-constraint violation (null / enum / length / list / element) into a
// single "N validation errors detected: ..." response. Floci mirrors the message text and count;
// the order across fields is deterministic here (declared order) rather than AWS's internal order.
// The "Url contains invalid format" business check is separate and only runs once the modeled
// constraints pass (probe-confirmed: a well-formed-length but non-URL value returns it standalone).
private static void validateAccountDetails(String mailType, String websiteUrl, String contactLanguage,
String useCaseDescription, List<String> additionalContacts) {
List<String> errors = new ArrayList<>();
if (mailType == null) {
errors.add(constraint("mailType", "Member must not be null"));
} else if (!MAIL_TYPES.contains(mailType)) {
errors.add(constraint("mailType", "Member must satisfy enum value set: [MARKETING, TRANSACTIONAL]"));
}
if (websiteUrl == null) {
errors.add(constraint("websiteURL", "Member must not be null"));
} else if (websiteUrl.isEmpty()) {
errors.add(constraint("websiteURL", "Member must have length greater than or equal to 1"));
} else if (websiteUrl.length() > WEBSITE_URL_MAX) {
errors.add(constraint("websiteURL", "Member must have length less than or equal to " + WEBSITE_URL_MAX));
}
if (contactLanguage != null && !CONTACT_LANGUAGES.contains(contactLanguage)) {
errors.add(constraint("contactLanguage", "Member must satisfy enum value set: [EN, JA]"));
}
if (useCaseDescription != null && useCaseDescription.length() > USE_CASE_DESCRIPTION_MAX) {
errors.add(constraint("useCaseDescription",
"Member must have length less than or equal to " + USE_CASE_DESCRIPTION_MAX));
}
if (additionalContacts != null) {
if (additionalContacts.isEmpty()) {
errors.add(constraint("additionalContactEmailAddresses",
"Member must have length greater than or equal to 1"));
} else if (additionalContacts.size() > CONTACTS_MAX) {
errors.add(constraint("additionalContactEmailAddresses",
"Member must have length less than or equal to " + CONTACTS_MAX));
}
for (String contact : additionalContacts) {
if (contact == null || contact.length() < CONTACT_MIN || contact.length() > CONTACT_MAX
|| !CONTACT_PATTERN.matcher(contact).matches()) {
// AWS reports all three element sub-constraints together regardless of which failed.
errors.add(constraint("additionalContactEmailAddresses",
"Member must satisfy constraint: [Member must have length less than or equal to "
+ CONTACT_MAX + ", Member must have length greater than or equal to "
+ CONTACT_MIN + ", Member must satisfy regular expression pattern: ^(.+)@(.+)$]"));
}
}
}
if (!errors.isEmpty()) {
throw new AwsException("BadRequestException",
errors.size() + " validation error" + (errors.size() > 1 ? "s" : "")
+ " detected: " + String.join("; ", errors), 400);
}
if (!isValidUrl(websiteUrl)) {
throw new AwsException("BadRequestException", "Url contains invalid format", 400);
}
}
private static String constraint(String field, String detail) {
return "Value at '" + field + "' failed to satisfy constraint: " + detail;
}
private static boolean isValidUrl(String url) {
try {
URI uri = URI.create(url);
return uri.getScheme() != null && uri.getHost() != null;
} catch (IllegalArgumentException e) {
return false;
}
}
}
@@ -1870,6 +1870,27 @@ public class SesController {
}
});
// Like VdmAttributes, AWS omits Details until PutAccountDetails has run for the region.
sesService.findAccountDetails(region).ifPresent(details -> {
ObjectNode d = result.putObject("Details");
d.put("MailType", details.mailType());
d.put("WebsiteURL", details.websiteUrl());
if (details.contactLanguage() != null) {
d.put("ContactLanguage", details.contactLanguage());
}
if (details.useCaseDescription() != null) {
d.put("UseCaseDescription", details.useCaseDescription());
}
if (details.additionalContactEmailAddresses() != null
&& !details.additionalContactEmailAddresses().isEmpty()) {
ArrayNode addrs = d.putArray("AdditionalContactEmailAddresses");
details.additionalContactEmailAddresses().forEach(addrs::add);
}
ObjectNode review = d.putObject("ReviewDetails");
review.put("Status", details.reviewStatus());
review.put("CaseId", details.caseId());
});
return Response.ok(result).build();
}
@@ -1910,6 +1931,75 @@ public class SesController {
}
}
@POST
@Path("/account/details")
public Response putAccountDetails(@Context HttpHeaders headers, String body) {
String region = regionResolver.resolveRegion(headers);
try {
JsonNode request = (body == null || body.isBlank())
? objectMapper.createObjectNode()
: objectMapper.readTree(body);
requireJsonObject(request);
// Parse every member first (rejecting wrong JSON types as a serialization error, the way
// AWS does before validation), then validate the parsed values together so all constraint
// violations are aggregated into one response.
String mailType = requireStringOrAbsent(request, "MailType");
String websiteUrl = requireStringOrAbsent(request, "WebsiteURL");
String contactLanguage = requireStringOrAbsent(request, "ContactLanguage");
String useCaseDescription = requireStringOrAbsent(request, "UseCaseDescription");
List<String> additionalContacts = null;
JsonNode contacts = request.path("AdditionalContactEmailAddresses");
if (!contacts.isMissingNode() && !contacts.isNull()) {
// A typed list member: reject a non-array, and reject non-string elements, rather than
// coercing (asText would turn 123 into "123"), matching how AWS rejects type mismatches.
if (!contacts.isArray()) {
throw new AwsException("SerializationException", null, 400);
}
additionalContacts = new ArrayList<>();
for (JsonNode node : contacts) {
if (!node.isTextual()) {
throw new AwsException("SerializationException", null, 400);
}
additionalContacts.add(node.textValue());
}
}
JsonNode productionAccess = request.path("ProductionAccessEnabled");
if (!productionAccess.isMissingNode() && !productionAccess.isNull() && !productionAccess.isBoolean()) {
throw new AwsException("SerializationException", null, 400);
}
boolean productionAccessEnabled = productionAccess.asBoolean(false);
// The service owns validation and the synthetic review/case so they can't be bypassed; the
// controller only parses the REST JSON and rejects wrong JSON types.
sesService.putAccountDetails(region, mailType, websiteUrl, contactLanguage,
useCaseDescription, additionalContacts, productionAccessEnabled);
LOG.infov("SES V2 PutAccountDetails: region={0}, mailType={1}", region, mailType);
return Response.ok(objectMapper.createObjectNode()).build();
} catch (AwsException e) {
throw remapV1Exception(e);
} catch (com.fasterxml.jackson.core.JsonProcessingException e) {
// AWS reports a malformed JSON body as a SerializationException, the same error type used
// for wrong-typed members above.
throw new AwsException("SerializationException", null, 400);
}
}
// Read a typed string member: absent/null returns null, but a present value of the wrong JSON type
// is rejected rather than coerced (asText would turn 123 into "123"), the same as the identity and
// configuration-set string members elsewhere in this controller.
private static String requireStringOrAbsent(JsonNode parent, String field) {
JsonNode n = parent.path(field);
if (n.isMissingNode() || n.isNull()) {
return null;
}
if (!n.isTextual()) {
throw new AwsException("SerializationException", null, 400);
}
return n.textValue();
}
// Parse an AWS FeatureStatus (ENABLED/DISABLED) field. A required member that is absent, or any
// value outside the enum, is a Smithy BadRequestException the way AWS returns it; an absent
// optional member defaults to DISABLED (false).
@@ -10,6 +10,7 @@ import io.github.hectorvent.floci.services.route53.model.HostedZone;
import io.github.hectorvent.floci.services.route53.model.ResourceRecord;
import io.github.hectorvent.floci.services.route53.model.ResourceRecordSet;
import io.github.hectorvent.floci.services.ses.model.AccountSuppressionAttributes;
import io.github.hectorvent.floci.services.ses.model.AccountDetails;
import io.github.hectorvent.floci.services.ses.model.AccountVdmAttributes;
import io.github.hectorvent.floci.services.ses.model.ArchivingOptions;
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntry;
@@ -1124,6 +1125,17 @@ public class SesService {
accountService.setAccountSendingEnabled(region, enabled);
}
public Optional<AccountDetails> findAccountDetails(String region) {
return accountService.findAccountDetails(region);
}
public AccountDetails putAccountDetails(String region, String mailType, String websiteUrl,
String contactLanguage, String useCaseDescription,
List<String> additionalContacts, boolean productionAccessEnabled) {
return accountService.putAccountDetails(region, mailType, websiteUrl, contactLanguage,
useCaseDescription, additionalContacts, productionAccessEnabled);
}
public Optional<AccountVdmAttributes> findAccountVdmAttributes(String region) {
return accountService.findAccountVdmAttributes(region);
}
@@ -0,0 +1,26 @@
package io.github.hectorvent.floci.services.ses.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.List;
/**
* Account-level provisioning details, set by PutAccountDetails and surfaced under GetAccount's
* {@code Details}. Per region and present-when-set: GetAccount omits the block entirely until
* PutAccountDetails is called for the region.
*
* <p>{@code reviewStatus}/{@code caseId} back the AWS {@code ReviewDetails} sub-structure. AWS runs a
* real production-access review; Floci has no sandbox, so it reports a granted review.
*/
@RegisterForReflection
@JsonIgnoreProperties(ignoreUnknown = true)
public record AccountDetails(String mailType,
String websiteUrl,
String contactLanguage,
String useCaseDescription,
List<String> additionalContactEmailAddresses,
boolean productionAccessEnabled,
String reviewStatus,
String caseId) {
}