mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
feat(ses): add ConfigurationSet CRUD on v1 Query and v2 REST JSON (#631)
* feat(ses): add ConfigurationSet CRUD on v1 Query and v2 REST JSON
Adds Configuration Set name management on both protocols:
- v1 Query: CreateConfigurationSet, DescribeConfigurationSet,
ListConfigurationSets, DeleteConfigurationSet
- v2 REST JSON: POST/GET (single)/GET (list)/DELETE under
/v2/email/configuration-sets[/{name}]
Storage is region-scoped and shared across both protocols, with name as
the primary key. Tags are persisted on v2 create and returned on v2 get;
v1 only round-trips the name (real SES v1 has no tags on configuration
sets). Errors map ConfigurationSetAlreadyExists / ConfigurationSetDoesNotExist
(v1) onto AlreadyExistsException 400 and NotFoundException 404 (v2)
via the existing SesController remap helper.
Field validation (per AWS limits): ConfigurationSetName must match
^[A-Za-z0-9_-]{1,64}$; each Tag Key is 1-128 chars and each Tag Value is
0-256 chars; non-array Tags are rejected with BadRequestException.
Out of scope (future PRs): SendingOptions / EventDestinations /
TrackingOptions / DeliveryOptions / ReputationOptions / SuppressionOptions /
VdmOptions, and ConfigurationSetName validation in the Send* APIs.
* fix(ses): allow Tag without Value on ConfigurationSet create
AWS SDKs commonly omit Tag.Value when only the key matters
(Tag.builder().key("env").build()), serialising the request without a
Value field. Floci was rejecting these calls with "Tag Value is
required", diverging from typical SDK and LocalStack behaviour. Drop
the required-value check; the 0-256 length constraint still applies
when a value is present.
This commit is contained in:
1 parent
e3368e014c
commit
cd42caa254
10 files changed
+995
-4
No files matched your search
@@ -279,7 +279,9 @@ public class AwsQueryController {
|
||||
"SetIdentityNotificationTopic", "GetIdentityNotificationAttributes",
|
||||
"GetIdentityDkimAttributes",
|
||||
"CreateTemplate", "UpdateTemplate", "GetTemplate", "DeleteTemplate",
|
||||
"ListTemplates", "SendTemplatedEmail"
|
||||
"ListTemplates", "SendTemplatedEmail",
|
||||
"CreateConfigurationSet", "DescribeConfigurationSet",
|
||||
"ListConfigurationSets", "DeleteConfigurationSet"
|
||||
);
|
||||
|
||||
private static final Set<String> COGNITO_ACTIONS = Set.of(
|
||||
|
||||
@@ -2,6 +2,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.ConfigurationSet;
|
||||
import io.github.hectorvent.floci.services.ses.model.EmailTemplate;
|
||||
import io.github.hectorvent.floci.services.ses.model.Identity;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
@@ -364,6 +365,92 @@ public class SesController {
|
||||
}
|
||||
}
|
||||
|
||||
// ──────────────────────── Configuration Sets ───────────────────────
|
||||
|
||||
@POST
|
||||
@Path("/configuration-sets")
|
||||
public Response createConfigurationSet(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
String name = request.path("ConfigurationSetName").asText(null);
|
||||
if (name == null || name.isBlank()) {
|
||||
throw new AwsException("BadRequestException", "ConfigurationSetName is required.", 400);
|
||||
}
|
||||
ConfigurationSet cs = new ConfigurationSet(name);
|
||||
JsonNode tags = request.get("Tags");
|
||||
if (tags != null && !tags.isNull()) {
|
||||
if (!tags.isArray()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"Tags must be an array.", 400);
|
||||
}
|
||||
List<ConfigurationSet.Tag> tagList = new ArrayList<>();
|
||||
for (JsonNode t : tags) {
|
||||
tagList.add(new ConfigurationSet.Tag(
|
||||
t.path("Key").asText(null),
|
||||
t.path("Value").asText(null)));
|
||||
}
|
||||
cs.setTags(tagList);
|
||||
}
|
||||
sesService.createConfigurationSet(cs, region);
|
||||
LOG.infov("SES V2 CreateConfigurationSet: {0}", name);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (Exception e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/configuration-sets")
|
||||
public Response listConfigurationSets(@Context HttpHeaders headers) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
List<ConfigurationSet> all = sesService.listConfigurationSets(region);
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
ArrayNode arr = result.putArray("ConfigurationSets");
|
||||
for (ConfigurationSet cs : all) {
|
||||
arr.add(cs.getName());
|
||||
}
|
||||
return Response.ok(result).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/configuration-sets/{configurationSetName}")
|
||||
public Response getConfigurationSet(@Context HttpHeaders headers,
|
||||
@PathParam("configurationSetName") String name) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
ConfigurationSet cs = sesService.getConfigurationSet(name, region);
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
result.put("ConfigurationSetName", cs.getName());
|
||||
ArrayNode tags = result.putArray("Tags");
|
||||
for (ConfigurationSet.Tag t : cs.getTags()) {
|
||||
ObjectNode tagNode = objectMapper.createObjectNode();
|
||||
tagNode.put("Key", t.key());
|
||||
tagNode.put("Value", t.value());
|
||||
tags.add(tagNode);
|
||||
}
|
||||
return Response.ok(result).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
}
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/configuration-sets/{configurationSetName}")
|
||||
public Response deleteConfigurationSet(@Context HttpHeaders headers,
|
||||
@PathParam("configurationSetName") String name) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
sesService.deleteConfigurationSet(name, region);
|
||||
LOG.infov("SES V2 DeleteConfigurationSet: {0}", name);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
}
|
||||
}
|
||||
|
||||
// ──────────────────────────── Account ────────────────────────────
|
||||
|
||||
@GET
|
||||
@@ -509,9 +596,9 @@ public class SesController {
|
||||
return switch (e.getErrorCode()) {
|
||||
case "InvalidParameterValue", "InvalidTemplate" ->
|
||||
new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
case "TemplateDoesNotExist" ->
|
||||
case "TemplateDoesNotExist", "ConfigurationSetDoesNotExist" ->
|
||||
new AwsException("NotFoundException", e.getMessage(), 404);
|
||||
case "AlreadyExists" ->
|
||||
case "AlreadyExists", "ConfigurationSetAlreadyExists" ->
|
||||
new AwsException("AlreadyExistsException", e.getMessage(), 400);
|
||||
default -> e;
|
||||
};
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsNamespaces;
|
||||
import io.github.hectorvent.floci.core.common.AwsQueryResponse;
|
||||
import io.github.hectorvent.floci.core.common.XmlBuilder;
|
||||
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.Identity;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
@@ -62,6 +63,10 @@ public class SesQueryHandler {
|
||||
case "DeleteTemplate" -> handleDeleteTemplate(params, region);
|
||||
case "ListTemplates" -> handleListTemplates(region);
|
||||
case "SendTemplatedEmail" -> handleSendTemplatedEmail(params, region);
|
||||
case "CreateConfigurationSet" -> handleCreateConfigurationSet(params, region);
|
||||
case "DescribeConfigurationSet" -> handleDescribeConfigurationSet(params, region);
|
||||
case "ListConfigurationSets" -> handleListConfigurationSets(region);
|
||||
case "DeleteConfigurationSet" -> handleDeleteConfigurationSet(params, region);
|
||||
default -> AwsQueryResponse.error("UnsupportedOperation",
|
||||
"Operation " + action + " is not supported by SES.", AwsNamespaces.SES, 400);
|
||||
};
|
||||
@@ -336,6 +341,48 @@ public class SesQueryHandler {
|
||||
return Response.ok(AwsQueryResponse.envelope("SendTemplatedEmail", AwsNamespaces.SES, result)).build();
|
||||
}
|
||||
|
||||
private Response handleCreateConfigurationSet(MultivaluedMap<String, String> params, String region) {
|
||||
String name = getParam(params, "ConfigurationSet.Name");
|
||||
if (name == null || name.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue", "ConfigurationSet.Name is required.", 400);
|
||||
}
|
||||
sesService.createConfigurationSet(new ConfigurationSet(name), region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult("CreateConfigurationSet", AwsNamespaces.SES)).build();
|
||||
}
|
||||
|
||||
private Response handleDescribeConfigurationSet(MultivaluedMap<String, String> params, String region) {
|
||||
String name = getParam(params, "ConfigurationSetName");
|
||||
if (name == null || name.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue", "ConfigurationSetName is required.", 400);
|
||||
}
|
||||
ConfigurationSet cs = sesService.getConfigurationSet(name, region);
|
||||
String result = new XmlBuilder()
|
||||
.start("ConfigurationSet")
|
||||
.elem("Name", cs.getName())
|
||||
.end("ConfigurationSet")
|
||||
.build();
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeConfigurationSet", AwsNamespaces.SES, result)).build();
|
||||
}
|
||||
|
||||
private Response handleListConfigurationSets(String region) {
|
||||
List<ConfigurationSet> all = sesService.listConfigurationSets(region);
|
||||
XmlBuilder xml = new XmlBuilder().start("ConfigurationSets");
|
||||
for (ConfigurationSet cs : all) {
|
||||
xml.start("member").elem("Name", cs.getName()).end("member");
|
||||
}
|
||||
xml.end("ConfigurationSets");
|
||||
return Response.ok(AwsQueryResponse.envelope("ListConfigurationSets", AwsNamespaces.SES, xml.build())).build();
|
||||
}
|
||||
|
||||
private Response handleDeleteConfigurationSet(MultivaluedMap<String, String> params, String region) {
|
||||
String name = getParam(params, "ConfigurationSetName");
|
||||
if (name == null || name.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue", "ConfigurationSetName is required.", 400);
|
||||
}
|
||||
sesService.deleteConfigurationSet(name, region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult("DeleteConfigurationSet", AwsNamespaces.SES)).build();
|
||||
}
|
||||
|
||||
private EmailTemplate readTemplateParams(MultivaluedMap<String, String> params) {
|
||||
String name = getParam(params, "Template.TemplateName");
|
||||
String subject = getParam(params, "Template.SubjectPart");
|
||||
|
||||
@@ -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.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
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.Identity;
|
||||
import io.github.hectorvent.floci.services.ses.model.SentEmail;
|
||||
@@ -33,6 +34,7 @@ public class SesService {
|
||||
private final StorageBackend<String, SentEmail> emailStore;
|
||||
private final StorageBackend<String, Boolean> accountSettingsStore;
|
||||
private final StorageBackend<String, EmailTemplate> templateStore;
|
||||
private final StorageBackend<String, ConfigurationSet> configSetStore;
|
||||
private final SmtpRelay smtpRelay;
|
||||
|
||||
@Inject
|
||||
@@ -45,6 +47,8 @@ public class SesService {
|
||||
new TypeReference<Map<String, Boolean>>() {});
|
||||
this.templateStore = storageFactory.create("ses", "ses-templates.json",
|
||||
new TypeReference<Map<String, EmailTemplate>>() {});
|
||||
this.configSetStore = storageFactory.create("ses", "ses-config-sets.json",
|
||||
new TypeReference<Map<String, ConfigurationSet>>() {});
|
||||
this.smtpRelay = smtpRelay;
|
||||
}
|
||||
|
||||
@@ -52,11 +56,13 @@ public class SesService {
|
||||
StorageBackend<String, SentEmail> emailStore,
|
||||
StorageBackend<String, Boolean> accountSettingsStore,
|
||||
StorageBackend<String, EmailTemplate> templateStore,
|
||||
StorageBackend<String, ConfigurationSet> configSetStore,
|
||||
SmtpRelay smtpRelay) {
|
||||
this.identityStore = identityStore;
|
||||
this.emailStore = emailStore;
|
||||
this.accountSettingsStore = accountSettingsStore;
|
||||
this.templateStore = templateStore;
|
||||
this.configSetStore = configSetStore;
|
||||
this.smtpRelay = smtpRelay;
|
||||
}
|
||||
|
||||
@@ -308,6 +314,93 @@ public class SesService {
|
||||
return all;
|
||||
}
|
||||
|
||||
public ConfigurationSet createConfigurationSet(ConfigurationSet configSet, String region) {
|
||||
if (configSet == null) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"ConfigurationSetName is required.", 400);
|
||||
}
|
||||
String key = configSetKey(region, configSet.getName());
|
||||
if (configSet.getTags() != null) {
|
||||
for (ConfigurationSet.Tag tag : configSet.getTags()) {
|
||||
validateTag(tag);
|
||||
}
|
||||
}
|
||||
if (configSetStore.get(key).isPresent()) {
|
||||
throw new AwsException("ConfigurationSetAlreadyExists",
|
||||
"Configuration set " + configSet.getName() + " already exists.", 400);
|
||||
}
|
||||
if (configSet.getCreatedTimestamp() == null) {
|
||||
configSet.setCreatedTimestamp(Instant.now());
|
||||
}
|
||||
configSetStore.put(key, configSet);
|
||||
LOG.infov("Created SES configuration set: {0} in region {1}", configSet.getName(), region);
|
||||
return configSet;
|
||||
}
|
||||
|
||||
public ConfigurationSet getConfigurationSet(String name, String region) {
|
||||
return configSetStore.get(configSetKey(region, name))
|
||||
.orElseThrow(() -> new AwsException("ConfigurationSetDoesNotExist",
|
||||
"Configuration set " + name + " does not exist.", 400));
|
||||
}
|
||||
|
||||
public List<ConfigurationSet> listConfigurationSets(String region) {
|
||||
String prefix = "configSet::" + region + "::";
|
||||
List<ConfigurationSet> all = new ArrayList<>(configSetStore.scan(k -> k.startsWith(prefix)));
|
||||
all.sort(Comparator.comparing(ConfigurationSet::getCreatedTimestamp,
|
||||
Comparator.nullsLast(Comparator.naturalOrder()))
|
||||
.thenComparing(ConfigurationSet::getName,
|
||||
Comparator.nullsLast(Comparator.naturalOrder())));
|
||||
return all;
|
||||
}
|
||||
|
||||
public void deleteConfigurationSet(String name, String region) {
|
||||
String key = configSetKey(region, name);
|
||||
if (configSetStore.get(key).isEmpty()) {
|
||||
throw new AwsException("ConfigurationSetDoesNotExist",
|
||||
"Configuration set " + name + " does not exist.", 400);
|
||||
}
|
||||
configSetStore.delete(key);
|
||||
LOG.infov("Deleted SES configuration set: {0} in region {1}", name, region);
|
||||
}
|
||||
|
||||
private static final Pattern CONFIG_SET_NAME = Pattern.compile("^[A-Za-z0-9_-]{1,64}$");
|
||||
|
||||
private static String configSetKey(String region, String name) {
|
||||
validateConfigurationSetName(name);
|
||||
return "configSet::" + region + "::" + name;
|
||||
}
|
||||
|
||||
static void validateConfigurationSetName(String name) {
|
||||
if (name == null || name.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"ConfigurationSetName is required.", 400);
|
||||
}
|
||||
if (!CONFIG_SET_NAME.matcher(name).matches()) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"ConfigurationSetName must be 1-64 characters and may only contain "
|
||||
+ "alphanumeric characters, underscores, and hyphens.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
static void validateTag(ConfigurationSet.Tag tag) {
|
||||
if (tag == null) {
|
||||
throw new AwsException("InvalidParameterValue", "Tag must not be null.", 400);
|
||||
}
|
||||
String key = tag.key();
|
||||
if (key == null || key.isEmpty()) {
|
||||
throw new AwsException("InvalidParameterValue", "Tag Key is required.", 400);
|
||||
}
|
||||
if (key.length() > 128) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Tag Key must be 1-128 characters.", 400);
|
||||
}
|
||||
String value = tag.value();
|
||||
if (value != null && value.length() > 256) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Tag Value must be 0-256 characters.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
public String sendTemplatedEmail(String source, List<String> toAddresses, List<String> ccAddresses,
|
||||
List<String> bccAddresses, List<String> replyToAddresses,
|
||||
String templateName, JsonNode templateData, String region) {
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package io.github.hectorvent.floci.services.ses.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class ConfigurationSet {
|
||||
|
||||
@JsonProperty("Name")
|
||||
private String name;
|
||||
|
||||
@JsonProperty("CreatedTimestamp")
|
||||
private Instant createdTimestamp;
|
||||
|
||||
@JsonProperty("Tags")
|
||||
private List<Tag> tags = new ArrayList<>();
|
||||
|
||||
public ConfigurationSet() {}
|
||||
|
||||
public ConfigurationSet(String name) {
|
||||
this.name = name;
|
||||
this.createdTimestamp = Instant.now();
|
||||
}
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public Instant getCreatedTimestamp() { return createdTimestamp; }
|
||||
public void setCreatedTimestamp(Instant createdTimestamp) { this.createdTimestamp = createdTimestamp; }
|
||||
|
||||
public List<Tag> getTags() { return tags; }
|
||||
public void setTags(List<Tag> tags) { this.tags = tags != null ? tags : new ArrayList<>(); }
|
||||
|
||||
@RegisterForReflection
|
||||
public record Tag(
|
||||
@JsonProperty("Key") String key,
|
||||
@JsonProperty("Value") String value) {
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user