mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(ses): extend tag endpoints to v2 EmailIdentity ARNs (#760)
* feat(ses): extend tag endpoints to v2 EmailIdentity ARNs Adds support for arn:aws:ses:<region>:<account>:identity/<email-or-domain> ARNs across TagResource / UntagResource / ListTagsForResource. Behaviour was verified against real AWS via aws sesv2 commands and matches the EmailTemplate routing exactly: - Tag region mismatch -> BadRequestException "Failed to tag resource" - Untag region mismatch -> BadRequestException "Failed to untag resource" - List region mismatch -> Tags resolved against the signing region - Missing identity -> NotFoundException with "No EmailIdentity present with name: <identity>" Identity gains a tags field. CreateEmailIdentity accepts an optional Tags array (validated via the existing validateTag()) and persists it on the freshly verified Identity record. GetEmailIdentity surfaces stored tags in the existing Tags response field. Tests: - SesTagsV2IntegrationTest gains identity lifecycle, identity-not-found, and identity-specific region-mismatch / signing-region-lookup cases. - SesIdentityAttributesV2IntegrationTest covers create-with-tags -> Get/ListTagsForResource round-trip. - SesTagResourceTest (Java SDK compat) exercises CreateEmailIdentity with Tags and the Tag/Untag lifecycle on the identity ARN. * test(ses): move identity tags round-trip test next to other createEmailIdentity cases The Tags-on-create round-trip case fits better next to the existing createEmailIdentity_* cases at the top of SesV2IntegrationTest than it does in the attributes-focused SesIdentityAttributesV2IntegrationTest, where DKIM / MAIL FROM / Feedback validation lives. * chore(ses): drop dead identity.setTags call after CreateEmailIdentity setIdentityTags already persists the tag list on the stored Identity, and CreateEmailIdentity does not surface Tags in its response per the AWS spec, so the in-memory mutation that followed had no observable effect.
This commit is contained in:
1 parent
646b4199df
commit
bcc36c08e0
7 files changed
+300
-8
No files matched your search
@@ -83,6 +83,11 @@ public class SesController {
|
||||
? sesService.verifyEmailIdentity(emailIdentity, region)
|
||||
: sesService.verifyDomainIdentity(emailIdentity, region);
|
||||
|
||||
List<Tag> parsedTags = parseTagsArray(request.path("Tags"));
|
||||
if (parsedTags != null) {
|
||||
sesService.setIdentityTags(emailIdentity, region, parsedTags);
|
||||
}
|
||||
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
result.put("IdentityType", toV2IdentityType(identity.getIdentityType()));
|
||||
result.put("VerifiedForSendingStatus", true);
|
||||
@@ -773,7 +778,13 @@ public class SesController {
|
||||
v1BehaviorToV2(identity.getBehaviorOnMxFailure()));
|
||||
|
||||
result.putObject("Policies");
|
||||
result.putArray("Tags");
|
||||
ArrayNode tags = result.putArray("Tags");
|
||||
for (Tag t : identity.getTags()) {
|
||||
ObjectNode tagNode = objectMapper.createObjectNode();
|
||||
tagNode.put("Key", t.key());
|
||||
tagNode.put("Value", t.value());
|
||||
tags.add(tagNode);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -490,10 +490,11 @@ public class SesService {
|
||||
ResourceRef ref = parseSesArn(arn);
|
||||
return switch (ref.type()) {
|
||||
case "configuration-set" -> listConfigurationSetTags(ref.name(), ref.region());
|
||||
// AWS ListTagsForResource on template ARNs uses the signing region for lookup
|
||||
// (the ARN region is effectively ignored), unlike configuration-set which routes
|
||||
// by the ARN's 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.
|
||||
case "template" -> listEmailTemplateTags(ref.name(), region);
|
||||
case "identity" -> listIdentityTags(ref.name(), region);
|
||||
default -> throw new AwsException("NotFoundException",
|
||||
"Resource " + arn + " was not found.", 404);
|
||||
};
|
||||
@@ -515,6 +516,7 @@ public class SesService {
|
||||
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);
|
||||
default -> throw new AwsException("NotFoundException",
|
||||
"Resource " + arn + " was not found.", 404);
|
||||
}
|
||||
@@ -530,14 +532,21 @@ public class SesService {
|
||||
switch (ref.type()) {
|
||||
case "configuration-set" -> untagConfigurationSet(ref.name(), ref.region(), tagKeys);
|
||||
case "template" -> {
|
||||
// AWS UntagResource on template 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.
|
||||
// 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);
|
||||
}
|
||||
default -> throw new AwsException("NotFoundException",
|
||||
"Resource " + arn + " was not found.", 404);
|
||||
}
|
||||
@@ -602,6 +611,48 @@ public class SesService {
|
||||
return out;
|
||||
}
|
||||
|
||||
private List<Tag> listIdentityTags(String identityValue, String region) {
|
||||
Identity identity = identityStore.get(identityKey(region, identityValue))
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
"No EmailIdentity present with name: " + identityValue, 404));
|
||||
return new ArrayList<>(identity.getTags());
|
||||
}
|
||||
|
||||
private void tagIdentity(String identityValue, String region, List<Tag> newTags) {
|
||||
String key = identityKey(region, identityValue);
|
||||
Identity identity = identityStore.get(key)
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
"No EmailIdentity present with name: " + identityValue, 404));
|
||||
identity.setTags(mergeTags(identity.getTags(), newTags));
|
||||
identityStore.put(key, identity);
|
||||
LOG.infov("Tagged SES identity: {0} (region {1}, +{2} tags)", identityValue, region, newTags.size());
|
||||
}
|
||||
|
||||
private void untagIdentity(String identityValue, String region, List<String> tagKeys) {
|
||||
String key = identityKey(region, identityValue);
|
||||
Identity identity = identityStore.get(key)
|
||||
.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()));
|
||||
identityStore.put(key, identity);
|
||||
LOG.infov("Untagged SES identity: {0} (region {1}, -{2} keys)", identityValue, region, tagKeys.size());
|
||||
}
|
||||
|
||||
public void setIdentityTags(String identityValue, String region, List<Tag> tags) {
|
||||
if (tags != null) {
|
||||
for (Tag tag : tags) {
|
||||
validateTag(tag);
|
||||
}
|
||||
}
|
||||
String key = identityKey(region, identityValue);
|
||||
Identity identity = identityStore.get(key)
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
"No EmailIdentity present with name: " + identityValue, 404));
|
||||
identity.setTags(tags);
|
||||
identityStore.put(key, identity);
|
||||
}
|
||||
|
||||
private void untagEmailTemplate(String name, String region, List<String> tagKeys) {
|
||||
String key = templateKey(region, name);
|
||||
EmailTemplate template = templateStore.get(key)
|
||||
|
||||
@@ -5,7 +5,9 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
@@ -51,6 +53,9 @@ public class Identity {
|
||||
@JsonProperty("CreatedAt")
|
||||
private Instant createdAt;
|
||||
|
||||
@JsonProperty("Tags")
|
||||
private List<Tag> tags = new ArrayList<>();
|
||||
|
||||
public Identity() {}
|
||||
|
||||
public Identity(String identity, String identityType) {
|
||||
@@ -101,4 +106,7 @@ public class Identity {
|
||||
|
||||
public Instant getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; }
|
||||
|
||||
public List<Tag> getTags() { return tags; }
|
||||
public void setTags(List<Tag> tags) { this.tags = tags != null ? tags : new ArrayList<>(); }
|
||||
}
|
||||
Reference in new issue
Block a user