mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 14:30:28 -05:00
feat(ses): per-configuration-set sending toggle (v1 + v2) (#1193)
Add UpdateConfigurationSetSendingEnabled (SES v1 Query) and
PutConfigurationSetSendingOptions (SES v2 REST, PUT
/v2/email/configuration-sets/{name}/sending) to toggle email sending
on a single configuration set, complementing the existing
account-level UpdateAccountSendingEnabled / PutAccountSendingAttributes
toggle. The two APIs share state: both write
`ConfigurationSet.sendingEnabled` (Boolean, null/true = enabled).
Enforcement is centralized in SesService.validateConfigurationSet,
which is called by SendEmail, SendRawEmail, and SendBulkTemplatedEmail
(v1 and v2 paths). When the CS's sendingEnabled is false, the send is
rejected with SendingPausedException + "Sending is paused for
configuration set <name>" — matching the exact wire shape AWS returns
in production (verified via `aws sesv2 send-email` against an AWS
account with a disabled CS; both ErrorCode and Message reproduce as-is).
Read-back paths:
- v2 GetConfigurationSet returns SendingOptions: {SendingEnabled}
- v1 DescribeConfigurationSet with `reputationOptions` attribute
returns ReputationOptions/SendingEnabled (matches the AWS v1 wire
contract where SendingEnabled lives under ReputationOptions)
The v1 action is also added to AwsQueryController.SES_ACTIONS so that
action-name-based service routing recognizes it.
Tests
- SesConfigurationSetSendingOptionsV2IntegrationTest (13 cases): toggle
via both APIs, cross-API state sharing, SendEmail rejection with
SendingPausedException when disabled, read-back via Get/Describe,
bad-request validation, unknown CS returns 404 via v2.
- SesConfigurationSetSendingTest (SDK compat, 9 cases): AWS Java SDK
v2 marshalling of both APIs, with sendEmail rejection asserted as
`SendingPausedException` (the AWS SDK class corresponding to the
matched server-side error code).
Docs
- docs/services/ses.md: list both APIs in their respective tables.
This commit is contained in:
1 parent
70acf49b00
commit
e36576c2a4
8 files changed
+564
-10
No files matched your search
@@ -335,7 +335,8 @@ public class AwsQueryController {
|
||||
"ListConfigurationSets", "DeleteConfigurationSet",
|
||||
"CreateConfigurationSetEventDestination",
|
||||
"UpdateConfigurationSetEventDestination",
|
||||
"DeleteConfigurationSetEventDestination"
|
||||
"DeleteConfigurationSetEventDestination",
|
||||
"UpdateConfigurationSetSendingEnabled"
|
||||
);
|
||||
|
||||
private static final Set<String> COGNITO_ACTIONS = Set.of(
|
||||
|
||||
@@ -655,6 +655,8 @@ public class SesController {
|
||||
reasons.add(r);
|
||||
}
|
||||
}
|
||||
ObjectNode sendingNode = result.putObject("SendingOptions");
|
||||
sendingNode.put("SendingEnabled", cs.isSendingEnabledEffective());
|
||||
return Response.ok(result).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
@@ -697,6 +699,33 @@ public class SesController {
|
||||
}
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/configuration-sets/{configurationSetName}/sending")
|
||||
public Response putConfigurationSetSendingOptions(@Context HttpHeaders headers,
|
||||
@PathParam("configurationSetName") String name,
|
||||
String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode enabledNode = request.path("SendingEnabled");
|
||||
if (enabledNode.isMissingNode() || enabledNode.isNull() || !enabledNode.isBoolean()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"SendingEnabled must be present and must be a boolean.", 400);
|
||||
}
|
||||
sesService.setConfigurationSetSendingEnabled(name, enabledNode.booleanValue(), region);
|
||||
LOG.infov("SES V2 PutConfigurationSetSendingOptions: {0} on {1}",
|
||||
enabledNode.booleanValue(), name);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/configuration-sets/{configurationSetName}")
|
||||
public Response deleteConfigurationSet(@Context HttpHeaders headers,
|
||||
@@ -1310,6 +1339,8 @@ public class SesController {
|
||||
new AwsException("NotFoundException", e.getMessage(), 404);
|
||||
case "AlreadyExists", "ConfigurationSetAlreadyExists" ->
|
||||
new AwsException("AlreadyExistsException", e.getMessage(), 400);
|
||||
case "ConfigurationSetSendingPausedException" ->
|
||||
new AwsException("SendingPausedException", e.getMessage(), 400);
|
||||
default -> e;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -88,6 +88,8 @@ public class SesQueryHandler {
|
||||
handleUpdateConfigurationSetEventDestination(params, region);
|
||||
case "DeleteConfigurationSetEventDestination" ->
|
||||
handleDeleteConfigurationSetEventDestination(params, region);
|
||||
case "UpdateConfigurationSetSendingEnabled" ->
|
||||
handleUpdateConfigurationSetSendingEnabled(params, region);
|
||||
default -> AwsQueryResponse.error("UnsupportedOperation",
|
||||
"Operation " + action + " is not supported by SES.", AwsNamespaces.SES, 400);
|
||||
};
|
||||
@@ -573,6 +575,11 @@ public class SesQueryHandler {
|
||||
}
|
||||
xml.end("EventDestinations");
|
||||
}
|
||||
if (attrs.contains("reputationOptions")) {
|
||||
xml.start("ReputationOptions")
|
||||
.elem("SendingEnabled", String.valueOf(cs.isSendingEnabledEffective()))
|
||||
.end("ReputationOptions");
|
||||
}
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeConfigurationSet",
|
||||
AwsNamespaces.SES, xml.build())).build();
|
||||
}
|
||||
@@ -684,6 +691,15 @@ public class SesQueryHandler {
|
||||
"DeleteConfigurationSetEventDestination", AwsNamespaces.SES)).build();
|
||||
}
|
||||
|
||||
private Response handleUpdateConfigurationSetSendingEnabled(MultivaluedMap<String, String> params,
|
||||
String region) {
|
||||
String configSet = requireParam(params, "ConfigurationSetName");
|
||||
boolean enabled = parseRequiredBoolean(params, "Enabled");
|
||||
sesService.setConfigurationSetSendingEnabled(configSet, enabled, region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
|
||||
"UpdateConfigurationSetSendingEnabled", 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
|
||||
|
||||
@@ -285,20 +285,30 @@ public class SesService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that a non-blank {@code ConfigurationSetName} refers to a configuration set
|
||||
* that exists in the given region. Always raises {@code ConfigurationSetDoesNotExist}
|
||||
* with {@code httpStatus = 400}; the V2 REST controller's {@code remapV1Exception}
|
||||
* then translates that into a {@code NotFoundException 404}, while V1 Query keeps the
|
||||
* original code/status. Mirrors AWS SES behaviour: invalid set name fails fast instead
|
||||
* of silently storing/relaying the message and skipping event publishing later.
|
||||
* Validate that a non-blank {@code ConfigurationSetName} is usable for a send. Performs
|
||||
* two gates:
|
||||
* 1. Existence — raises {@code ConfigurationSetDoesNotExist} (400) when the set is
|
||||
* missing in the given region. The V2 REST controller's {@code remapV1Exception}
|
||||
* translates that into {@code NotFoundException 404}; V1 Query keeps the original.
|
||||
* 2. Sending-enabled — raises {@code ConfigurationSetSendingPausedException} (400)
|
||||
* when the set's {@code SendingEnabled} flag has been turned off via
|
||||
* {@code UpdateConfigurationSetSendingEnabled} (v1) /
|
||||
* {@code PutConfigurationSetSendingOptions} (v2). The V2 controller narrows that
|
||||
* code to {@code SendingPausedException}; V1 keeps the longer form, matching the
|
||||
* exact wire shape AWS returns on each surface.
|
||||
* Mirrors AWS SES behaviour: invalid or paused set fails fast instead of silently
|
||||
* storing/relaying the message and skipping event publishing later.
|
||||
*/
|
||||
private void validateConfigurationSet(String configurationSetName, String region) {
|
||||
if (configurationSetName == null || configurationSetName.isBlank()) {
|
||||
return;
|
||||
}
|
||||
if (configSetStore.get(configSetKey(region, configurationSetName)).isEmpty()) {
|
||||
throw new AwsException("ConfigurationSetDoesNotExist",
|
||||
"Configuration set <" + configurationSetName + "> does not exist.", 400);
|
||||
ConfigurationSet cs = configSetStore.get(configSetKey(region, configurationSetName))
|
||||
.orElseThrow(() -> new AwsException("ConfigurationSetDoesNotExist",
|
||||
"Configuration set <" + configurationSetName + "> does not exist.", 400));
|
||||
if (cs.getSendingEnabled() != null && !cs.getSendingEnabled()) {
|
||||
throw new AwsException("ConfigurationSetSendingPausedException",
|
||||
"Sending is paused for configuration set " + configurationSetName, 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,6 +544,14 @@ public class SesService {
|
||||
LOG.infov("Updated account sending enabled for region {0}: {1}", region, enabled);
|
||||
}
|
||||
|
||||
public void setConfigurationSetSendingEnabled(String configSetName, boolean enabled, String region) {
|
||||
ConfigurationSet cs = getConfigurationSet(configSetName, region);
|
||||
cs.setSendingEnabled(enabled);
|
||||
configSetStore.put(configSetKey(region, configSetName), cs);
|
||||
LOG.infov("Updated SendingEnabled on configuration set {0} in region {1}: {2}",
|
||||
configSetName, region, enabled);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Templates ────────────────────────────
|
||||
|
||||
public EmailTemplate createTemplate(EmailTemplate template, String region) {
|
||||
|
||||
@@ -27,6 +27,9 @@ public class ConfigurationSet {
|
||||
@JsonProperty("SuppressionOptions")
|
||||
private SuppressionOptions suppressionOptions;
|
||||
|
||||
@JsonProperty("SendingEnabled")
|
||||
private Boolean sendingEnabled;
|
||||
|
||||
public ConfigurationSet() {}
|
||||
|
||||
public ConfigurationSet(String name) {
|
||||
@@ -52,4 +55,19 @@ public class ConfigurationSet {
|
||||
public void setSuppressionOptions(SuppressionOptions suppressionOptions) {
|
||||
this.suppressionOptions = suppressionOptions;
|
||||
}
|
||||
|
||||
public Boolean getSendingEnabled() { return sendingEnabled; }
|
||||
public void setSendingEnabled(Boolean sendingEnabled) { this.sendingEnabled = sendingEnabled; }
|
||||
|
||||
/**
|
||||
* Effective sending-enabled flag with the AWS default applied — an unset
|
||||
* (null) field is treated as enabled, matching the AWS behaviour where a
|
||||
* configuration set without an explicit {@code SendingEnabled} state is
|
||||
* implicitly enabled. Use this anywhere v1/v2 read or enforce the toggle
|
||||
* so the default rule stays consistent across surfaces.
|
||||
*/
|
||||
@com.fasterxml.jackson.annotation.JsonIgnore
|
||||
public boolean isSendingEnabledEffective() {
|
||||
return sendingEnabled == null || sendingEnabled;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user