refactor(ses): split the custom verification template endpoints into SesCvetController (#3735)

The five /v2/email/custom-verification-email-templates endpoints and
their two helpers move out of SesController into SesCvetController. Get,
list and delete call SesCvetService directly, and SesQueryHandler's v1
actions do the same; create and update stay on the SesService facade
because their validation checks the From address against the identity
domain. SesService drops the three pure delegations, and sending a
custom verification email stays with the send endpoints. The new class
is registered on the SES descriptor. No wire behavior changes.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-09-16 13:31:37 -04:00
1 parent 5de25631ac
commit a1419b9e69
5 files changed
+178 -120

No files matched your search

@@ -35,6 +35,7 @@ import io.github.hectorvent.floci.services.cloudfront.CloudFrontServingControlle
import io.github.hectorvent.floci.services.route53.Route53Controller;
import io.github.hectorvent.floci.services.ses.SesContactController;
import io.github.hectorvent.floci.services.ses.SesController;
import io.github.hectorvent.floci.services.ses.SesCvetController;
import io.github.hectorvent.floci.services.ses.SesDedicatedIpController;
import io.github.hectorvent.floci.services.ses.SesTemplateController;
import io.github.hectorvent.floci.services.appsync.AppSyncController;
@@ -290,7 +291,8 @@ public class ResolvedServiceCatalog {
protocols(ServiceProtocol.REST_JSON, ServiceProtocol.QUERY),
Set.of(), Set.of("email", "ses", "sesv2"), Set.of(),
Set.of(SesController.class, SesContactController.class,
SesDedicatedIpController.class, SesTemplateController.class)),
SesCvetController.class, SesDedicatedIpController.class,
SesTemplateController.class)),
descriptor("es", "opensearch", config.services().opensearch().enabled(), true,
"opensearch", storageMode(config.storage().services().opensearch().mode(), config.storage().mode()),
config.storage().services().opensearch().flushIntervalMs(), null, ServiceProtocol.REST_JSON,
@@ -10,7 +10,6 @@ import io.github.hectorvent.floci.services.ses.model.GuardianOptions;
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;
import io.github.hectorvent.floci.services.ses.model.CustomVerificationEmailTemplate;
import io.github.hectorvent.floci.services.ses.model.DeliveryOptions;
import io.github.hectorvent.floci.services.ses.model.EmailTemplate;
import io.github.hectorvent.floci.services.ses.model.EventDestination;
@@ -737,80 +736,6 @@ public class SesController {
// ──────────────── Custom verification email templates ────────────────
@POST
@Path("/custom-verification-email-templates")
public Response createCustomVerificationEmailTemplate(@Context HttpHeaders headers, String body) {
String region = regionResolver.resolveRegion(headers);
try {
JsonNode request = objectMapper.readTree(body);
CustomVerificationEmailTemplate t = parseCvet(request);
// Tags exist only on the create request; UpdateCustomVerificationEmailTemplate has no
// Tags member and preserves the stored ones.
t.setTags(parseTagsArray(request.path("Tags")));
sesService.createCustomVerificationEmailTemplate(t, region);
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);
}
}
@GET
@Path("/custom-verification-email-templates")
public Response listCustomVerificationEmailTemplates(@Context HttpHeaders headers) {
String region = regionResolver.resolveRegion(headers);
ObjectNode result = objectMapper.createObjectNode();
ArrayNode items = result.putArray("CustomVerificationEmailTemplates");
for (CustomVerificationEmailTemplate t : sesService.listCustomVerificationEmailTemplates(region)) {
items.add(cvetJson(t, false));
}
return Response.ok(result).build();
}
@GET
@Path("/custom-verification-email-templates/{templateName}")
public Response getCustomVerificationEmailTemplate(@Context HttpHeaders headers,
@PathParam("templateName") String templateName) {
String region = regionResolver.resolveRegion(headers);
try {
return Response.ok(
cvetJson(sesService.getCustomVerificationEmailTemplate(templateName, region), true)).build();
} catch (AwsException e) {
throw remapV1Exception(e);
}
}
@PUT
@Path("/custom-verification-email-templates/{templateName}")
public Response updateCustomVerificationEmailTemplate(@Context HttpHeaders headers,
@PathParam("templateName") String templateName, String body) {
String region = regionResolver.resolveRegion(headers);
try {
CustomVerificationEmailTemplate t = parseCvet(objectMapper.readTree(body));
t.setTemplateName(templateName);
sesService.updateCustomVerificationEmailTemplate(t, region);
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("/custom-verification-email-templates/{templateName}")
public Response deleteCustomVerificationEmailTemplate(@Context HttpHeaders headers,
@PathParam("templateName") String templateName) {
String region = regionResolver.resolveRegion(headers);
try {
sesService.deleteCustomVerificationEmailTemplate(templateName, region);
return Response.ok(objectMapper.createObjectNode()).build();
} catch (AwsException e) {
throw remapV1Exception(e);
}
}
@POST
@Path("/outbound-custom-verification-emails")
public Response sendCustomVerificationEmail(@Context HttpHeaders headers, String body) {
@@ -843,32 +768,6 @@ public class SesController {
}
}
private CustomVerificationEmailTemplate parseCvet(JsonNode request) {
requireJsonObject(request);
CustomVerificationEmailTemplate t = new CustomVerificationEmailTemplate();
t.setTemplateName(request.path("TemplateName").asText(null));
t.setFromEmailAddress(request.path("FromEmailAddress").asText(null));
t.setTemplateSubject(request.path("TemplateSubject").asText(null));
t.setTemplateContent(request.path("TemplateContent").asText(null));
t.setSuccessRedirectionURL(request.path("SuccessRedirectionURL").asText(null));
t.setFailureRedirectionURL(request.path("FailureRedirectionURL").asText(null));
return t;
}
// List omits TemplateContent (matches AWS); Get includes it.
private ObjectNode cvetJson(CustomVerificationEmailTemplate t, boolean includeContent) {
ObjectNode o = objectMapper.createObjectNode();
o.put("TemplateName", t.getTemplateName());
o.put("FromEmailAddress", t.getFromEmailAddress());
o.put("TemplateSubject", t.getTemplateSubject());
if (includeContent) {
o.put("TemplateContent", t.getTemplateContent());
}
o.put("SuccessRedirectionURL", t.getSuccessRedirectionURL());
o.put("FailureRedirectionURL", t.getFailureRedirectionURL());
return o;
}
// ──────────────────────────── Tenants (multi-tenancy) ────────────────────────────
// The SES v2 tenant operations use RPC-style POST subpaths (/tenants, /tenants/get, /tenants/list,
// /tenants/delete). The service owns id/ARN generation and name validation; the controller only
@@ -0,0 +1,163 @@
package io.github.hectorvent.floci.services.ses;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.services.ses.model.CustomVerificationEmailTemplate;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.jboss.logging.Logger;
import java.util.List;
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;
/**
* SES V2 custom verification email template endpoints
* ({@code /v2/email/custom-verification-email-templates}), split out of {@link SesController}.
* Get, list and delete call {@link SesCvetService} directly; create and update go through the
* {@link SesService} facade, which validates the template (including the From-address verified
* check against the identity domain) before the store write. Sending one of these templates stays
* with the send endpoints.
*/
@Path("/v2/email")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class SesCvetController {
private static final Logger LOG = Logger.getLogger(SesCvetController.class);
private final SesCvetService cvetService;
private final SesService sesService;
private final RegionResolver regionResolver;
private final ObjectMapper objectMapper;
@Inject
public SesCvetController(SesCvetService cvetService, SesService sesService,
RegionResolver regionResolver, ObjectMapper objectMapper) {
this.cvetService = cvetService;
this.sesService = sesService;
this.regionResolver = regionResolver;
this.objectMapper = objectMapper;
}
@POST
@Path("/custom-verification-email-templates")
public Response createCustomVerificationEmailTemplate(@Context HttpHeaders headers, String body) {
String region = regionResolver.resolveRegion(headers);
try {
JsonNode request = objectMapper.readTree(body);
CustomVerificationEmailTemplate t = parseCvet(request);
// Tags exist only on the create request; UpdateCustomVerificationEmailTemplate has no
// Tags member and preserves the stored ones.
t.setTags(parseTagsArray(request.path("Tags")));
sesService.createCustomVerificationEmailTemplate(t, region);
return Response.ok(objectMapper.createObjectNode()).build();
} catch (AwsException e) {
throw remapV1Exception(e);
} catch (JsonProcessingException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
}
}
@GET
@Path("/custom-verification-email-templates")
public Response listCustomVerificationEmailTemplates(@Context HttpHeaders headers) {
String region = regionResolver.resolveRegion(headers);
ObjectNode result = objectMapper.createObjectNode();
ArrayNode items = result.putArray("CustomVerificationEmailTemplates");
List<CustomVerificationEmailTemplate> templates =
cvetService.listCustomVerificationEmailTemplates(region);
for (CustomVerificationEmailTemplate t : templates) {
items.add(cvetJson(t, false));
}
return Response.ok(result).build();
}
@GET
@Path("/custom-verification-email-templates/{templateName}")
public Response getCustomVerificationEmailTemplate(@Context HttpHeaders headers,
@PathParam("templateName") String templateName) {
String region = regionResolver.resolveRegion(headers);
try {
return Response.ok(
cvetJson(cvetService.getCustomVerificationEmailTemplate(templateName, region),
true)).build();
} catch (AwsException e) {
throw remapV1Exception(e);
}
}
@PUT
@Path("/custom-verification-email-templates/{templateName}")
public Response updateCustomVerificationEmailTemplate(@Context HttpHeaders headers,
@PathParam("templateName") String templateName, String body) {
String region = regionResolver.resolveRegion(headers);
try {
CustomVerificationEmailTemplate t = parseCvet(objectMapper.readTree(body));
t.setTemplateName(templateName);
sesService.updateCustomVerificationEmailTemplate(t, region);
return Response.ok(objectMapper.createObjectNode()).build();
} catch (AwsException e) {
throw remapV1Exception(e);
} catch (JsonProcessingException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
}
}
@DELETE
@Path("/custom-verification-email-templates/{templateName}")
public Response deleteCustomVerificationEmailTemplate(@Context HttpHeaders headers,
@PathParam("templateName") String templateName) {
String region = regionResolver.resolveRegion(headers);
try {
cvetService.deleteCustomVerificationEmailTemplate(templateName, region);
return Response.ok(objectMapper.createObjectNode()).build();
} catch (AwsException e) {
throw remapV1Exception(e);
}
}
private CustomVerificationEmailTemplate parseCvet(JsonNode request) {
requireJsonObject(request);
CustomVerificationEmailTemplate t = new CustomVerificationEmailTemplate();
t.setTemplateName(request.path("TemplateName").asText(null));
t.setFromEmailAddress(request.path("FromEmailAddress").asText(null));
t.setTemplateSubject(request.path("TemplateSubject").asText(null));
t.setTemplateContent(request.path("TemplateContent").asText(null));
t.setSuccessRedirectionURL(request.path("SuccessRedirectionURL").asText(null));
t.setFailureRedirectionURL(request.path("FailureRedirectionURL").asText(null));
return t;
}
// List omits TemplateContent (matches AWS); Get includes it.
private ObjectNode cvetJson(CustomVerificationEmailTemplate t, boolean includeContent) {
ObjectNode o = objectMapper.createObjectNode();
o.put("TemplateName", t.getTemplateName());
o.put("FromEmailAddress", t.getFromEmailAddress());
o.put("TemplateSubject", t.getTemplateSubject());
if (includeContent) {
o.put("TemplateContent", t.getTemplateContent());
}
o.put("SuccessRedirectionURL", t.getSuccessRedirectionURL());
o.put("FailureRedirectionURL", t.getFailureRedirectionURL());
return o;
}
}
@@ -48,16 +48,18 @@ public class SesQueryHandler {
private final SesReceiptRuleService receiptRuleService;
private final SesIdentityService identityService;
private final SesTemplateService templateService;
private final SesCvetService cvetService;
private final ObjectMapper objectMapper;
@Inject
public SesQueryHandler(SesService sesService, SesReceiptRuleService receiptRuleService,
SesIdentityService identityService, SesTemplateService templateService,
ObjectMapper objectMapper) {
SesCvetService cvetService, ObjectMapper objectMapper) {
this.sesService = sesService;
this.receiptRuleService = receiptRuleService;
this.identityService = identityService;
this.templateService = templateService;
this.cvetService = cvetService;
this.objectMapper = objectMapper;
}
@@ -621,7 +623,7 @@ public class SesQueryHandler {
}
private Response handleGetCustomVerificationEmailTemplate(MultivaluedMap<String, String> params, String region) {
CustomVerificationEmailTemplate t = sesService.getCustomVerificationEmailTemplate(
CustomVerificationEmailTemplate t = cvetService.getCustomVerificationEmailTemplate(
requireParam(params, "TemplateName"), region);
String xml = new XmlBuilder()
.elem("TemplateName", t.getTemplateName())
@@ -637,7 +639,9 @@ public class SesQueryHandler {
private Response handleListCustomVerificationEmailTemplates(String region) {
XmlBuilder xml = new XmlBuilder().start("CustomVerificationEmailTemplates");
for (CustomVerificationEmailTemplate t : sesService.listCustomVerificationEmailTemplates(region)) {
List<CustomVerificationEmailTemplate> templates =
cvetService.listCustomVerificationEmailTemplates(region);
for (CustomVerificationEmailTemplate t : templates) {
xml.start("member")
.elem("TemplateName", t.getTemplateName())
.elem("FromEmailAddress", t.getFromEmailAddress())
@@ -652,7 +656,8 @@ public class SesQueryHandler {
}
private Response handleDeleteCustomVerificationEmailTemplate(MultivaluedMap<String, String> params, String region) {
sesService.deleteCustomVerificationEmailTemplate(requireParam(params, "TemplateName"), region);
cvetService.deleteCustomVerificationEmailTemplate(requireParam(params, "TemplateName"),
region);
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
"DeleteCustomVerificationEmailTemplate", AwsNamespaces.SES)).build();
}
@@ -89,8 +89,9 @@ public class SesService {
// Identity (sending authorization) policy storage, extracted to SesPolicyService.
// The facade keeps the identity-existence check and delegates the rest.
private final SesPolicyService policyService;
// Custom verification email templates: storage extracted to SesCvetService. The
// facade keeps the identity-dependent validation and the send path; the service owns the store.
// Custom verification email templates: storage extracted to SesCvetService, which the v2
// controller and the v1 handler call directly for get/list/delete. The facade keeps create and
// update for the identity-dependent validation, plus the send path and the tag dispatch.
private final SesCvetService cvetService;
// Tenants (multi-tenancy) live in SesTenantService. The facade delegates.
private final SesTenantService tenantService;
@@ -727,14 +728,6 @@ public class SesService {
cvetService.createCustomVerificationEmailTemplate(template, region);
}
public CustomVerificationEmailTemplate getCustomVerificationEmailTemplate(String templateName, String region) {
return cvetService.getCustomVerificationEmailTemplate(templateName, region);
}
public List<CustomVerificationEmailTemplate> listCustomVerificationEmailTemplates(String region) {
return cvetService.listCustomVerificationEmailTemplates(region);
}
public void updateCustomVerificationEmailTemplate(CustomVerificationEmailTemplate template, String region) {
// Validate (including the From-verified identity check and the required-field checks) before
// delegating the storage update, matching createCustomVerificationEmailTemplate.
@@ -742,10 +735,6 @@ public class SesService {
cvetService.updateCustomVerificationEmailTemplate(template, region);
}
public void deleteCustomVerificationEmailTemplate(String templateName, String region) {
cvetService.deleteCustomVerificationEmailTemplate(templateName, region);
}
// AWS appends this exact disclaimer to the end of every custom verification email and it cannot
// be removed (SES docs Q10).
private static final String CUSTOM_VERIFICATION_DISCLAIMER =