mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
feat(ses): extend tag endpoints to v2 EmailTemplate ARNs (#759)
Adds support for arn:aws:ses:<region>:<account>:template/<name> ARNs across TagResource / UntagResource / ListTagsForResource. Behaviour was verified against real AWS via aws sesv2 commands and aligned where it diverged. - EmailTemplate gains a tags field. CreateEmailTemplate accepts an optional Tags array; tag validation reuses validateTag(). - UpdateEmailTemplate intentionally preserves the existing tags so that AWS-style "tags only mutated via Tag/UntagResource" semantics hold. - GetEmailTemplate response surfaces stored tags. - Missing templates return NotFoundException with the AWS-canonical "No Template present with name: <name>" message — AWS uses the bare "Template" (not "EmailTemplate") for tag-endpoint lookups even though the SDK type is EmailTemplate. Resource-type-specific routing in the tag endpoints: - TagResource on a template ARN strictly validates ARN/signing region match (BadRequestException "Failed to tag resource" on mismatch), matching the existing ConfigurationSet behaviour. - UntagResource on a template ARN strictly validates ARN/signing region match (BadRequestException "Failed to untag resource"), whereas ConfigurationSet's lenient ARN-region lookup is preserved. AWS treats the two resource types asymmetrically here. - ListTagsForResource on a template ARN ignores the ARN region and resolves the template against the signing region. ConfigurationSet continues to route by ARN region. Three small refactors that fall out naturally from adding a second taggable resource: - Tag is promoted from ConfigurationSet.Tag to a top-level services/ses/model/Tag so EmailTemplate and the shared helpers no longer reference a Configuration-scoped name. JSON serialization is unchanged. - A private mergeTags(existing, incoming) helper centralizes the LinkedHashMap merge previously duplicated between tagConfigurationSet and tagEmailTemplate. - A private parseTagsArray(JsonNode) helper centralizes the JSON Tags array parse previously duplicated across createConfigurationSet, createEmailTemplate, and tagResource. The helper returns null for missing/null nodes; the required caller (tagResource) treats null as BadRequestException. Tests: - SesTagsV2IntegrationTest gains a template lifecycle case, a template-not-found assertion, and the two template-specific region-mismatch / signing-region-lookup cases. - SesTemplateV2IntegrationTest covers create-with-tags, list-via-tags endpoint, and update-preserves-tags round-trips. - SesTagResourceTest (Java SDK compat) exercises CreateEmailTemplate with Tags and the Tag/Untag lifecycle on the template ARN.
This commit is contained in:
1 parent
ce2012de45
commit
646b4199df
9 files changed
+425
-62
No files matched your search
+63
-1
@@ -10,7 +10,12 @@ import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import software.amazon.awssdk.services.sesv2.SesV2Client;
|
||||
import software.amazon.awssdk.services.sesv2.model.CreateConfigurationSetRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.CreateEmailTemplateRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.DeleteConfigurationSetRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.DeleteEmailTemplateRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.EmailTemplateContent;
|
||||
import software.amazon.awssdk.services.sesv2.model.GetEmailTemplateRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.GetEmailTemplateResponse;
|
||||
import software.amazon.awssdk.services.sesv2.model.ListTagsForResourceRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.ListTagsForResourceResponse;
|
||||
import software.amazon.awssdk.services.sesv2.model.NotFoundException;
|
||||
@@ -30,12 +35,17 @@ class SesTagResourceTest {
|
||||
private static SesV2Client sesV2;
|
||||
private static String configSetName;
|
||||
private static String configSetArn;
|
||||
private static String templateName;
|
||||
private static String templateArn;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
sesV2 = TestFixtures.sesV2Client();
|
||||
configSetName = "sdk-tag-cs-" + TestFixtures.uniqueName();
|
||||
String suffix = TestFixtures.uniqueName();
|
||||
configSetName = "sdk-tag-cs-" + suffix;
|
||||
configSetArn = "arn:aws:ses:us-east-1:000000000000:configuration-set/" + configSetName;
|
||||
templateName = "sdk-tag-tpl-" + suffix;
|
||||
templateArn = "arn:aws:ses:us-east-1:000000000000:template/" + templateName;
|
||||
|
||||
sesV2.createConfigurationSet(CreateConfigurationSetRequest.builder()
|
||||
.configurationSetName(configSetName)
|
||||
@@ -49,6 +59,10 @@ class SesTagResourceTest {
|
||||
sesV2.deleteConfigurationSet(DeleteConfigurationSetRequest.builder()
|
||||
.configurationSetName(configSetName).build());
|
||||
} catch (Exception ignored) {}
|
||||
try {
|
||||
sesV2.deleteEmailTemplate(DeleteEmailTemplateRequest.builder()
|
||||
.templateName(templateName).build());
|
||||
} catch (Exception ignored) {}
|
||||
sesV2.close();
|
||||
}
|
||||
}
|
||||
@@ -127,4 +141,52 @@ class SesTagResourceTest {
|
||||
.build()))
|
||||
.isInstanceOf(NotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void emailTemplate_createWithTags_visibleViaListTagsAndGet() {
|
||||
sesV2.createEmailTemplate(CreateEmailTemplateRequest.builder()
|
||||
.templateName(templateName)
|
||||
.templateContent(EmailTemplateContent.builder()
|
||||
.subject("S").text("T").build())
|
||||
.tags(
|
||||
Tag.builder().key("env").value("dev").build(),
|
||||
Tag.builder().key("team").value("platform").build())
|
||||
.build());
|
||||
|
||||
// ListTagsForResource sees the create-time tags
|
||||
ListTagsForResourceResponse listed = sesV2.listTagsForResource(ListTagsForResourceRequest.builder()
|
||||
.resourceArn(templateArn).build());
|
||||
assertThat(listed.tags()).hasSize(2);
|
||||
|
||||
// GetEmailTemplate also surfaces them
|
||||
GetEmailTemplateResponse got = sesV2.getEmailTemplate(GetEmailTemplateRequest.builder()
|
||||
.templateName(templateName).build());
|
||||
assertThat(got.tags())
|
||||
.extracting(Tag::key)
|
||||
.containsExactlyInAnyOrder("env", "team");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void emailTemplate_tagAndUntag_lifecycle() {
|
||||
sesV2.tagResource(TagResourceRequest.builder()
|
||||
.resourceArn(templateArn)
|
||||
.tags(Tag.builder().key("owner").value("alice").build())
|
||||
.build());
|
||||
|
||||
ListTagsForResourceResponse afterTag = sesV2.listTagsForResource(ListTagsForResourceRequest.builder()
|
||||
.resourceArn(templateArn).build());
|
||||
assertThat(afterTag.tags()).hasSize(3);
|
||||
|
||||
sesV2.untagResource(UntagResourceRequest.builder()
|
||||
.resourceArn(templateArn)
|
||||
.tagKeys("env", "team")
|
||||
.build());
|
||||
|
||||
ListTagsForResourceResponse afterUntag = sesV2.listTagsForResource(ListTagsForResourceRequest.builder()
|
||||
.resourceArn(templateArn).build());
|
||||
assertThat(afterUntag.tags()).hasSize(1);
|
||||
assertThat(afterUntag.tags().get(0).key()).isEqualTo("owner");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user