mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(ses): extend tag endpoints to contact lists, custom verification email templates, and dedicated IP pools (#2589)
* feat(ses): extend tag endpoints to contact lists, custom verification email templates, and dedicated IP pools * feat(ses): accept inline Tags on v2 CreateCustomVerificationEmailTemplate * fix(ses): match probed AWS behavior for empty Tags/TagKeys and avoid tag-list aliasing * docs(ses): describe the actual ValidationException wire body
This commit is contained in:
1 parent
f912c3b717
commit
c7cd78e3b3
15 files changed
+1171
-112
No files matched your search
@@ -105,6 +105,48 @@ public class SesContactService {
|
||||
.orElseThrow(() -> contactListNotFound(name));
|
||||
}
|
||||
|
||||
public List<Tag> listTags(String name, String region) {
|
||||
ContactList list = contactListStore.get(contactListKey(region, name))
|
||||
.orElseThrow(() -> tagTargetNotFound(name));
|
||||
return new ArrayList<>(list.getTags());
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the incoming tags into the stored list. The lookup and write share the mutation lock
|
||||
* used by deletion, so tagging can't resurrect a concurrently deleted list or overwrite a
|
||||
* concurrent mutation with a stale object.
|
||||
*/
|
||||
public void tag(String name, String region, List<Tag> newTags) {
|
||||
String key = contactListKey(region, name);
|
||||
synchronized (contactMutationLock) {
|
||||
ContactList list = contactListStore.get(key).orElseThrow(() -> tagTargetNotFound(name));
|
||||
list.setTags(SesTags.merge(list.getTags(), newTags));
|
||||
contactListStore.put(key, list);
|
||||
}
|
||||
LOG.infov("Tagged SES contact list: {0} in region {1} (+{2} tags)", name, region, newTags.size());
|
||||
}
|
||||
|
||||
public void untag(String name, String region, List<String> tagKeys) {
|
||||
String key = contactListKey(region, name);
|
||||
synchronized (contactMutationLock) {
|
||||
ContactList list = contactListStore.get(key).orElseThrow(() -> tagTargetNotFound(name));
|
||||
Set<String> toRemove = new HashSet<>(tagKeys);
|
||||
// Copy-on-write: the stored list may be immutable, and unlocked readers iterate it.
|
||||
List<Tag> remaining = new ArrayList<>(list.getTags());
|
||||
remaining.removeIf(t -> toRemove.contains(t.key()));
|
||||
list.setTags(remaining);
|
||||
contactListStore.put(key, list);
|
||||
}
|
||||
LOG.infov("Untagged SES contact list: {0} in region {1} (-{2} keys)", name, region, tagKeys.size());
|
||||
}
|
||||
|
||||
private static AwsException tagTargetNotFound(String name) {
|
||||
// The tag endpoints use AWS's "No ContactList present with name" wording
|
||||
// (probe-confirmed), unlike the CRUD "List with name: X doesn't exist."
|
||||
return new AwsException("NotFoundException",
|
||||
"No ContactList present with name: " + name, 404);
|
||||
}
|
||||
|
||||
public List<ContactList> listContactLists(String region) {
|
||||
String prefix = "contactList::" + region + "::";
|
||||
return contactListStore.scan(k -> k.startsWith(prefix)).stream()
|
||||
|
||||
@@ -722,7 +722,11 @@ public class SesController {
|
||||
public Response createCustomVerificationEmailTemplate(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
CustomVerificationEmailTemplate t = parseCvet(objectMapper.readTree(body));
|
||||
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) {
|
||||
@@ -1468,7 +1472,8 @@ public class SesController {
|
||||
} else {
|
||||
scalingMode = scalingNode.asText();
|
||||
}
|
||||
sesService.createDedicatedIpPool(poolName, scalingMode, region);
|
||||
List<Tag> tags = parseTagsArray(request.path("Tags"));
|
||||
sesService.createDedicatedIpPool(poolName, scalingMode, tags, region);
|
||||
LOG.infov("SES V2 CreateDedicatedIpPool: {0}", poolName);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
@@ -1495,7 +1500,11 @@ public class SesController {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
DedicatedIpPool pool = sesService.getDedicatedIpPool(poolName, region);
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
result.set("DedicatedIpPool", objectMapper.valueToTree(pool));
|
||||
// Built explicitly: the AWS DedicatedIpPool shape carries only PoolName and ScalingMode;
|
||||
// the model's tags are exposed via ListTagsForResource, not here.
|
||||
ObjectNode poolNode = result.putObject("DedicatedIpPool");
|
||||
poolNode.put("PoolName", pool.getPoolName());
|
||||
poolNode.put("ScalingMode", pool.getScalingMode());
|
||||
return Response.ok(result).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,14 +5,18 @@ 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.CustomVerificationEmailTemplate;
|
||||
import io.github.hectorvent.floci.services.ses.model.Tag;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Storage for custom verification email templates (the {@code cvetStore}), extracted from
|
||||
@@ -47,6 +51,7 @@ public class SesCvetService {
|
||||
}
|
||||
|
||||
public void createCustomVerificationEmailTemplate(CustomVerificationEmailTemplate template, String region) {
|
||||
SesTags.validate(template.getTags());
|
||||
String key = cvetKey(region, template.getTemplateName());
|
||||
// Lock only the check-then-put so concurrent creates for the same name can't both observe
|
||||
// the key as absent; the facade's validation and this logging stay outside the lock.
|
||||
@@ -80,9 +85,11 @@ public class SesCvetService {
|
||||
// Guard the existence check and the put together so a concurrent delete can't slip between
|
||||
// them and have the update resurrect the just-deleted template.
|
||||
synchronized (cvetMutationLock) {
|
||||
if (cvetStore.get(key).isEmpty()) {
|
||||
throw cvetNotFound(template.getTemplateName());
|
||||
}
|
||||
CustomVerificationEmailTemplate existing = cvetStore.get(key)
|
||||
.orElseThrow(() -> cvetNotFound(template.getTemplateName()));
|
||||
// The update request has no Tags member — preserve the stored ones (copied, so the
|
||||
// two objects never share a list instance).
|
||||
template.setTags(new ArrayList<>(existing.getTags()));
|
||||
cvetStore.put(key, template);
|
||||
}
|
||||
LOG.infov("Updated custom verification email template {0} in region {1}",
|
||||
@@ -110,6 +117,52 @@ public class SesCvetService {
|
||||
return cvetStore.get(cvetKey(region, templateName));
|
||||
}
|
||||
|
||||
public List<Tag> listTags(String templateName, String region) {
|
||||
CustomVerificationEmailTemplate template = cvetStore.get(cvetKey(region, templateName))
|
||||
.orElseThrow(() -> tagTargetNotFound(templateName));
|
||||
return new ArrayList<>(template.getTags());
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the incoming tags into the stored template. The lookup and write share the mutation
|
||||
* lock so a concurrent update can't be overwritten with a stale object and a concurrent delete
|
||||
* can't be resurrected.
|
||||
*/
|
||||
public void tag(String templateName, String region, List<Tag> newTags) {
|
||||
String key = cvetKey(region, templateName);
|
||||
synchronized (cvetMutationLock) {
|
||||
CustomVerificationEmailTemplate template = cvetStore.get(key)
|
||||
.orElseThrow(() -> tagTargetNotFound(templateName));
|
||||
template.setTags(SesTags.merge(template.getTags(), newTags));
|
||||
cvetStore.put(key, template);
|
||||
}
|
||||
LOG.infov("Tagged custom verification email template {0} in region {1} (+{2} tags)",
|
||||
templateName, region, newTags.size());
|
||||
}
|
||||
|
||||
public void untag(String templateName, String region, List<String> tagKeys) {
|
||||
String key = cvetKey(region, templateName);
|
||||
synchronized (cvetMutationLock) {
|
||||
CustomVerificationEmailTemplate template = cvetStore.get(key)
|
||||
.orElseThrow(() -> tagTargetNotFound(templateName));
|
||||
Set<String> toRemove = new HashSet<>(tagKeys);
|
||||
// Copy-on-write: the stored list may be immutable, and unlocked readers iterate it.
|
||||
List<Tag> remaining = new ArrayList<>(template.getTags());
|
||||
remaining.removeIf(t -> toRemove.contains(t.key()));
|
||||
template.setTags(remaining);
|
||||
cvetStore.put(key, template);
|
||||
}
|
||||
LOG.infov("Untagged custom verification email template {0} in region {1} (-{2} keys)",
|
||||
templateName, region, tagKeys.size());
|
||||
}
|
||||
|
||||
private static AwsException tagTargetNotFound(String templateName) {
|
||||
// The v2 tag endpoints use AWS's "No CustomVerificationEmailTemplate present with name"
|
||||
// wording (probe-confirmed), not the v1-native CRUD message above.
|
||||
return new AwsException("NotFoundException",
|
||||
"No CustomVerificationEmailTemplate present with name: " + templateName, 404);
|
||||
}
|
||||
|
||||
private static AwsException cvetNotFound(String templateName) {
|
||||
// v1-native code (verified: CustomVerificationEmailTemplateDoesNotExist / 400).
|
||||
// SesController.remapV1Exception translates it to NotFoundException / 404 for the v2 boundary.
|
||||
|
||||
@@ -5,10 +5,13 @@ 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.DedicatedIpPool;
|
||||
import io.github.hectorvent.floci.services.ses.model.Tag;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -27,6 +30,9 @@ public class SesDedicatedIpService {
|
||||
private static final Set<String> SCALING_MODES = Set.of("STANDARD", "MANAGED");
|
||||
|
||||
private final StorageBackend<String, DedicatedIpPool> dedicatedIpPoolStore;
|
||||
// Serializes pool check-then-write mutations (create/delete/tag) so concurrent creates for the
|
||||
// same name can't both succeed and tagging can't resurrect a concurrently deleted pool.
|
||||
private final Object poolMutationLock = new Object();
|
||||
|
||||
@Inject
|
||||
public SesDedicatedIpService(StorageFactory storageFactory) {
|
||||
@@ -38,7 +44,8 @@ public class SesDedicatedIpService {
|
||||
this.dedicatedIpPoolStore = dedicatedIpPoolStore;
|
||||
}
|
||||
|
||||
public DedicatedIpPool createDedicatedIpPool(String poolName, String scalingMode, String region) {
|
||||
public DedicatedIpPool createDedicatedIpPool(String poolName, String scalingMode, List<Tag> tags,
|
||||
String region) {
|
||||
if (poolName == null || poolName.isBlank()) {
|
||||
throw new AwsException("BadRequestException", "PoolName is required.", 400);
|
||||
}
|
||||
@@ -46,13 +53,17 @@ public class SesDedicatedIpService {
|
||||
if (!SCALING_MODES.contains(effectiveScaling)) {
|
||||
throw new AwsException("BadRequestException", "The ScalingMode parameter is invalid.", 400);
|
||||
}
|
||||
SesTags.validate(tags);
|
||||
String key = dedicatedIpPoolKey(region, poolName);
|
||||
if (dedicatedIpPoolStore.get(key).isPresent()) {
|
||||
throw new AwsException("AlreadyExistsException",
|
||||
"The pool <" + poolName + "> already exists.", 400);
|
||||
}
|
||||
DedicatedIpPool pool = new DedicatedIpPool(poolName, effectiveScaling);
|
||||
dedicatedIpPoolStore.put(key, pool);
|
||||
pool.setTags(tags);
|
||||
synchronized (poolMutationLock) {
|
||||
if (dedicatedIpPoolStore.get(key).isPresent()) {
|
||||
throw new AwsException("AlreadyExistsException",
|
||||
"The pool <" + poolName + "> already exists.", 400);
|
||||
}
|
||||
dedicatedIpPoolStore.put(key, pool);
|
||||
}
|
||||
LOG.infov("Created SES dedicated IP pool: {0} in region {1}", poolName, region);
|
||||
return pool;
|
||||
}
|
||||
@@ -77,14 +88,59 @@ public class SesDedicatedIpService {
|
||||
|
||||
public void deleteDedicatedIpPool(String poolName, String region) {
|
||||
String key = dedicatedIpPoolKey(region, poolName);
|
||||
if (dedicatedIpPoolStore.get(key).isEmpty()) {
|
||||
throw new AwsException("NotFoundException",
|
||||
"The requested pool <" + poolName + "> does not exist.", 404);
|
||||
synchronized (poolMutationLock) {
|
||||
if (dedicatedIpPoolStore.get(key).isEmpty()) {
|
||||
throw new AwsException("NotFoundException",
|
||||
"The requested pool <" + poolName + "> does not exist.", 404);
|
||||
}
|
||||
dedicatedIpPoolStore.delete(key);
|
||||
}
|
||||
dedicatedIpPoolStore.delete(key);
|
||||
LOG.infov("Deleted SES dedicated IP pool: {0} in region {1}", poolName, region);
|
||||
}
|
||||
|
||||
public List<Tag> listTags(String poolName, String region) {
|
||||
DedicatedIpPool pool = dedicatedIpPoolStore.get(dedicatedIpPoolKey(region, poolName))
|
||||
.orElseThrow(() -> tagTargetNotFound(poolName));
|
||||
return new ArrayList<>(pool.getTags());
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the incoming tags into the stored pool. The lookup and write share the mutation lock
|
||||
* so tagging can't resurrect a concurrently deleted pool or lose a concurrent tag update.
|
||||
*/
|
||||
public void tag(String poolName, String region, List<Tag> newTags) {
|
||||
String key = dedicatedIpPoolKey(region, poolName);
|
||||
synchronized (poolMutationLock) {
|
||||
DedicatedIpPool pool = dedicatedIpPoolStore.get(key)
|
||||
.orElseThrow(() -> tagTargetNotFound(poolName));
|
||||
pool.setTags(SesTags.merge(pool.getTags(), newTags));
|
||||
dedicatedIpPoolStore.put(key, pool);
|
||||
}
|
||||
LOG.infov("Tagged SES dedicated IP pool: {0} in region {1} (+{2} tags)", poolName, region, newTags.size());
|
||||
}
|
||||
|
||||
public void untag(String poolName, String region, List<String> tagKeys) {
|
||||
String key = dedicatedIpPoolKey(region, poolName);
|
||||
synchronized (poolMutationLock) {
|
||||
DedicatedIpPool pool = dedicatedIpPoolStore.get(key)
|
||||
.orElseThrow(() -> tagTargetNotFound(poolName));
|
||||
Set<String> toRemove = new HashSet<>(tagKeys);
|
||||
// Copy-on-write: the stored list may be immutable, and unlocked readers iterate it.
|
||||
List<Tag> remaining = new ArrayList<>(pool.getTags());
|
||||
remaining.removeIf(t -> toRemove.contains(t.key()));
|
||||
pool.setTags(remaining);
|
||||
dedicatedIpPoolStore.put(key, pool);
|
||||
}
|
||||
LOG.infov("Untagged SES dedicated IP pool: {0} in region {1} (-{2} keys)", poolName, region, tagKeys.size());
|
||||
}
|
||||
|
||||
private static AwsException tagTargetNotFound(String poolName) {
|
||||
// The tag endpoints use AWS's "No DedicatedIpPool present with name" wording
|
||||
// (probe-confirmed), unlike the CRUD "The requested pool <X> does not exist."
|
||||
return new AwsException("NotFoundException",
|
||||
"No DedicatedIpPool present with name: " + poolName, 404);
|
||||
}
|
||||
|
||||
private static String dedicatedIpPoolKey(String region, String name) {
|
||||
return "dedicatedIpPool::" + region + "::" + name;
|
||||
}
|
||||
|
||||
@@ -1671,8 +1671,9 @@ public class SesService {
|
||||
|
||||
// Storage lives in SesDedicatedIpService; the facade forwards.
|
||||
|
||||
public DedicatedIpPool createDedicatedIpPool(String poolName, String scalingMode, String region) {
|
||||
return dedicatedIpService.createDedicatedIpPool(poolName, scalingMode, region);
|
||||
public DedicatedIpPool createDedicatedIpPool(String poolName, String scalingMode, List<Tag> tags,
|
||||
String region) {
|
||||
return dedicatedIpService.createDedicatedIpPool(poolName, scalingMode, tags, region);
|
||||
}
|
||||
|
||||
public DedicatedIpPool getDedicatedIpPool(String poolName, String region) {
|
||||
@@ -2040,33 +2041,44 @@ public class SesService {
|
||||
|
||||
public List<Tag> listResourceTags(String arn, String region) {
|
||||
ResourceRef ref = parseSesArn(arn);
|
||||
return switch (ref.type()) {
|
||||
case "configuration-set" -> listConfigurationSetTags(ref.name(), ref.region());
|
||||
// AWS ListTagsForResource on template / identity ARNs uses the signing region
|
||||
// for lookup (the ARN region is effectively ignored), unlike configuration-set
|
||||
// which routes by the ARN's region.
|
||||
requireCallerAccount(ref);
|
||||
List<Tag> tags = switch (ref.type()) {
|
||||
case "configuration-set" -> listConfigurationSetTags(ref.name(), region);
|
||||
case "template" -> listEmailTemplateTags(ref.name(), region);
|
||||
case "identity" -> listIdentityTags(ref.name(), region);
|
||||
case "contact-list" -> contactService.listTags(ref.name(), region);
|
||||
case "custom-verification-email-template" -> cvetService.listTags(ref.name(), region);
|
||||
case "dedicated-ip-pool" -> dedicatedIpService.listTags(ref.name(), region);
|
||||
default -> throw new AwsException("NotFoundException",
|
||||
"Resource " + arn + " was not found.", 404);
|
||||
};
|
||||
// AWS checks existence against the signing region but keys the tag store by the literal
|
||||
// ARN: a mismatched ARN region passes the existence check above yet addresses an ARN
|
||||
// nothing was ever tagged under, so the result is empty (probe-confirmed across all six
|
||||
// resource types).
|
||||
if (!ref.region().equals(region)) {
|
||||
return List.of();
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void tagResource(String arn, String region, List<Tag> newTags) {
|
||||
ResourceRef ref = parseSesArn(arn);
|
||||
requireCallerAccount(ref);
|
||||
if (!ref.region().equals(region)) {
|
||||
throw new AwsException("BadRequestException", "Failed to tag resource", 400);
|
||||
}
|
||||
if (newTags == null || newTags.isEmpty()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"1 validation error detected: Value at 'tags' failed to satisfy constraint: "
|
||||
+ "Member must have length greater than or equal to 1", 400);
|
||||
}
|
||||
SesTags.validate(newTags);
|
||||
// An empty Tags list is not an error: AWS still runs the account, region, and existence
|
||||
// checks and then applies the empty merge as a no-op (probe-confirmed).
|
||||
List<Tag> tags = newTags == null ? List.of() : newTags;
|
||||
SesTags.validate(tags);
|
||||
switch (ref.type()) {
|
||||
case "configuration-set" -> tagConfigurationSet(ref.name(), ref.region(), newTags);
|
||||
case "template" -> tagEmailTemplate(ref.name(), ref.region(), newTags);
|
||||
case "identity" -> tagIdentity(ref.name(), ref.region(), newTags);
|
||||
case "configuration-set" -> tagConfigurationSet(ref.name(), region, tags);
|
||||
case "template" -> tagEmailTemplate(ref.name(), region, tags);
|
||||
case "identity" -> tagIdentity(ref.name(), region, tags);
|
||||
case "contact-list" -> contactService.tag(ref.name(), region, tags);
|
||||
case "custom-verification-email-template" -> cvetService.tag(ref.name(), region, tags);
|
||||
case "dedicated-ip-pool" -> dedicatedIpService.tag(ref.name(), region, tags);
|
||||
default -> throw new AwsException("NotFoundException",
|
||||
"Resource " + arn + " was not found.", 404);
|
||||
}
|
||||
@@ -2074,29 +2086,25 @@ public class SesService {
|
||||
|
||||
public void untagResource(String arn, String region, List<String> tagKeys) {
|
||||
ResourceRef ref = parseSesArn(arn);
|
||||
requireCallerAccount(ref);
|
||||
if (tagKeys == null || tagKeys.isEmpty()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"1 validation error detected: Value at 'tagKeys' failed to satisfy constraint: "
|
||||
+ "Member must have length greater than or equal to 1", 400);
|
||||
// AWS rejects a missing/empty TagKeys member with a message-less ValidationException
|
||||
// (probe-confirmed: only the error-type header, empty body), after the account guard
|
||||
// and before the region guard. The null message is deliberate — it surfaces through
|
||||
// Floci's standard error body as "message":null, which restJson1 SDKs parse the same
|
||||
// way as AWS's empty body since they read x-amzn-errortype first.
|
||||
throw new AwsException("ValidationException", null, 400);
|
||||
}
|
||||
if (!ref.region().equals(region)) {
|
||||
throw new AwsException("BadRequestException", "Failed to untag resource", 400);
|
||||
}
|
||||
switch (ref.type()) {
|
||||
case "configuration-set" -> untagConfigurationSet(ref.name(), ref.region(), tagKeys);
|
||||
case "template" -> {
|
||||
// AWS UntagResource on template / identity ARNs strictly requires the ARN
|
||||
// region to match the signing region (rejects mismatch with
|
||||
// BadRequestException), unlike configuration-set which routes the lookup
|
||||
// to the ARN's region.
|
||||
if (!ref.region().equals(region)) {
|
||||
throw new AwsException("BadRequestException", "Failed to untag resource", 400);
|
||||
}
|
||||
untagEmailTemplate(ref.name(), region, tagKeys);
|
||||
}
|
||||
case "identity" -> {
|
||||
if (!ref.region().equals(region)) {
|
||||
throw new AwsException("BadRequestException", "Failed to untag resource", 400);
|
||||
}
|
||||
untagIdentity(ref.name(), region, tagKeys);
|
||||
}
|
||||
case "configuration-set" -> untagConfigurationSet(ref.name(), region, tagKeys);
|
||||
case "template" -> untagEmailTemplate(ref.name(), region, tagKeys);
|
||||
case "identity" -> untagIdentity(ref.name(), region, tagKeys);
|
||||
case "contact-list" -> contactService.untag(ref.name(), region, tagKeys);
|
||||
case "custom-verification-email-template" -> cvetService.untag(ref.name(), region, tagKeys);
|
||||
case "dedicated-ip-pool" -> dedicatedIpService.untag(ref.name(), region, tagKeys);
|
||||
default -> throw new AwsException("NotFoundException",
|
||||
"Resource " + arn + " was not found.", 404);
|
||||
}
|
||||
@@ -2114,7 +2122,7 @@ public class SesService {
|
||||
ConfigurationSet cs = configSetStore.get(key)
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
"No ConfigurationSet present with name: " + name, 404));
|
||||
cs.setTags(mergeTags(cs.getTags(), newTags));
|
||||
cs.setTags(SesTags.merge(cs.getTags(), newTags));
|
||||
configSetStore.put(key, cs);
|
||||
LOG.infov("Tagged SES configuration set: {0} (region {1}, +{2} tags)", name, region, newTags.size());
|
||||
}
|
||||
@@ -2125,7 +2133,10 @@ public class SesService {
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
"No ConfigurationSet present with name: " + name, 404));
|
||||
Set<String> toRemove = new HashSet<>(tagKeys);
|
||||
cs.getTags().removeIf(t -> toRemove.contains(t.key()));
|
||||
// Copy-on-write: the stored list may be immutable, and unlocked readers iterate it.
|
||||
List<Tag> remaining = new ArrayList<>(cs.getTags());
|
||||
remaining.removeIf(t -> toRemove.contains(t.key()));
|
||||
cs.setTags(remaining);
|
||||
configSetStore.put(key, cs);
|
||||
LOG.infov("Untagged SES configuration set: {0} (region {1}, -{2} keys)", name, region, tagKeys.size());
|
||||
}
|
||||
@@ -2141,26 +2152,11 @@ public class SesService {
|
||||
EmailTemplate template = templateService.find(name, region)
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
"No Template present with name: " + name, 404));
|
||||
template.setTags(mergeTags(template.getTags(), newTags));
|
||||
template.setTags(SesTags.merge(template.getTags(), newTags));
|
||||
templateService.save(template, region);
|
||||
LOG.infov("Tagged SES template: {0} (region {1}, +{2} tags)", name, region, newTags.size());
|
||||
}
|
||||
|
||||
private static List<Tag> mergeTags(List<Tag> existing,
|
||||
List<Tag> incoming) {
|
||||
Map<String, String> merged = new LinkedHashMap<>();
|
||||
for (Tag t : existing) {
|
||||
merged.put(t.key(), t.value());
|
||||
}
|
||||
for (Tag t : incoming) {
|
||||
merged.put(t.key(), t.value());
|
||||
}
|
||||
SesTags.validateMergedCount(merged.size());
|
||||
List<Tag> out = new ArrayList<>();
|
||||
merged.forEach((k, v) -> out.add(new Tag(k, v)));
|
||||
return out;
|
||||
}
|
||||
|
||||
private List<Tag> listIdentityTags(String identityValue, String region) {
|
||||
Identity identity = identityStore.get(identityKey(region, identityValue))
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
@@ -2173,7 +2169,7 @@ public class SesService {
|
||||
Identity identity = identityStore.get(key)
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
"No EmailIdentity present with name: " + identityValue, 404));
|
||||
identity.setTags(mergeTags(identity.getTags(), newTags));
|
||||
identity.setTags(SesTags.merge(identity.getTags(), newTags));
|
||||
identityStore.put(key, identity);
|
||||
LOG.infov("Tagged SES identity: {0} (region {1}, +{2} tags)", identityValue, region, newTags.size());
|
||||
}
|
||||
@@ -2184,7 +2180,10 @@ public class SesService {
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
"No EmailIdentity present with name: " + identityValue, 404));
|
||||
Set<String> toRemove = new HashSet<>(tagKeys);
|
||||
identity.getTags().removeIf(t -> toRemove.contains(t.key()));
|
||||
// Copy-on-write: the stored list may be immutable, and unlocked readers iterate it.
|
||||
List<Tag> remaining = new ArrayList<>(identity.getTags());
|
||||
remaining.removeIf(t -> toRemove.contains(t.key()));
|
||||
identity.setTags(remaining);
|
||||
identityStore.put(key, identity);
|
||||
LOG.infov("Untagged SES identity: {0} (region {1}, -{2} keys)", identityValue, region, tagKeys.size());
|
||||
}
|
||||
@@ -2204,12 +2203,28 @@ public class SesService {
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
"No Template present with name: " + name, 404));
|
||||
Set<String> toRemove = new HashSet<>(tagKeys);
|
||||
template.getTags().removeIf(t -> toRemove.contains(t.key()));
|
||||
// Copy-on-write: the stored list may be immutable, and unlocked readers iterate it.
|
||||
List<Tag> remaining = new ArrayList<>(template.getTags());
|
||||
remaining.removeIf(t -> toRemove.contains(t.key()));
|
||||
template.setTags(remaining);
|
||||
templateService.save(template, region);
|
||||
LOG.infov("Untagged SES template: {0} (region {1}, -{2} keys)", name, region, tagKeys.size());
|
||||
}
|
||||
|
||||
private record ResourceRef(String region, String type, String name) {}
|
||||
private record ResourceRef(String account, String region, String type, String name) {}
|
||||
|
||||
/**
|
||||
* AWS rejects a tag operation whose ARN carries a different account id before any region or
|
||||
* existence check (probe-confirmed): the account error wins even when the region is also
|
||||
* mismatched or the resource doesn't exist anywhere.
|
||||
*/
|
||||
private void requireCallerAccount(ResourceRef ref) {
|
||||
String callerAccountId = regionResolver != null ? regionResolver.getAccountId() : defaultAccountId;
|
||||
if (!ref.account().equals(callerAccountId)) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"Operations on a resource created in a different account is not allowed", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static ResourceRef parseSesArn(String arn) {
|
||||
if (arn == null || arn.isBlank()) {
|
||||
@@ -2234,7 +2249,8 @@ public class SesService {
|
||||
if (slash <= 0 || slash == resource.length() - 1) {
|
||||
throw new AwsException("BadRequestException", "Invalid ARN: " + arn, 400);
|
||||
}
|
||||
return new ResourceRef(parsed.region(), resource.substring(0, slash), resource.substring(slash + 1));
|
||||
return new ResourceRef(parsed.accountId(), parsed.region(),
|
||||
resource.substring(0, slash), resource.substring(slash + 1));
|
||||
}
|
||||
|
||||
// ──────────────────── Suppression (account attributes + list) ────────────────────
|
||||
|
||||
@@ -5,7 +5,9 @@ import io.github.hectorvent.floci.services.ses.model.Tag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -112,6 +114,24 @@ final class SesTags {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code TagResource} merge semantics: incoming keys overwrite existing values, insertion order
|
||||
* is preserved, and the 50-tag ceiling applies to the merged result.
|
||||
*/
|
||||
static List<Tag> merge(List<Tag> existing, List<Tag> incoming) {
|
||||
Map<String, String> merged = new LinkedHashMap<>();
|
||||
for (Tag t : existing) {
|
||||
merged.put(t.key(), t.value());
|
||||
}
|
||||
for (Tag t : incoming) {
|
||||
merged.put(t.key(), t.value());
|
||||
}
|
||||
validateMergedCount(merged.size());
|
||||
List<Tag> out = new ArrayList<>();
|
||||
merged.forEach((k, v) -> out.add(new Tag(k, v)));
|
||||
return out;
|
||||
}
|
||||
|
||||
// A null value counts as a character-set violation (AWS requires a string value; empty is allowed).
|
||||
private static boolean charsetOk(String s) {
|
||||
return s != null && TAG_CHARS.matcher(s).matches();
|
||||
|
||||
@@ -74,8 +74,9 @@ public class SesTemplateService {
|
||||
"Template " + template.getTemplateName() + " does not exist.", 400));
|
||||
template.setCreatedTimestamp(existing.getCreatedTimestamp());
|
||||
template.setLastUpdatedTimestamp(Instant.now());
|
||||
// Tags are managed exclusively via Tag/UntagResource — preserve them on update.
|
||||
template.setTags(existing.getTags());
|
||||
// Tags are managed exclusively via Tag/UntagResource — preserve them on update (copied,
|
||||
// so the two objects never share a list instance).
|
||||
template.setTags(new ArrayList<>(existing.getTags()));
|
||||
templateStore.put(key, template);
|
||||
LOG.infov("Updated SES template: {0} in region {1}", template.getTemplateName(), region);
|
||||
return template;
|
||||
|
||||
+11
@@ -4,6 +4,9 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A custom verification email template: the branded email SES sends when verifying a new
|
||||
* sender email address (as opposed to {@link EmailTemplate}, which is for the emails a caller
|
||||
@@ -31,6 +34,9 @@ public class CustomVerificationEmailTemplate {
|
||||
@JsonProperty("FailureRedirectionURL")
|
||||
private String failureRedirectionURL;
|
||||
|
||||
@JsonProperty("Tags")
|
||||
private List<Tag> tags = new ArrayList<>();
|
||||
|
||||
public CustomVerificationEmailTemplate() {}
|
||||
|
||||
public String getTemplateName() { return templateName; }
|
||||
@@ -54,4 +60,9 @@ public class CustomVerificationEmailTemplate {
|
||||
public void setFailureRedirectionURL(String failureRedirectionURL) {
|
||||
this.failureRedirectionURL = failureRedirectionURL;
|
||||
}
|
||||
|
||||
public List<Tag> getTags() { return tags; }
|
||||
public void setTags(List<Tag> tags) {
|
||||
this.tags = tags == null ? new ArrayList<>() : tags;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A SES V2 dedicated IP pool. Mirrors the AWS {@code DedicatedIpPool} shape:
|
||||
* a pool name and its scaling mode ({@code STANDARD} or {@code MANAGED}).
|
||||
@@ -20,6 +23,9 @@ public class DedicatedIpPool {
|
||||
@JsonProperty("ScalingMode")
|
||||
private String scalingMode;
|
||||
|
||||
@JsonProperty("Tags")
|
||||
private List<Tag> tags = new ArrayList<>();
|
||||
|
||||
public DedicatedIpPool() {}
|
||||
|
||||
public DedicatedIpPool(String poolName, String scalingMode) {
|
||||
@@ -32,4 +38,9 @@ public class DedicatedIpPool {
|
||||
|
||||
public String getScalingMode() { return scalingMode; }
|
||||
public void setScalingMode(String scalingMode) { this.scalingMode = scalingMode; }
|
||||
|
||||
public List<Tag> getTags() { return tags; }
|
||||
public void setTags(List<Tag> tags) {
|
||||
this.tags = tags == null ? new ArrayList<>() : tags;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user