feat(ses): support V1 ConfigurationSetEventDestination CRUD (#1111)

V2 SES already exposes ConfigurationSet event-destination CRUD via
REST JSON; this PR adds the matching V1 Query actions
(CreateConfigurationSetEventDestination /
UpdateConfigurationSetEventDestination /
DeleteConfigurationSetEventDestination) and extends
DescribeConfigurationSet so V1 callers can round-trip their stored
destinations. The service layer (`SesService.createConfigurationSetEventDestination`
etc.) already had the persistence and validation logic, so most of the
work is wire-format: parse V1 Query parameter shapes, render V1 XML
responses, and route the new action names.

- SesQueryHandler: three new Query actions plus
  `readEventDestination(params, prefix)` and `writeEventDestination`
  helpers. V1 wire field names use uppercase `ARN` / `NS` suffix
  variants (`SNSDestination.TopicARN`,
  `KinesisFirehoseDestination.IAMRoleARN` / `DeliveryStreamARN`,
  `CloudWatchDestination.DimensionConfigurations.member.N`) which are
  mapped onto the existing model classes; the `EventDestination.Enabled`
  default mirrors the V2 primitive-boolean default of `false` when
  omitted.
- V1 event-type wire forms are lowercase camelCase (`send`,
  `complaint`, `renderingFailure`) while floci stores the V2 canonical
  form (SCREAMING_SNAKE). New `V1_EVENT_TYPE_TO_INTERNAL` /
  `INTERNAL_EVENT_TYPE_TO_V1` maps translate in both directions; unknown
  values pass through so the existing validate-against-VALID_EVENT_TYPES
  check still catches typos.
- `handleDescribeConfigurationSet`: when
  `ConfigurationSetAttributeNames.member.N=eventDestinations` is
  requested, render the stored event destinations as a V1 XML block.
  Treat a null `ConfigurationSet.eventDestinations` list as empty when
  rendering, so a corrupted persisted JSON with `"EventDestinations": null`
  still produces an empty `<EventDestinations/>` container rather than
  NPE-ing. Other ConfigurationSet attribute names (trackingOptions,
  deliveryOptions, reputationOptions) remain unsupported and are
  silently ignored — they will land with their respective Put*Options
  PRs. The container is emitted even when the destination list is
  empty so the response depends only on the requested attributes.
- `writeEventDestination`: skip destination blocks when required fields
  are blank (defensive belt-and-suspenders for any legacy state) and
  filter incomplete CloudWatch dimension members so partial members
  don't leak into the XML.
- `SesService.validateEventDestination`: centralize required-field
  validation for SNS / Firehose / CloudWatch dimensions, so both V1
  and V2 reject partial destinations at create/update time. Members
  with missing required fields now fail with a 400
  `InvalidParameterValue` carrying the offending member index.
- `AwsQueryController.SES_ACTIONS`: include the three new actions in
  the action-name → "email" service routing fallback so SigV4 requests
  whose credential scope doesn't pin the service still reach SES.

Tests
- `SesConfigurationSetEventDestinationV1IntegrationTest`: 15 cases
  covering create / describe-with-attribute / describe-without-attribute
  / describe-empty-attribute / duplicate / update / update-unknown /
  delete / delete-unknown / partial Firehose / partial CloudWatch dim
  / blank SNS TopicARN / action-name routing fallback when the
  Authorization header is absent.
- `SesServiceEventDestinationTest`: 8 new unit cases for the
  centralized SNS / Firehose / CloudWatch dim validation, exercising
  validateEventDestination directly.
- `compatibility-tests/sdk-test-java SesConfigurationSetEventDestinationTest`:
  extended to drive both V1 (SesClient) and V2 (SesV2Client) against a
  live Floci. Each protocol gets its own config set; nine new V1 tests
  mirror the V2 lifecycle plus partial-Firehose rejection.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-06-02 00:14:53 -05:00
1 parent 35211adc4a
commit 2c9e0bce7c
6 files changed
+921 -50

No files matched your search

@@ -332,7 +332,10 @@ public class AwsQueryController {
"ListTemplates", "SendTemplatedEmail", "SendBulkTemplatedEmail",
"TestRenderTemplate",
"CreateConfigurationSet", "DescribeConfigurationSet",
"ListConfigurationSets", "DeleteConfigurationSet"
"ListConfigurationSets", "DeleteConfigurationSet",
"CreateConfigurationSetEventDestination",
"UpdateConfigurationSetEventDestination",
"DeleteConfigurationSetEventDestination"
);
private static final Set<String> COGNITO_ACTIONS = Set.of(
@@ -6,10 +6,15 @@ import io.github.hectorvent.floci.core.common.AwsQueryResponse;
import io.github.hectorvent.floci.core.common.XmlBuilder;
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.CloudWatchDestination;
import io.github.hectorvent.floci.services.ses.model.CloudWatchDimensionConfiguration;
import io.github.hectorvent.floci.services.ses.model.ConfigurationSet;
import io.github.hectorvent.floci.services.ses.model.EmailTemplate;
import io.github.hectorvent.floci.services.ses.model.EventDestination;
import io.github.hectorvent.floci.services.ses.model.Identity;
import io.github.hectorvent.floci.services.ses.model.KinesisFirehoseDestination;
import io.github.hectorvent.floci.services.ses.model.MessageTag;
import io.github.hectorvent.floci.services.ses.model.SnsDestination;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.enterprise.context.ApplicationScoped;
@@ -77,6 +82,12 @@ public class SesQueryHandler {
case "DescribeConfigurationSet" -> handleDescribeConfigurationSet(params, region);
case "ListConfigurationSets" -> handleListConfigurationSets(region);
case "DeleteConfigurationSet" -> handleDeleteConfigurationSet(params, region);
case "CreateConfigurationSetEventDestination" ->
handleCreateConfigurationSetEventDestination(params, region);
case "UpdateConfigurationSetEventDestination" ->
handleUpdateConfigurationSetEventDestination(params, region);
case "DeleteConfigurationSetEventDestination" ->
handleDeleteConfigurationSetEventDestination(params, region);
default -> AwsQueryResponse.error("UnsupportedOperation",
"Operation " + action + " is not supported by SES.", AwsNamespaces.SES, 400);
};
@@ -545,12 +556,84 @@ public class SesQueryHandler {
throw new AwsException("InvalidParameterValue", "ConfigurationSetName is required.", 400);
}
ConfigurationSet cs = sesService.getConfigurationSet(name, region);
String result = new XmlBuilder()
List<String> attrs = extractMembers(params, "ConfigurationSetAttributeNames");
XmlBuilder xml = new XmlBuilder()
.start("ConfigurationSet")
.elem("Name", cs.getName())
.end("ConfigurationSet")
.build();
return Response.ok(AwsQueryResponse.envelope("DescribeConfigurationSet", AwsNamespaces.SES, result)).build();
.end("ConfigurationSet");
if (attrs.contains("eventDestinations")) {
xml.start("EventDestinations");
List<EventDestination> destinations = cs.getEventDestinations();
if (destinations != null) {
for (EventDestination ed : destinations) {
xml.start("member");
writeEventDestination(xml, ed);
xml.end("member");
}
}
xml.end("EventDestinations");
}
return Response.ok(AwsQueryResponse.envelope("DescribeConfigurationSet",
AwsNamespaces.SES, xml.build())).build();
}
/**
* Render an {@link EventDestination} into the V1 SES XML shape. V1 wire names use the
* uppercase {@code ARN}/{@code NS} suffix variants (e.g., {@code SNSDestination},
* {@code TopicARN}, {@code IAMRoleARN}, {@code DeliveryStreamARN}). Skips destination
* blocks for which no configuration is present.
*/
private static void writeEventDestination(XmlBuilder xml, EventDestination ed) {
xml.elem("Name", ed.getName())
.elem("Enabled", String.valueOf(ed.isEnabled()));
xml.start("MatchingEventTypes");
if (ed.getMatchingEventTypes() != null) {
for (String t : ed.getMatchingEventTypes()) {
xml.elem("member", INTERNAL_EVENT_TYPE_TO_V1.getOrDefault(t, t));
}
}
xml.end("MatchingEventTypes");
if (ed.getSnsDestination() != null
&& ed.getSnsDestination().getTopicArn() != null
&& !ed.getSnsDestination().getTopicArn().isBlank()) {
xml.start("SNSDestination")
.elem("TopicARN", ed.getSnsDestination().getTopicArn())
.end("SNSDestination");
}
if (ed.getKinesisFirehoseDestination() != null
&& ed.getKinesisFirehoseDestination().getIamRoleArn() != null
&& !ed.getKinesisFirehoseDestination().getIamRoleArn().isBlank()
&& ed.getKinesisFirehoseDestination().getDeliveryStreamArn() != null
&& !ed.getKinesisFirehoseDestination().getDeliveryStreamArn().isBlank()) {
xml.start("KinesisFirehoseDestination")
.elem("IAMRoleARN", ed.getKinesisFirehoseDestination().getIamRoleArn())
.elem("DeliveryStreamARN", ed.getKinesisFirehoseDestination().getDeliveryStreamArn())
.end("KinesisFirehoseDestination");
}
if (ed.getCloudWatchDestination() != null
&& ed.getCloudWatchDestination().getDimensionConfigurations() != null) {
List<CloudWatchDimensionConfiguration> validDims = new ArrayList<>();
for (CloudWatchDimensionConfiguration dim
: ed.getCloudWatchDestination().getDimensionConfigurations()) {
if (dim != null
&& dim.getDimensionName() != null && !dim.getDimensionName().isBlank()
&& dim.getDimensionValueSource() != null && !dim.getDimensionValueSource().isBlank()
&& dim.getDefaultDimensionValue() != null && !dim.getDefaultDimensionValue().isBlank()) {
validDims.add(dim);
}
}
if (!validDims.isEmpty()) {
xml.start("CloudWatchDestination").start("DimensionConfigurations");
for (CloudWatchDimensionConfiguration dim : validDims) {
xml.start("member")
.elem("DimensionName", dim.getDimensionName())
.elem("DimensionValueSource", dim.getDimensionValueSource())
.elem("DefaultDimensionValue", dim.getDefaultDimensionValue())
.end("member");
}
xml.end("DimensionConfigurations").end("CloudWatchDestination");
}
}
}
private Response handleListConfigurationSets(String region) {
@@ -572,6 +655,131 @@ public class SesQueryHandler {
return Response.ok(AwsQueryResponse.envelopeEmptyResult("DeleteConfigurationSet", AwsNamespaces.SES)).build();
}
private Response handleCreateConfigurationSetEventDestination(MultivaluedMap<String, String> params,
String region) {
String configSet = requireParam(params, "ConfigurationSetName");
String edName = requireParam(params, "EventDestination.Name");
EventDestination dest = readEventDestination(params, "EventDestination");
sesService.createConfigurationSetEventDestination(configSet, edName, dest, region);
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
"CreateConfigurationSetEventDestination", AwsNamespaces.SES)).build();
}
private Response handleUpdateConfigurationSetEventDestination(MultivaluedMap<String, String> params,
String region) {
String configSet = requireParam(params, "ConfigurationSetName");
String edName = requireParam(params, "EventDestination.Name");
EventDestination dest = readEventDestination(params, "EventDestination");
sesService.updateConfigurationSetEventDestination(configSet, edName, dest, region);
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
"UpdateConfigurationSetEventDestination", AwsNamespaces.SES)).build();
}
private Response handleDeleteConfigurationSetEventDestination(MultivaluedMap<String, String> params,
String region) {
String configSet = requireParam(params, "ConfigurationSetName");
String edName = requireParam(params, "EventDestinationName");
sesService.deleteConfigurationSetEventDestination(configSet, edName, region);
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
"DeleteConfigurationSetEventDestination", AwsNamespaces.SES)).build();
}
/**
* AWS V1 SES uses lowercased event-type names on the wire (e.g. {@code send},
* {@code complaint}, {@code renderingFailure}) while V2 uses
* {@code SCREAMING_SNAKE_CASE} (e.g. {@code SEND}, {@code RENDERING_FAILURE}).
* Floci stores the V2 canonical form internally, so the V1 handler translates
* in both directions.
*/
private static final java.util.Map<String, String> V1_EVENT_TYPE_TO_INTERNAL =
java.util.Map.ofEntries(
java.util.Map.entry("send", "SEND"),
java.util.Map.entry("reject", "REJECT"),
java.util.Map.entry("bounce", "BOUNCE"),
java.util.Map.entry("complaint", "COMPLAINT"),
java.util.Map.entry("delivery", "DELIVERY"),
java.util.Map.entry("open", "OPEN"),
java.util.Map.entry("click", "CLICK"),
java.util.Map.entry("renderingFailure", "RENDERING_FAILURE"),
java.util.Map.entry("deliveryDelay", "DELIVERY_DELAY"),
java.util.Map.entry("subscription", "SUBSCRIPTION"));
private static final java.util.Map<String, String> INTERNAL_EVENT_TYPE_TO_V1;
static {
java.util.Map<String, String> reverse = new java.util.HashMap<>();
for (var e : V1_EVENT_TYPE_TO_INTERNAL.entrySet()) {
reverse.put(e.getValue(), e.getKey());
}
INTERNAL_EVENT_TYPE_TO_V1 = java.util.Map.copyOf(reverse);
}
/**
* Parse a V1 SES Query {@code EventDestination.*} parameter group into an
* {@link EventDestination}. V1 wire names use uppercase {@code ARN} / {@code NS}
* suffixes ({@code SNSDestination.TopicARN}, {@code KinesisFirehoseDestination.IAMRoleARN}
* / {@code DeliveryStreamARN}) which are mapped onto the model's Title-cased fields,
* and the lowercase event-type wire forms are normalized to the V2 canonical form
* via {@link #V1_EVENT_TYPE_TO_INTERNAL}.
*/
private EventDestination readEventDestination(MultivaluedMap<String, String> params, String prefix) {
EventDestination dest = new EventDestination();
dest.setName(getParam(params, prefix + ".Name"));
dest.setEnabled(parseOptionalBoolean(params, prefix + ".Enabled", false));
List<String> rawTypes = extractMembers(params, prefix + ".MatchingEventTypes");
List<String> normalizedTypes = new ArrayList<>(rawTypes.size());
for (String t : rawTypes) {
normalizedTypes.add(V1_EVENT_TYPE_TO_INTERNAL.getOrDefault(t, t));
}
dest.setMatchingEventTypes(normalizedTypes);
String topicArn = getParam(params, prefix + ".SNSDestination.TopicARN");
if (topicArn != null) {
SnsDestination sns = new SnsDestination();
sns.setTopicArn(topicArn);
dest.setSnsDestination(sns);
}
String firehoseIam = getParam(params, prefix + ".KinesisFirehoseDestination.IAMRoleARN");
String firehoseStream = getParam(params, prefix + ".KinesisFirehoseDestination.DeliveryStreamARN");
if (firehoseIam != null || firehoseStream != null) {
KinesisFirehoseDestination fh = new KinesisFirehoseDestination();
fh.setIamRoleArn(firehoseIam);
fh.setDeliveryStreamArn(firehoseStream);
dest.setKinesisFirehoseDestination(fh);
}
List<CloudWatchDimensionConfiguration> cwDims = new ArrayList<>();
for (int i = 1; ; i++) {
String dimPrefix = prefix + ".CloudWatchDestination.DimensionConfigurations.member." + i;
String name = getParam(params, dimPrefix + ".DimensionName");
String source = getParam(params, dimPrefix + ".DimensionValueSource");
String def = getParam(params, dimPrefix + ".DefaultDimensionValue");
if (name == null && source == null && def == null) {
break;
}
CloudWatchDimensionConfiguration dim = new CloudWatchDimensionConfiguration();
dim.setDimensionName(name);
dim.setDimensionValueSource(source);
dim.setDefaultDimensionValue(def);
cwDims.add(dim);
}
if (!cwDims.isEmpty()) {
CloudWatchDestination cw = new CloudWatchDestination();
cw.setDimensionConfigurations(cwDims);
dest.setCloudWatchDestination(cw);
}
return dest;
}
private static String requireParam(MultivaluedMap<String, String> params, String name) {
String v = params.getFirst(name);
if (v == null || v.isBlank()) {
throw new AwsException("InvalidParameterValue", name + " is required.", 400);
}
return v;
}
private EmailTemplate readTemplateParams(MultivaluedMap<String, String> params) {
String name = getParam(params, "Template.TemplateName");
String subject = getParam(params, "Template.SubjectPart");
@@ -8,6 +8,7 @@ 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.CloudWatchDimensionConfiguration;
import io.github.hectorvent.floci.services.ses.model.ConfigurationSet;
import io.github.hectorvent.floci.services.ses.model.EmailTemplate;
import io.github.hectorvent.floci.services.ses.model.EventDestination;
@@ -732,11 +733,42 @@ public class SesService {
"Please provide only one destination with each request. Either a Firehose Destination "
+ "or a Cloudwatch Destination or an SNS Destination or an EventBridge Destination.", 400);
}
if (dest.getCloudWatchDestination() != null
&& (dest.getCloudWatchDestination().getDimensionConfigurations() == null
|| dest.getCloudWatchDestination().getDimensionConfigurations().isEmpty())) {
if (dest.getSnsDestination() != null
&& (dest.getSnsDestination().getTopicArn() == null
|| dest.getSnsDestination().getTopicArn().isBlank())) {
throw new AwsException("InvalidParameterValue",
"CloudWatch metrics dimension configuration list cannot be empty.", 400);
"SnsDestination requires a non-blank TopicArn.", 400);
}
if (dest.getKinesisFirehoseDestination() != null
&& (dest.getKinesisFirehoseDestination().getIamRoleArn() == null
|| dest.getKinesisFirehoseDestination().getIamRoleArn().isBlank()
|| dest.getKinesisFirehoseDestination().getDeliveryStreamArn() == null
|| dest.getKinesisFirehoseDestination().getDeliveryStreamArn().isBlank())) {
throw new AwsException("InvalidParameterValue",
"KinesisFirehoseDestination requires both IamRoleArn and DeliveryStreamArn.",
400);
}
if (dest.getCloudWatchDestination() != null) {
List<CloudWatchDimensionConfiguration> dims =
dest.getCloudWatchDestination().getDimensionConfigurations();
if (dims == null || dims.isEmpty()) {
throw new AwsException("InvalidParameterValue",
"CloudWatch metrics dimension configuration list cannot be empty.", 400);
}
for (int i = 0; i < dims.size(); i++) {
CloudWatchDimensionConfiguration dim = dims.get(i);
if (dim == null
|| dim.getDimensionName() == null || dim.getDimensionName().isBlank()
|| dim.getDimensionValueSource() == null
|| dim.getDimensionValueSource().isBlank()
|| dim.getDefaultDimensionValue() == null
|| dim.getDefaultDimensionValue().isBlank()) {
throw new AwsException("InvalidParameterValue",
"CloudWatchDestination dimension configurations require "
+ "DimensionName, DimensionValueSource, and DefaultDimensionValue "
+ "(missing on member " + (i + 1) + ").", 400);
}
}
}
if (dest.getPinpointDestination() != null
&& (dest.getPinpointDestination().getApplicationArn() == null