mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(ses): implement PutAccountVdmAttributes and return VdmAttributes from GetAccount (v2) (#2265)
* feat(ses): implement PutAccountVdmAttributes and return VdmAttributes from GetAccount (v2) Add the SES v2 PutAccountVdmAttributes action (PUT /v2/email/account/vdm) and surface the account's VDM settings in GetAccount under VdmAttributes. The settings (VdmEnabled, DashboardAttributes.EngagementMetrics, GuardianAttributes.OptimizedSharedDelivery — each an ENABLED/DISABLED FeatureStatus) are stored per region and round-trip through GetAccount. VDM is opt-in, so each flag defaults to DISABLED. An invalid FeatureStatus value is a BadRequestException, matching AWS; Floci stores the settings but does not run VDM analytics. * fix(ses): reject non-string FeatureStatus values in PutAccountVdmAttributes parseFeatureStatus coerced any JSON node via asText(), so a boolean or object VdmEnabled produced a misleading enum error instead of being rejected as a type mismatch. Guard on isTextual() before matching the ENABLED/DISABLED enum, consistent with the other SES v2 parsers. * fix(ses): match AWS GetAccount VdmAttributes shape GetAccount always emitted VdmAttributes with the nested Dashboard/Guardian objects. AWS instead omits VdmAttributes entirely until VDM has been configured for the region, and once present adds the Dashboard/Guardian sub-objects only while VdmEnabled is ENABLED. Return VdmAttributes only when the region has stored VDM state, and gate the nested objects on the stored VdmEnabled flag. * test(ses): record live-AWS confirmation that unconfigured VDM omits VdmAttributes eu-west-1 and ap-northeast-1 (never configured) omit the VdmAttributes key, while a configured-then-disabled region reports VdmEnabled DISABLED.
This commit is contained in:
1 parent
a985fa4640
commit
80d1dc732e
14 files changed
+468
-165
No files matched your search
@@ -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.RegionResolver;
|
||||
import io.github.hectorvent.floci.services.ses.model.AccountSuppressionAttributes;
|
||||
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.DashboardOptions;
|
||||
import io.github.hectorvent.floci.services.ses.model.GuardianOptions;
|
||||
@@ -1811,9 +1812,88 @@ public class SesController {
|
||||
reasons.add(r);
|
||||
}
|
||||
|
||||
// AWS only surfaces VdmAttributes once VDM has been configured for the region (an untouched
|
||||
// region omits the key entirely), and only adds the Dashboard/Guardian sub-attributes while
|
||||
// VdmEnabled is ENABLED.
|
||||
sesService.findAccountVdmAttributes(region).ifPresent(vdm -> {
|
||||
ObjectNode vdmAttrs = result.putObject("VdmAttributes");
|
||||
vdmAttrs.put("VdmEnabled", featureStatus(vdm.vdmEnabled()));
|
||||
if (vdm.vdmEnabled()) {
|
||||
vdmAttrs.putObject("DashboardAttributes")
|
||||
.put("EngagementMetrics", featureStatus(vdm.engagementMetrics()));
|
||||
vdmAttrs.putObject("GuardianAttributes")
|
||||
.put("OptimizedSharedDelivery", featureStatus(vdm.optimizedSharedDelivery()));
|
||||
}
|
||||
});
|
||||
|
||||
return Response.ok(result).build();
|
||||
}
|
||||
|
||||
private static String featureStatus(boolean enabled) {
|
||||
return enabled ? "ENABLED" : "DISABLED";
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/account/vdm")
|
||||
public Response putAccountVdmAttributes(@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 vdm = request.path("VdmAttributes");
|
||||
if (!vdm.isObject()) {
|
||||
throw new AwsException("BadRequestException", "VdmAttributes is required.", 400);
|
||||
}
|
||||
boolean vdmEnabled = parseFeatureStatus(vdm, "VdmEnabled",
|
||||
"vdmAttributes.vdmEnabled", true);
|
||||
boolean engagement = parseFeatureStatus(
|
||||
requireObjectOrAbsent(vdm, "DashboardAttributes"), "EngagementMetrics",
|
||||
"vdmAttributes.dashboardAttributes.engagementMetrics", false);
|
||||
boolean osd = parseFeatureStatus(
|
||||
requireObjectOrAbsent(vdm, "GuardianAttributes"), "OptimizedSharedDelivery",
|
||||
"vdmAttributes.guardianAttributes.optimizedSharedDelivery", false);
|
||||
sesService.putAccountVdmAttributes(region,
|
||||
new AccountVdmAttributes(vdmEnabled, engagement, osd));
|
||||
LOG.infov("SES V2 PutAccountVdmAttributes: enabled={0}, engagement={1}, osd={2}",
|
||||
vdmEnabled, engagement, osd);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// 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).
|
||||
private static boolean parseFeatureStatus(JsonNode parent, String field, String path, boolean required) {
|
||||
JsonNode node = parent.path(field);
|
||||
if (node.isMissingNode() || node.isNull()) {
|
||||
if (required) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"1 validation error detected: Value null at '" + path
|
||||
+ "' failed to satisfy constraint: Member must not be null", 400);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (node.isTextual()) {
|
||||
String value = node.asText();
|
||||
if ("ENABLED".equals(value)) {
|
||||
return true;
|
||||
}
|
||||
if ("DISABLED".equals(value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
throw new AwsException("BadRequestException",
|
||||
"1 validation error detected: Value at '" + path
|
||||
+ "' failed to satisfy constraint: Member must satisfy enum value set: [ENABLED, DISABLED]",
|
||||
400);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/account/suppression")
|
||||
public Response putAccountSuppressionAttributes(@Context HttpHeaders headers, String body) {
|
||||
|
||||
@@ -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.AccountVdmAttributes;
|
||||
import io.github.hectorvent.floci.services.ses.model.ArchivingOptions;
|
||||
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntry;
|
||||
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntryResult;
|
||||
@@ -89,6 +90,7 @@ public class SesService {
|
||||
private final StorageBackend<String, ConfigurationSet> configSetStore;
|
||||
private final StorageBackend<String, SuppressedDestination> suppressionStore;
|
||||
private final StorageBackend<String, AccountSuppressionAttributes> accountSuppressionStore;
|
||||
private final StorageBackend<String, AccountVdmAttributes> accountVdmStore;
|
||||
private final StorageBackend<String, DedicatedIpPool> dedicatedIpPoolStore;
|
||||
private final StorageBackend<String, ContactList> contactListStore;
|
||||
private final StorageBackend<String, Contact> contactStore;
|
||||
@@ -142,6 +144,8 @@ public class SesService {
|
||||
new TypeReference<Map<String, SuppressedDestination>>() {});
|
||||
this.accountSuppressionStore = storageFactory.create("ses", "ses-account-suppression.json",
|
||||
new TypeReference<Map<String, AccountSuppressionAttributes>>() {});
|
||||
this.accountVdmStore = storageFactory.create("ses", "ses-account-vdm.json",
|
||||
new TypeReference<Map<String, AccountVdmAttributes>>() {});
|
||||
this.dedicatedIpPoolStore = storageFactory.create("ses", "ses-dedicated-ip-pools.json",
|
||||
new TypeReference<Map<String, DedicatedIpPool>>() {});
|
||||
this.contactListStore = storageFactory.create("ses", "ses-contact-lists.json",
|
||||
@@ -170,6 +174,7 @@ public class SesService {
|
||||
StorageBackend<String, ConfigurationSet> configSetStore,
|
||||
StorageBackend<String, SuppressedDestination> suppressionStore,
|
||||
StorageBackend<String, AccountSuppressionAttributes> accountSuppressionStore,
|
||||
StorageBackend<String, AccountVdmAttributes> accountVdmStore,
|
||||
StorageBackend<String, DedicatedIpPool> dedicatedIpPoolStore,
|
||||
StorageBackend<String, ContactList> contactListStore,
|
||||
StorageBackend<String, Contact> contactStore,
|
||||
@@ -180,8 +185,8 @@ public class SesService {
|
||||
ObjectMapper objectMapper,
|
||||
Clock clock) {
|
||||
this(identityStore, emailStore, accountSettingsStore, templateStore, configSetStore, suppressionStore,
|
||||
accountSuppressionStore, dedicatedIpPoolStore, contactListStore, contactStore, policyStore,
|
||||
receiptRuleSetStore, cvetStore, smtpRelay, objectMapper, null, clock);
|
||||
accountSuppressionStore, accountVdmStore, dedicatedIpPoolStore, contactListStore, contactStore,
|
||||
policyStore, receiptRuleSetStore, cvetStore, smtpRelay, objectMapper, null, clock);
|
||||
}
|
||||
|
||||
SesService(StorageBackend<String, Identity> identityStore,
|
||||
@@ -191,6 +196,7 @@ public class SesService {
|
||||
StorageBackend<String, ConfigurationSet> configSetStore,
|
||||
StorageBackend<String, SuppressedDestination> suppressionStore,
|
||||
StorageBackend<String, AccountSuppressionAttributes> accountSuppressionStore,
|
||||
StorageBackend<String, AccountVdmAttributes> accountVdmStore,
|
||||
StorageBackend<String, DedicatedIpPool> dedicatedIpPoolStore,
|
||||
StorageBackend<String, ContactList> contactListStore,
|
||||
StorageBackend<String, Contact> contactStore,
|
||||
@@ -208,6 +214,7 @@ public class SesService {
|
||||
this.configSetStore = configSetStore;
|
||||
this.suppressionStore = suppressionStore;
|
||||
this.accountSuppressionStore = accountSuppressionStore;
|
||||
this.accountVdmStore = accountVdmStore;
|
||||
this.dedicatedIpPoolStore = dedicatedIpPoolStore;
|
||||
this.contactListStore = contactListStore;
|
||||
this.contactStore = contactStore;
|
||||
@@ -1009,6 +1016,23 @@ public class SesService {
|
||||
LOG.infov("Updated account sending enabled for region {0}: {1}", region, enabled);
|
||||
}
|
||||
|
||||
// VDM (Virtual Deliverability Manager) is opt-in and per region: GetAccount omits VdmAttributes
|
||||
// entirely until PutAccountVdmAttributes is called for the region, so this returns empty when the
|
||||
// region was never configured. The whole tuple is stored under one region key so GetAccount never
|
||||
// observes a partially updated state.
|
||||
public Optional<AccountVdmAttributes> findAccountVdmAttributes(String region) {
|
||||
return accountVdmStore.get(accountVdmKey(region));
|
||||
}
|
||||
|
||||
public void putAccountVdmAttributes(String region, AccountVdmAttributes vdm) {
|
||||
accountVdmStore.put(accountVdmKey(region), vdm);
|
||||
LOG.infov("Updated account VDM attributes for region {0}: enabled={1}", region, vdm.vdmEnabled());
|
||||
}
|
||||
|
||||
private static String accountVdmKey(String region) {
|
||||
return "account-vdm::" + region;
|
||||
}
|
||||
|
||||
public void setConfigurationSetSendingEnabled(String configSetName, boolean enabled, String region) {
|
||||
ConfigurationSet cs = getConfigurationSet(configSetName, region);
|
||||
cs.setSendingEnabled(enabled);
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package io.github.hectorvent.floci.services.ses.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
/**
|
||||
* Account-level Virtual Deliverability Manager (VDM) settings, returned by GetAccount and set by
|
||||
* PutAccountVdmAttributes. Each flag maps to the AWS {@code FeatureStatus} enum (ENABLED / DISABLED).
|
||||
*/
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record AccountVdmAttributes(boolean vdmEnabled,
|
||||
boolean engagementMetrics,
|
||||
boolean optimizedSharedDelivery) {
|
||||
}
|
||||
Reference in new issue
Block a user