Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

refactor(ses): split the suppression-list and tag endpoints out of SesController (#3786)

Kenshin Okinakaf83341e0130a
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
index 281c1b6a51..40b71fb2ed 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
@@ -38,6 +38,8 @@ 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.SesSuppressionController;
+import io.github.hectorvent.floci.services.ses.SesTagController;
import io.github.hectorvent.floci.services.ses.SesTemplateController;
import io.github.hectorvent.floci.services.appsync.AppSyncController;
import io.github.hectorvent.floci.services.rdsdata.RdsDataController;
@@ -293,7 +295,8 @@ public class ResolvedServiceCatalog {
Set.of(), Set.of("email", "ses", "sesv2"), Set.of(),
Set.of(SesController.class, SesAccountController.class,
SesContactController.class, SesCvetController.class,
- SesDedicatedIpController.class, SesTemplateController.class)),
+ SesDedicatedIpController.class, SesSuppressionController.class,
+ SesTagController.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,
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java
index 2f41748d0f..cca37b3c39 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java
@@ -15,7 +15,6 @@ import io.github.hectorvent.floci.services.ses.model.Identity;
import io.github.hectorvent.floci.services.ses.model.ListManagementOptions;
import io.github.hectorvent.floci.services.ses.model.MessageHeader;
import io.github.hectorvent.floci.services.ses.model.MessageTag;
-import io.github.hectorvent.floci.services.ses.model.SuppressedDestination;
import io.github.hectorvent.floci.services.ses.model.SuppressionOptions;
import io.github.hectorvent.floci.services.ses.model.Tag;
import io.github.hectorvent.floci.services.ses.model.Tenant;
@@ -35,7 +34,6 @@ import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;
@@ -53,7 +51,6 @@ import static io.github.hectorvent.floci.services.ses.SesV2Json.parseSendingEnab
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseSuppressedReasons;
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;
import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;
-import static io.github.hectorvent.floci.services.ses.SesV2Json.readRequiredStringField;
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireObjectOrAbsent;
@@ -1509,161 +1506,6 @@ public class SesController {
}
}
- // ──────────────────── Suppression list ───────────────────────────
-
- @PUT
- @Path("/suppression/addresses")
- public Response putSuppressedDestination(@Context HttpHeaders headers, String body) {
- String region = regionResolver.resolveRegion(headers);
- try {
- if (body == null || body.isBlank()) {
- throw new AwsException("BadRequestException", "Request body is required.", 400);
- }
- JsonNode request = objectMapper.readTree(body);
- requireJsonObject(request);
- String emailAddress = readRequiredStringField(request, "EmailAddress");
- String reason = readRequiredStringField(request, "Reason");
- String tenantName = stringMemberOrAbsent(request, "TenantName");
- sesService.putSuppressedDestination(region, emailAddress, reason, tenantName);
- LOG.infov("SES V2 PutSuppressedDestination: {0} ({1})", emailAddress, reason);
- 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("/suppression/addresses/{emailAddress}")
- public Response getSuppressedDestination(@Context HttpHeaders headers,
- @PathParam("emailAddress") String emailAddress,
- @QueryParam("TenantName") String tenantName) {
- String region = regionResolver.resolveRegion(headers);
- try {
- SuppressedDestination suppressed =
- sesService.getSuppressedDestination(region, emailAddress, tenantName);
- ObjectNode result = objectMapper.createObjectNode();
- ObjectNode entry = result.putObject("SuppressedDestination");
- entry.put("EmailAddress", suppressed.getEmailAddress());
- entry.put("Reason", suppressed.getReason());
- if (suppressed.getLastUpdateTime() != null) {
- entry.put("LastUpdateTime", suppressed.getLastUpdateTime().getEpochSecond());
- }
- // AWS renders TenantName on every entry — an explicit null for account-level ones.
- entry.put("TenantName", suppressed.getTenantName());
- return Response.ok(result).build();
- } catch (AwsException e) {
- throw remapV1Exception(e);
- }
- }
-
- @DELETE
- @Path("/suppression/addresses/{emailAddress}")
- public Response deleteSuppressedDestination(@Context HttpHeaders headers,
- @PathParam("emailAddress") String emailAddress,
- @QueryParam("TenantName") String tenantName) {
- String region = regionResolver.resolveRegion(headers);
- try {
- sesService.deleteSuppressedDestination(region, emailAddress, tenantName);
- LOG.infov("SES V2 DeleteSuppressedDestination: {0}", emailAddress);
- return Response.ok(objectMapper.createObjectNode()).build();
- } catch (AwsException e) {
- throw remapV1Exception(e);
- }
- }
-
- @GET
- @Path("/suppression/addresses")
- public Response listSuppressedDestinations(@Context HttpHeaders headers,
- @QueryParam("Reason") List<String> reasons,
- @QueryParam("TenantName") String tenantName) {
- String region = regionResolver.resolveRegion(headers);
- List<SuppressedDestination> entries;
- try {
- entries = sesService.listSuppressedDestinations(region, reasons, tenantName);
- } catch (AwsException e) {
- throw remapV1Exception(e);
- }
- ObjectNode result = objectMapper.createObjectNode();
- ArrayNode summaries = result.putArray("SuppressedDestinationSummaries");
- for (SuppressedDestination s : entries) {
- ObjectNode item = objectMapper.createObjectNode();
- item.put("EmailAddress", s.getEmailAddress());
- item.put("Reason", s.getReason());
- if (s.getLastUpdateTime() != null) {
- item.put("LastUpdateTime", s.getLastUpdateTime().getEpochSecond());
- }
- summaries.add(item);
- }
- return Response.ok(result).build();
- }
-
- // ──────────────────────────── Tags ───────────────────────────────
-
- @POST
- @Path("/tags")
- public Response tagResource(@Context HttpHeaders headers, String body) {
- String region = regionResolver.resolveRegion(headers);
- try {
- if (body == null || body.isBlank()) {
- throw new AwsException("BadRequestException", "Request body is required.", 400);
- }
- JsonNode request = objectMapper.readTree(body);
- String arn = request.path("ResourceArn").asText(null);
- if (arn == null || arn.isBlank()) {
- throw new AwsException("BadRequestException", "ResourceArn is required.", 400);
- }
- List<Tag> tags = parseTagsArray(request.path("Tags"));
- if (tags == null) {
- throw new AwsException("BadRequestException", "Tags must be an array.", 400);
- }
- sesService.tagResource(arn, region, tags);
- LOG.infov("SES V2 TagResource: {0}", arn);
- 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("/tags")
- public Response untagResource(@Context HttpHeaders headers,
- @QueryParam("ResourceArn") String arn,
- @QueryParam("TagKeys") List<String> tagKeys) {
- String region = regionResolver.resolveRegion(headers);
- try {
- sesService.untagResource(arn, region, tagKeys);
- LOG.infov("SES V2 UntagResource: {0}", arn);
- return Response.ok(objectMapper.createObjectNode()).build();
- } catch (AwsException e) {
- throw remapV1Exception(e);
- }
- }
-
- @GET
- @Path("/tags")
- public Response listTagsForResource(@Context HttpHeaders headers,
- @QueryParam("ResourceArn") String arn) {
- String region = regionResolver.resolveRegion(headers);
- try {
- List<Tag> tags = sesService.listResourceTags(arn, region);
- ObjectNode result = objectMapper.createObjectNode();
- ArrayNode arr = result.putArray("Tags");
- for (Tag t : tags) {
- ObjectNode tagNode = objectMapper.createObjectNode();
- tagNode.put("Key", t.key());
- tagNode.put("Value", t.value());
- arr.add(tagNode);
- }
- return Response.ok(result).build();
- } catch (AwsException e) {
- throw remapV1Exception(e);
- }
- }
-
// ──────────────────────────── Helpers ────────────────────────────
private ObjectNode buildFullIdentityResponse(Identity identity, String region) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesSuppressionController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesSuppressionController.java
new file mode 100644
index 0000000000..e6a313cc82
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesSuppressionController.java
@@ -0,0 +1,146 @@
+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.SuppressedDestination;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.DELETE;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.PUT;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.QueryParam;
+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.readRequiredStringField;
+import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
+import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;
+import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAbsent;
+
+/**
+ * SES V2 suppression-list endpoints ({@code /v2/email/suppression/addresses}), split out of
+ * {@link SesController}. Every operation keeps going through the {@link SesService} facade,
+ * because an optional {@code TenantName} routes it to that tenant's own list, which spans the
+ * suppression and tenant domains; the account-level suppression attributes live under
+ * {@code /account}.
+ */
+@Path("/v2/email")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class SesSuppressionController {
+
+ private static final Logger LOG = Logger.getLogger(SesSuppressionController.class);
+
+ private final SesService sesService;
+ private final RegionResolver regionResolver;
+ private final ObjectMapper objectMapper;
+
+ @Inject
+ public SesSuppressionController(SesService sesService, RegionResolver regionResolver,
+ ObjectMapper objectMapper) {
+ this.sesService = sesService;
+ this.regionResolver = regionResolver;
+ this.objectMapper = objectMapper;
+ }
+
+ @PUT
+ @Path("/suppression/addresses")
+ public Response putSuppressedDestination(@Context HttpHeaders headers, String body) {
+ String region = regionResolver.resolveRegion(headers);
+ try {
+ if (body == null || body.isBlank()) {
+ throw new AwsException("BadRequestException", "Request body is required.", 400);
+ }
+ JsonNode request = objectMapper.readTree(body);
+ requireJsonObject(request);
+ String emailAddress = readRequiredStringField(request, "EmailAddress");
+ String reason = readRequiredStringField(request, "Reason");
+ String tenantName = stringMemberOrAbsent(request, "TenantName");
+ sesService.putSuppressedDestination(region, emailAddress, reason, tenantName);
+ LOG.infov("SES V2 PutSuppressedDestination: {0} ({1})", emailAddress, reason);
+ return Response.ok(objectMapper.createObjectNode()).build();
+ } catch (AwsException e) {
+ throw remapV1Exception(e);
+ } catch (JsonProcessingException e) {
+ throw new AwsException("BadRequestException", e.getMessage(), 400);
+ }
+ }
+
+ @GET
+ @Path("/suppression/addresses/{emailAddress}")
+ public Response getSuppressedDestination(@Context HttpHeaders headers,
+ @PathParam("emailAddress") String emailAddress,
+ @QueryParam("TenantName") String tenantName) {
+ String region = regionResolver.resolveRegion(headers);
+ try {
+ SuppressedDestination suppressed =
+ sesService.getSuppressedDestination(region, emailAddress, tenantName);
+ ObjectNode result = objectMapper.createObjectNode();
+ ObjectNode entry = result.putObject("SuppressedDestination");
+ entry.put("EmailAddress", suppressed.getEmailAddress());
+ entry.put("Reason", suppressed.getReason());
+ if (suppressed.getLastUpdateTime() != null) {
+ entry.put("LastUpdateTime", suppressed.getLastUpdateTime().getEpochSecond());
+ }
+ // AWS renders TenantName on every entry: an explicit null for account-level ones.
+ entry.put("TenantName", suppressed.getTenantName());
+ return Response.ok(result).build();
+ } catch (AwsException e) {
+ throw remapV1Exception(e);
+ }
+ }
+
+ @DELETE
+ @Path("/suppression/addresses/{emailAddress}")
+ public Response deleteSuppressedDestination(@Context HttpHeaders headers,
+ @PathParam("emailAddress") String emailAddress,
+ @QueryParam("TenantName") String tenantName) {
+ String region = regionResolver.resolveRegion(headers);
+ try {
+ sesService.deleteSuppressedDestination(region, emailAddress, tenantName);
+ LOG.infov("SES V2 DeleteSuppressedDestination: {0}", emailAddress);
+ return Response.ok(objectMapper.createObjectNode()).build();
+ } catch (AwsException e) {
+ throw remapV1Exception(e);
+ }
+ }
+
+ @GET
+ @Path("/suppression/addresses")
+ public Response listSuppressedDestinations(@Context HttpHeaders headers,
+ @QueryParam("Reason") List<String> reasons,
+ @QueryParam("TenantName") String tenantName) {
+ String region = regionResolver.resolveRegion(headers);
+ List<SuppressedDestination> entries;
+ try {
+ entries = sesService.listSuppressedDestinations(region, reasons, tenantName);
+ } catch (AwsException e) {
+ throw remapV1Exception(e);
+ }
+ ObjectNode result = objectMapper.createObjectNode();
+ ArrayNode summaries = result.putArray("SuppressedDestinationSummaries");
+ for (SuppressedDestination s : entries) {
+ ObjectNode item = objectMapper.createObjectNode();
+ item.put("EmailAddress", s.getEmailAddress());
+ item.put("Reason", s.getReason());
+ if (s.getLastUpdateTime() != null) {
+ item.put("LastUpdateTime", s.getLastUpdateTime().getEpochSecond());
+ }
+ summaries.add(item);
+ }
+ return Response.ok(result).build();
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesTagController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesTagController.java
new file mode 100644
index 0000000000..4aa1ccc033
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesTagController.java
@@ -0,0 +1,118 @@
+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.Tag;
+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.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.QueryParam;
+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;
+
+/**
+ * SES V2 resource-tag endpoints ({@code /v2/email/tags}), split out of {@link SesController}.
+ * Every operation keeps going through the {@link SesService} facade, which parses the resource
+ * ARN and dispatches to whichever of the seven taggable domains owns it; that cross-domain
+ * dispatch is the facade's job by the survival rule, so this class is a pure size split like
+ * {@code LambdaTagController}.
+ */
+@Path("/v2/email")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class SesTagController {
+
+ private static final Logger LOG = Logger.getLogger(SesTagController.class);
+
+ private final SesService sesService;
+ private final RegionResolver regionResolver;
+ private final ObjectMapper objectMapper;
+
+ @Inject
+ public SesTagController(SesService sesService, RegionResolver regionResolver,
+ ObjectMapper objectMapper) {
+ this.sesService = sesService;
+ this.regionResolver = regionResolver;
+ this.objectMapper = objectMapper;
+ }
+
+ @POST
+ @Path("/tags")
+ public Response tagResource(@Context HttpHeaders headers, String body) {
+ String region = regionResolver.resolveRegion(headers);
+ try {
+ if (body == null || body.isBlank()) {
+ throw new AwsException("BadRequestException", "Request body is required.", 400);
+ }
+ JsonNode request = objectMapper.readTree(body);
+ String arn = request.path("ResourceArn").asText(null);
+ if (arn == null || arn.isBlank()) {
+ throw new AwsException("BadRequestException", "ResourceArn is required.", 400);
+ }
+ List<Tag> tags = parseTagsArray(request.path("Tags"));
+ if (tags == null) {
+ throw new AwsException("BadRequestException", "Tags must be an array.", 400);
+ }
+ sesService.tagResource(arn, region, tags);
+ LOG.infov("SES V2 TagResource: {0}", arn);
+ return Response.ok(objectMapper.createObjectNode()).build();
+ } catch (AwsException e) {
+ throw remapV1Exception(e);
+ } catch (JsonProcessingException e) {
+ throw new AwsException("BadRequestException", e.getMessage(), 400);
+ }
+ }
+
+ @DELETE
+ @Path("/tags")
+ public Response untagResource(@Context HttpHeaders headers,
+ @QueryParam("ResourceArn") String arn,
+ @QueryParam("TagKeys") List<String> tagKeys) {
+ String region = regionResolver.resolveRegion(headers);
+ try {
+ sesService.untagResource(arn, region, tagKeys);
+ LOG.infov("SES V2 UntagResource: {0}", arn);
+ return Response.ok(objectMapper.createObjectNode()).build();
+ } catch (AwsException e) {
+ throw remapV1Exception(e);
+ }
+ }
+
+ @GET
+ @Path("/tags")
+ public Response listTagsForResource(@Context HttpHeaders headers,
+ @QueryParam("ResourceArn") String arn) {
+ String region = regionResolver.resolveRegion(headers);
+ try {
+ List<Tag> tags = sesService.listResourceTags(arn, region);
+ ObjectNode result = objectMapper.createObjectNode();
+ ArrayNode arr = result.putArray("Tags");
+ for (Tag t : tags) {
+ ObjectNode tagNode = objectMapper.createObjectNode();
+ tagNode.put("Key", t.key());
+ tagNode.put("Value", t.value());
+ arr.add(tagNode);
+ }
+ return Response.ok(result).build();
+ } catch (AwsException e) {
+ throw remapV1Exception(e);
+ }
+ }
+}