} itself and tags against that. Anything
+ * that is not such an ARN names no DMS resource Floci holds, which is a ResourceNotFoundFault
+ * rather than a parameter error.
+ *
+ * An ARN naming another account or another Region is treated the same way. Tagging is not a
+ * cross-account or cross-Region operation on AWS, and here it cannot be one either: storage is
+ * scoped to the caller's account and keyed by the caller's Region, so honouring a foreign ARN
+ * would silently reach the caller's own group of that name instead of the one named.
+ */
+ private String subnetGroupKeyForArn(String resourceArn, String callerRegion) {
+ AwsArnUtils.Arn arn;
+ try {
+ arn = AwsArnUtils.parse(resourceArn);
+ } catch (IllegalArgumentException e) {
+ throw notFoundForArn(resourceArn);
+ }
+ String[] resource = arn.resource().split(":", 2);
+ if (!"dms".equals(arn.service()) || resource.length != 2
+ || !SUBNET_GROUP_ARN_RESOURCE_TYPE.equals(resource[0]) || resource[1].isBlank()) {
+ throw notFoundForArn(resourceArn);
+ }
+ if (!arn.accountId().isBlank() && !arn.accountId().equals(regionResolver.getAccountId())) {
+ throw notFoundForArn(resourceArn);
+ }
+ if (arn.region() != null && !arn.region().isBlank() && !arn.region().equals(callerRegion)) {
+ throw notFoundForArn(resourceArn);
+ }
+ return storageKey(callerRegion, resource[1].toLowerCase(Locale.ROOT));
+ }
+
+ private static List arnList(JsonNode request) {
+ JsonNode node = request == null ? null : request.get("ResourceArnList");
+ if (node == null || node.isNull()) {
+ return List.of();
+ }
+ if (!node.isArray()) {
+ throw serialization("ResourceArnList must be a list of strings.");
+ }
+ return stringList(node, "ResourceArnList");
+ }
+
+ private static String requireResourceArn(JsonNode request) {
+ String resourceArn = text(request, "ResourceArn");
+ if (resourceArn == null || resourceArn.isBlank()) {
+ throw invalidParameter("The parameter ResourceArn must be provided and must not be blank.");
+ }
+ return resourceArn;
+ }
+
+ private static Map readTags(JsonNode node) {
+ Map tags = new LinkedHashMap<>();
+ if (node == null || node.isNull()) {
+ return tags;
+ }
+ if (!node.isArray()) {
+ throw serialization("Tags must be a list of Key and Value pairs.");
+ }
+ for (JsonNode element : node) {
+ if (!element.isObject()) {
+ throw serialization("Tags must be a list of Key and Value pairs.");
+ }
+ String key = text(element, "Key");
+ String value = text(element, "Value");
+ if (key == null || key.isEmpty() || key.length() > 128 || isReserved(key)) {
+ throw invalidParameter("Tag keys must be 1-128 characters and must not start with"
+ + " \"aws:\" or \"dms:\".");
+ }
+ String tagValue = value == null ? "" : value;
+ if (tagValue.length() > 256 || isReserved(tagValue)) {
+ throw invalidParameter("Tag values must be at most 256 characters and must not start"
+ + " with \"aws:\" or \"dms:\".");
+ }
+ tags.put(key, tagValue);
+ }
+ return tags;
+ }
+
+ private static boolean isReserved(String value) {
+ return RESERVED_TAG_PREFIXES.stream().anyMatch(value::startsWith);
+ }
+
+ private static AwsException notFoundForArn(String resourceArn) {
+ return new AwsException("ResourceNotFoundFault",
+ "Resource " + resourceArn + " not found.", 400);
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/dms/model/ReplicationSubnetGroup.java b/src/main/java/io/github/hectorvent/floci/services/dms/model/ReplicationSubnetGroup.java
new file mode 100644
index 0000000000..febb4f21f4
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/dms/model/ReplicationSubnetGroup.java
@@ -0,0 +1,95 @@
+package io.github.hectorvent.floci.services.dms.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+@RegisterForReflection
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ReplicationSubnetGroup {
+
+ private String replicationSubnetGroupIdentifier;
+ private String replicationSubnetGroupDescription;
+ private String vpcId;
+ private String subnetGroupStatus = "Complete";
+ private List subnetIds = new ArrayList<>();
+ private Map subnetAvailabilityZones = new LinkedHashMap<>();
+ private List supportedNetworkTypes = new ArrayList<>();
+ private Map tags = new LinkedHashMap<>();
+
+ public ReplicationSubnetGroup() {
+ }
+
+ public String getReplicationSubnetGroupIdentifier() {
+ return replicationSubnetGroupIdentifier;
+ }
+
+ public void setReplicationSubnetGroupIdentifier(String replicationSubnetGroupIdentifier) {
+ this.replicationSubnetGroupIdentifier = replicationSubnetGroupIdentifier;
+ }
+
+ public String getReplicationSubnetGroupDescription() {
+ return replicationSubnetGroupDescription;
+ }
+
+ public void setReplicationSubnetGroupDescription(String replicationSubnetGroupDescription) {
+ this.replicationSubnetGroupDescription = replicationSubnetGroupDescription;
+ }
+
+ public String getVpcId() {
+ return vpcId;
+ }
+
+ public void setVpcId(String vpcId) {
+ this.vpcId = vpcId;
+ }
+
+ public String getSubnetGroupStatus() {
+ return subnetGroupStatus;
+ }
+
+ public void setSubnetGroupStatus(String subnetGroupStatus) {
+ this.subnetGroupStatus = subnetGroupStatus;
+ }
+
+ public List getSubnetIds() {
+ return List.copyOf(subnetIds);
+ }
+
+ public void setSubnetIds(List subnetIds) {
+ this.subnetIds = subnetIds != null ? new ArrayList<>(subnetIds) : new ArrayList<>();
+ }
+
+ public Map getSubnetAvailabilityZones() {
+ return Map.copyOf(subnetAvailabilityZones);
+ }
+
+ public void setSubnetAvailabilityZones(Map subnetAvailabilityZones) {
+ this.subnetAvailabilityZones = subnetAvailabilityZones != null
+ ? new LinkedHashMap<>(subnetAvailabilityZones)
+ : new LinkedHashMap<>();
+ }
+
+ public List getSupportedNetworkTypes() {
+ return List.copyOf(supportedNetworkTypes);
+ }
+
+ public void setSupportedNetworkTypes(List supportedNetworkTypes) {
+ this.supportedNetworkTypes = supportedNetworkTypes != null
+ ? new ArrayList<>(supportedNetworkTypes)
+ : new ArrayList<>();
+ }
+
+ public Map getTags() {
+ return Collections.unmodifiableMap(new LinkedHashMap<>(tags));
+ }
+
+ public void setTags(Map tags) {
+ this.tags = tags != null ? new LinkedHashMap<>(tags) : new LinkedHashMap<>();
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/dms/model/ResourceTag.java b/src/main/java/io/github/hectorvent/floci/services/dms/model/ResourceTag.java
new file mode 100644
index 0000000000..90dc860225
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/dms/model/ResourceTag.java
@@ -0,0 +1,9 @@
+package io.github.hectorvent.floci.services.dms.model;
+
+/**
+ * One tag as DMS returns it from {@code ListTagsForResource}. {@code resourceArn} is null for a
+ * single-ARN request and set when the caller passed {@code ResourceArnList}, which is the only
+ * form where AWS documents the field as part of the response.
+ */
+public record ResourceTag(String resourceArn, String key, String value) {
+}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 9fd286fcec..1f0762c9f4 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -832,3 +832,5 @@ floci:
enabled: true
marketplace:
enabled: true
+ dms:
+ enabled: true
diff --git a/src/test/java/io/github/hectorvent/floci/services/dms/DmsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/dms/DmsIntegrationTest.java
new file mode 100644
index 0000000000..d6234dfa59
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/dms/DmsIntegrationTest.java
@@ -0,0 +1,381 @@
+package io.github.hectorvent.floci.services.dms;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import io.restassured.specification.RequestSpecification;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.everyItem;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@QuarkusTest
+class DmsIntegrationTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String TARGET_PREFIX = "AmazonDMSv20160101.";
+ private static final String ACCOUNT_ID = "723679240095";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=" + ACCOUNT_ID + "/20260101/us-east-1/dms/aws4_request";
+ private static final String SUBNET_A = "subnet-default-us-east-1-a";
+ private static final String SUBNET_B = "subnet-default-us-east-1-b";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ @Test
+ void subnetGroupLifecycleIsReadableThroughDescribe() {
+ dms("CreateReplicationSubnetGroup")
+ .body("{\"ReplicationSubnetGroupIdentifier\":\"Tf-Lifecycle\","
+ + "\"ReplicationSubnetGroupDescription\":\"terraform managed\","
+ + "\"SubnetIds\":[\"" + SUBNET_A + "\",\"" + SUBNET_B + "\"]}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("ReplicationSubnetGroup.ReplicationSubnetGroupIdentifier", equalTo("tf-lifecycle"));
+
+ dms("DescribeReplicationSubnetGroups")
+ .body("{\"Filters\":[{\"Name\":\"replication-subnet-group-id\","
+ + "\"Values\":[\"tf-lifecycle\"]}]}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("ReplicationSubnetGroups", hasSize(1))
+ .body("ReplicationSubnetGroups[0].ReplicationSubnetGroupDescription",
+ equalTo("terraform managed"))
+ .body("ReplicationSubnetGroups[0].VpcId", equalTo("vpc-default-us-east-1"))
+ .body("ReplicationSubnetGroups[0].SubnetGroupStatus", equalTo("Complete"))
+ .body("ReplicationSubnetGroups[0].Subnets.SubnetIdentifier", contains(SUBNET_A, SUBNET_B))
+ .body("ReplicationSubnetGroups[0].Subnets.find { it.SubnetIdentifier == '"
+ + SUBNET_A + "' }.SubnetAvailabilityZone.Name", equalTo("us-east-1a"))
+ .body("ReplicationSubnetGroups[0].Subnets.find { it.SubnetIdentifier == '"
+ + SUBNET_B + "' }.SubnetAvailabilityZone.Name", equalTo("us-east-1b"))
+ .body("ReplicationSubnetGroups[0].Subnets.SubnetStatus", everyItem(equalTo("Active")))
+ .body("ReplicationSubnetGroups[0].SupportedNetworkTypes", contains("IPV4"))
+ .body("ReplicationSubnetGroups[0].IsReadOnly", equalTo(false));
+
+ dms("DeleteReplicationSubnetGroup")
+ .body("{\"ReplicationSubnetGroupIdentifier\":\"tf-lifecycle\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ dms("DescribeReplicationSubnetGroups")
+ .body("{\"Filters\":[{\"Name\":\"replication-subnet-group-id\","
+ + "\"Values\":[\"tf-lifecycle\"]}]}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundFault"));
+ }
+
+ /**
+ * DMS pages at a minimum MaxRecords of 20, so a second page needs more than 20 groups. Walk the
+ * pages on the wire and check Marker resumes where the previous page stopped and is absent from
+ * the final response.
+ */
+ @Test
+ void describePagesOnMarkerAndOmitsItFromTheFinalPage() {
+ List created = new ArrayList<>();
+ for (int i = 0; i < 25; i++) {
+ String identifier = "tf-page-" + String.format("%02d", i);
+ created.add(identifier);
+ dms("CreateReplicationSubnetGroup")
+ .body(createBody(identifier))
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+ }
+ try {
+ List walked = new ArrayList<>();
+ String marker = null;
+ int pages = 0;
+ do {
+ String body = marker == null
+ ? "{\"MaxRecords\":20}"
+ : "{\"MaxRecords\":20,\"Marker\":\"" + marker + "\"}";
+ Response page = dms("DescribeReplicationSubnetGroups")
+ .body(body)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .extract().response();
+ pages++;
+ marker = page.path("Marker");
+ List identifiers =
+ page.path("ReplicationSubnetGroups.ReplicationSubnetGroupIdentifier");
+ if (marker != null) {
+ assertEquals(20, identifiers.size(), "a non-final page must be full");
+ }
+ walked.addAll(identifiers);
+ } while (marker != null);
+
+ assertNull(marker, "the final page must not carry a Marker");
+ assertTrue(pages > 1, "25 groups at MaxRecords=20 must span more than one page");
+ assertEquals(walked.size(), walked.stream().distinct().count(), "a group was returned twice");
+ assertEquals(created, walked.stream().filter(id -> id.startsWith("tf-page-")).sorted().toList());
+ } finally {
+ created.forEach(identifier -> dms("DeleteReplicationSubnetGroup")
+ .body("{\"ReplicationSubnetGroupIdentifier\":\"" + identifier + "\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200));
+ }
+ }
+
+ @Test
+ void describeRejectsMaxRecordsOutsideTheDocumentedRange() {
+ for (int outOfRange : new int[] {19, 101}) {
+ dms("DescribeReplicationSubnetGroups")
+ .body("{\"MaxRecords\":" + outOfRange + "}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParameterValueException"));
+ }
+ }
+
+ @Test
+ void createRejectsADescriptionCarryingAControlCharacter() {
+ dms("CreateReplicationSubnetGroup")
+ .body("{\"ReplicationSubnetGroupIdentifier\":\"tf-control-char\","
+ + "\"ReplicationSubnetGroupDescription\":\"terraform\\u0001managed\","
+ + "\"SubnetIds\":[\"" + SUBNET_A + "\",\"" + SUBNET_B + "\"]}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParameterValueException"));
+
+ dms("DescribeReplicationSubnetGroups")
+ .body("{\"Filters\":[{\"Name\":\"replication-subnet-group-id\","
+ + "\"Values\":[\"tf-control-char\"]}]}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundFault"));
+ }
+
+ @Test
+ void createRejectsADuplicateIdentifier() {
+ dms("CreateReplicationSubnetGroup")
+ .body(createBody("tf-duplicate"))
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ dms("CreateReplicationSubnetGroup")
+ .body(createBody("tf-duplicate"))
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceAlreadyExistsFault"));
+
+ dms("DeleteReplicationSubnetGroup")
+ .body("{\"ReplicationSubnetGroupIdentifier\":\"tf-duplicate\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+ }
+
+ @Test
+ void createRejectsSubnetsInASingleAvailabilityZone() {
+ dms("CreateReplicationSubnetGroup")
+ .body("{\"ReplicationSubnetGroupIdentifier\":\"tf-one-az\","
+ + "\"ReplicationSubnetGroupDescription\":\"terraform managed\","
+ + "\"SubnetIds\":[\"" + SUBNET_A + "\"]}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ReplicationSubnetGroupDoesNotCoverEnoughAZs"));
+ }
+
+ @Test
+ void createRejectsAnUnknownSubnet() {
+ dms("CreateReplicationSubnetGroup")
+ .body("{\"ReplicationSubnetGroupIdentifier\":\"tf-bad-subnet\","
+ + "\"ReplicationSubnetGroupDescription\":\"terraform managed\","
+ + "\"SubnetIds\":[\"" + SUBNET_A + "\",\"subnet-does-not-exist\"]}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidSubnet"));
+ }
+
+ @Test
+ void createRejectsAMissingDescription() {
+ dms("CreateReplicationSubnetGroup")
+ .body("{\"ReplicationSubnetGroupIdentifier\":\"tf-no-description\","
+ + "\"SubnetIds\":[\"" + SUBNET_A + "\",\"" + SUBNET_B + "\"]}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParameterValueException"));
+ }
+
+ @Test
+ void deleteOfAMissingSubnetGroupFaults() {
+ dms("DeleteReplicationSubnetGroup")
+ .body("{\"ReplicationSubnetGroupIdentifier\":\"tf-absent\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundFault"));
+ }
+
+ @Test
+ void aTagValueOfTheWrongTypeIsASerializationErrorOnTheWire() {
+ dms("CreateReplicationSubnetGroup")
+ .body("{\"ReplicationSubnetGroupIdentifier\":\"tf-object-tag\","
+ + "\"ReplicationSubnetGroupDescription\":\"terraform managed\","
+ + "\"SubnetIds\":[\"" + SUBNET_A + "\",\"" + SUBNET_B + "\"],"
+ + "\"Tags\":[{\"Key\":\"env\",\"Value\":{\"nested\":1}}]}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("SerializationException"));
+
+ dms("DescribeReplicationSubnetGroups")
+ .body("{\"Filters\":[{\"Name\":\"replication-subnet-group-id\","
+ + "\"Values\":[\"tf-object-tag\"]}]}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundFault"));
+ }
+
+ @Test
+ void unsupportedDmsActionReportsUnknownOperation() {
+ dms("CreateReplicationInstance")
+ .body("{}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(404)
+ .body("__type", equalTo("UnknownOperationException"));
+ }
+
+ @Test
+ void tagsSurviveCreateAndAreReadableThroughListTagsForResource() {
+ dms("CreateReplicationSubnetGroup")
+ .body("{\"ReplicationSubnetGroupIdentifier\":\"tf-tagged\","
+ + "\"ReplicationSubnetGroupDescription\":\"terraform managed\","
+ + "\"SubnetIds\":[\"" + SUBNET_A + "\",\"" + SUBNET_B + "\"],"
+ + "\"Tags\":[{\"Key\":\"env\",\"Value\":\"test\"}]}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ dms("ListTagsForResource")
+ .body("{\"ResourceArn\":\"" + arn("tf-tagged") + "\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("TagList", hasSize(1))
+ .body("TagList[0].Key", equalTo("env"))
+ .body("TagList[0].Value", equalTo("test"))
+ .body("TagList[0].ResourceArn", nullValue());
+
+ dms("AddTagsToResource")
+ .body("{\"ResourceArn\":\"" + arn("tf-tagged") + "\","
+ + "\"Tags\":[{\"Key\":\"owner\",\"Value\":\"data\"}]}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ dms("ListTagsForResource")
+ .body("{\"ResourceArn\":\"" + arn("tf-tagged") + "\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("TagList.Key", containsInAnyOrder("env", "owner"));
+
+ dms("RemoveTagsFromResource")
+ .body("{\"ResourceArn\":\"" + arn("tf-tagged") + "\",\"TagKeys\":[\"env\"]}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ dms("ListTagsForResource")
+ .body("{\"ResourceArnList\":[\"" + arn("tf-tagged") + "\"]}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("TagList", hasSize(1))
+ .body("TagList[0].Key", equalTo("owner"))
+ .body("TagList[0].ResourceArn", equalTo(arn("tf-tagged")));
+
+ dms("DeleteReplicationSubnetGroup")
+ .body("{\"ReplicationSubnetGroupIdentifier\":\"tf-tagged\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+ }
+
+ @Test
+ void listTagsForAnUnknownArnFaults() {
+ dms("ListTagsForResource")
+ .body("{\"ResourceArn\":\"" + arn("tf-never-created") + "\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundFault"));
+ }
+
+ private static String arn(String identifier) {
+ return "arn:aws:dms:us-east-1:" + ACCOUNT_ID + ":subgrp:" + identifier;
+ }
+
+ private static String createBody(String identifier) {
+ return "{\"ReplicationSubnetGroupIdentifier\":\"" + identifier + "\","
+ + "\"ReplicationSubnetGroupDescription\":\"terraform managed\","
+ + "\"SubnetIds\":[\"" + SUBNET_A + "\",\"" + SUBNET_B + "\"]}";
+ }
+
+ private static RequestSpecification dms(String action) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET_PREFIX + action)
+ .header("Authorization", AUTH_HEADER);
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/dms/DmsServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/dms/DmsServiceTest.java
new file mode 100644
index 0000000000..3da3b7659e
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/dms/DmsServiceTest.java
@@ -0,0 +1,573 @@
+package io.github.hectorvent.floci.services.dms;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+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.PaginatedResult;
+import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.services.dms.model.ReplicationSubnetGroup;
+import io.github.hectorvent.floci.services.dms.model.ResourceTag;
+import io.github.hectorvent.floci.services.ec2.Ec2Service;
+import io.github.hectorvent.floci.services.ec2.model.Subnet;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class DmsServiceTest {
+ private static final String REGION = "us-east-1";
+ private static final String ACCOUNT_ID = "123456789012";
+ private static final String VPC_ID = "vpc-0dms";
+
+ private final ObjectMapper mapper = new ObjectMapper();
+ private DmsService service;
+
+ @BeforeEach
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ void setUp() {
+ StorageFactory storageFactory = mock(StorageFactory.class);
+ AccountAwareStorageBackend store =
+ AccountAwareStorageBackend.inMemory(ACCOUNT_ID);
+ when(storageFactory.create(eq("dms"), eq("dms-replication-subnet-groups.json"), any(TypeReference.class)))
+ .thenReturn((AccountAwareStorageBackend) store);
+
+ Ec2Service ec2Service = mock(Ec2Service.class);
+ when(ec2Service.describeSubnets(eq(REGION), anyList(), anyMap())).thenAnswer(invocation -> {
+ List requested = invocation.getArgument(1);
+ return requested.stream().map(DmsServiceTest::subnet).filter(Objects::nonNull).toList();
+ });
+ RegionResolver regionResolver = mock(RegionResolver.class);
+ when(regionResolver.getAccountId()).thenReturn(ACCOUNT_ID);
+ service = new DmsService(storageFactory, ec2Service, regionResolver);
+ }
+
+ @Test
+ void createStoresGroupUnderLowercasedIdentifier() {
+ service.createReplicationSubnetGroup(
+ createRequest("Tf-Example", "example", "subnet-a", "subnet-b"), REGION);
+
+ List described =
+ service.describeReplicationSubnetGroups(filterRequest("tf-example"), REGION).items();
+
+ assertEquals(1, described.size());
+ ReplicationSubnetGroup group = described.getFirst();
+ assertEquals("tf-example", group.getReplicationSubnetGroupIdentifier());
+ assertEquals("example", group.getReplicationSubnetGroupDescription());
+ assertEquals(VPC_ID, group.getVpcId());
+ assertEquals("Complete", group.getSubnetGroupStatus());
+ assertEquals(List.of("subnet-a", "subnet-b"), group.getSubnetIds());
+ assertEquals(Map.of("subnet-a", "us-east-1a", "subnet-b", "us-east-1b"),
+ group.getSubnetAvailabilityZones());
+ assertEquals(List.of("IPV4"), group.getSupportedNetworkTypes());
+ }
+
+ @Test
+ void createRejectsDuplicateIdentifierRegardlessOfCase() {
+ service.createReplicationSubnetGroup(createRequest("dup", "first", "subnet-a", "subnet-b"), REGION);
+
+ AwsException duplicate = assertThrows(AwsException.class, () -> service.createReplicationSubnetGroup(
+ createRequest("DUP", "second", "subnet-a", "subnet-b"), REGION));
+ assertEquals("ResourceAlreadyExistsFault", duplicate.getErrorCode());
+ }
+
+ @Test
+ void createRejectsUnknownSubnets() {
+ AwsException invalid = assertThrows(AwsException.class, () -> service.createReplicationSubnetGroup(
+ createRequest("bad-subnets", "example", "subnet-a", "subnet-missing"), REGION));
+ assertEquals("InvalidSubnet", invalid.getErrorCode());
+ }
+
+ @Test
+ void createRejectsSubnetsInASingleAvailabilityZone() {
+ AwsException tooFewZones = assertThrows(AwsException.class, () -> service.createReplicationSubnetGroup(
+ createRequest("one-az", "example", "subnet-a"), REGION));
+ assertEquals("ReplicationSubnetGroupDoesNotCoverEnoughAZs", tooFewZones.getErrorCode());
+ }
+
+ @Test
+ void createRejectsTwoSubnetsSharingOneAvailabilityZone() {
+ AwsException tooFewZones = assertThrows(AwsException.class, () -> service.createReplicationSubnetGroup(
+ createRequest("same-az", "example", "subnet-a", "subnet-a2"), REGION));
+ assertEquals("ReplicationSubnetGroupDoesNotCoverEnoughAZs", tooFewZones.getErrorCode());
+ }
+
+ @Test
+ void createRejectsASubnetWithNoAvailabilityZone() {
+ AwsException noZone = assertThrows(AwsException.class, () -> service.createReplicationSubnetGroup(
+ createRequest("no-az", "example", "subnet-a", "subnet-no-az"), REGION));
+ assertEquals("InvalidSubnet", noZone.getErrorCode());
+ }
+
+ @Test
+ void createRejectsSubnetsSpanningVpcs() {
+ AwsException crossVpc = assertThrows(AwsException.class, () -> service.createReplicationSubnetGroup(
+ createRequest("cross-vpc", "example", "subnet-a", "subnet-other-vpc"), REGION));
+ assertEquals("InvalidSubnet", crossVpc.getErrorCode());
+ }
+
+ @Test
+ void createRejectsMissingDescription() {
+ ObjectNode request = createRequest("no-description", null, "subnet-a", "subnet-b");
+ AwsException missing = assertThrows(AwsException.class,
+ () -> service.createReplicationSubnetGroup(request, REGION));
+ assertEquals("InvalidParameterValueException", missing.getErrorCode());
+ }
+
+ @Test
+ void createRejectsReservedDefaultIdentifier() {
+ AwsException reserved = assertThrows(AwsException.class, () -> service.createReplicationSubnetGroup(
+ createRequest("Default", "example", "subnet-a", "subnet-b"), REGION));
+ assertEquals("InvalidParameterValueException", reserved.getErrorCode());
+ }
+
+ @Test
+ void describeIsScopedToTheRequestRegion() {
+ service.createReplicationSubnetGroup(createRequest("scoped", "example", "subnet-a", "subnet-b"), REGION);
+
+ assertTrue(service.describeReplicationSubnetGroups(mapper.createObjectNode(), "eu-west-1")
+ .items().isEmpty());
+ }
+
+ @Test
+ void describeOfMissingGroupFaults() {
+ AwsException notFound = assertThrows(AwsException.class,
+ () -> service.describeReplicationSubnetGroups(filterRequest("absent"), REGION));
+ assertEquals("ResourceNotFoundFault", notFound.getErrorCode());
+ }
+
+ @Test
+ void describeWalksEveryGroupAcrossPagesWithoutDuplicatesOrOmissions() {
+ List created = createGroups(25);
+
+ PaginatedResult first =
+ service.describeReplicationSubnetGroups(pageRequest(20, null), REGION);
+ assertEquals(20, first.items().size());
+ assertNotNull(first.nextToken());
+
+ PaginatedResult second =
+ service.describeReplicationSubnetGroups(pageRequest(20, first.nextToken()), REGION);
+ assertEquals(5, second.items().size());
+ assertNull(second.nextToken(), "the final page must not carry a Marker");
+
+ List walked = new ArrayList<>();
+ first.items().forEach(group -> walked.add(group.getReplicationSubnetGroupIdentifier()));
+ second.items().forEach(group -> walked.add(group.getReplicationSubnetGroupIdentifier()));
+ assertEquals(created, walked);
+ }
+
+ @Test
+ void describeResumesAfterTheMarkerEvenWhenAnEarlierGroupIsDeleted() {
+ createGroups(25);
+
+ PaginatedResult first =
+ service.describeReplicationSubnetGroups(pageRequest(20, null), REGION);
+ service.deleteReplicationSubnetGroup(identifierRequest("page-00"), REGION);
+
+ PaginatedResult second =
+ service.describeReplicationSubnetGroups(pageRequest(20, first.nextToken()), REGION);
+
+ assertEquals(List.of("page-20", "page-21", "page-22", "page-23", "page-24"),
+ second.items().stream().map(ReplicationSubnetGroup::getReplicationSubnetGroupIdentifier).toList());
+ }
+
+ @Test
+ void describeDefaultsToOneHundredRecordsPerPage() {
+ createGroups(25);
+
+ PaginatedResult page =
+ service.describeReplicationSubnetGroups(mapper.createObjectNode(), REGION);
+
+ assertEquals(25, page.items().size());
+ assertNull(page.nextToken());
+ }
+
+ @Test
+ void describeRejectsMaxRecordsBelowTwenty() {
+ AwsException tooSmall = assertThrows(AwsException.class,
+ () -> service.describeReplicationSubnetGroups(pageRequest(19, null), REGION));
+ assertEquals("InvalidParameterValueException", tooSmall.getErrorCode());
+ }
+
+ @Test
+ void describeRejectsMaxRecordsAboveOneHundred() {
+ AwsException tooLarge = assertThrows(AwsException.class,
+ () -> service.describeReplicationSubnetGroups(pageRequest(101, null), REGION));
+ assertEquals("InvalidParameterValueException", tooLarge.getErrorCode());
+ }
+
+ @Test
+ void describeRejectsMaxRecordsThatIsNotAnInteger() {
+ ObjectNode request = mapper.createObjectNode();
+ request.put("MaxRecords", "20");
+
+ AwsException wrongType = assertThrows(AwsException.class,
+ () -> service.describeReplicationSubnetGroups(request, REGION));
+ assertEquals("SerializationException", wrongType.getErrorCode());
+ }
+
+ @Test
+ void createRejectsADescriptionCarryingAControlCharacter() {
+ ObjectNode request = createRequest("control-char", "terraform\u0001managed", "subnet-a", "subnet-b");
+
+ AwsException nonPrintable = assertThrows(AwsException.class,
+ () -> service.createReplicationSubnetGroup(request, REGION));
+ assertEquals("InvalidParameterValueException", nonPrintable.getErrorCode());
+ AwsException notStored = assertThrows(AwsException.class,
+ () -> service.describeReplicationSubnetGroups(filterRequest("control-char"), REGION));
+ assertEquals("ResourceNotFoundFault", notStored.getErrorCode());
+ }
+
+ @Test
+ void deleteRemovesTheGroup() {
+ service.createReplicationSubnetGroup(createRequest("doomed", "example", "subnet-a", "subnet-b"), REGION);
+ service.deleteReplicationSubnetGroup(identifierRequest("doomed"), REGION);
+
+ AwsException notFound = assertThrows(AwsException.class,
+ () -> service.describeReplicationSubnetGroups(filterRequest("doomed"), REGION));
+ assertEquals("ResourceNotFoundFault", notFound.getErrorCode());
+ }
+
+ @Test
+ void deleteOfMissingGroupFaults() {
+ AwsException notFound = assertThrows(AwsException.class,
+ () -> service.deleteReplicationSubnetGroup(identifierRequest("absent"), REGION));
+ assertEquals("ResourceNotFoundFault", notFound.getErrorCode());
+ }
+
+ @Test
+ void clearRemovesPersistedState() {
+ service.createReplicationSubnetGroup(createRequest("reset-me", "example", "subnet-a", "subnet-b"), REGION);
+ service.clear();
+
+ assertTrue(service.describeReplicationSubnetGroups(mapper.createObjectNode(), REGION).items().isEmpty());
+ }
+
+ @Test
+ void createStoresTagsReadableThroughListTagsForResource() {
+ ObjectNode request = createRequest("tagged", "example", "subnet-a", "subnet-b");
+ tagList(request.putArray("Tags"), "env", "test", "team", "platform");
+ service.createReplicationSubnetGroup(request, REGION);
+
+ assertEquals(Map.of("env", "test", "team", "platform"), tagsOf("tagged"));
+ }
+
+ @Test
+ void addTagsMergesWithExistingTagsAndOverwritesByKey() {
+ ObjectNode request = createRequest("merge-me", "example", "subnet-a", "subnet-b");
+ tagList(request.putArray("Tags"), "env", "test");
+ service.createReplicationSubnetGroup(request, REGION);
+
+ ObjectNode addRequest = mapper.createObjectNode();
+ addRequest.put("ResourceArn", arn("merge-me"));
+ tagList(addRequest.putArray("Tags"), "env", "prod", "owner", "data");
+ service.addTagsToResource(addRequest, REGION);
+
+ assertEquals(Map.of("env", "prod", "owner", "data"), tagsOf("merge-me"));
+ }
+
+ @Test
+ void removeTagsDropsOnlyTheNamedKeys() {
+ ObjectNode request = createRequest("trim-me", "example", "subnet-a", "subnet-b");
+ tagList(request.putArray("Tags"), "env", "test", "owner", "data");
+ service.createReplicationSubnetGroup(request, REGION);
+
+ ObjectNode removeRequest = mapper.createObjectNode();
+ removeRequest.put("ResourceArn", arn("trim-me"));
+ removeRequest.putArray("TagKeys").add("env").add("absent-key");
+ service.removeTagsFromResource(removeRequest, REGION);
+
+ assertEquals(Map.of("owner", "data"), tagsOf("trim-me"));
+ }
+
+ @Test
+ void listTagsByArnListCarriesTheOwningArnOnEachTag() {
+ ObjectNode request = createRequest("arn-list", "example", "subnet-a", "subnet-b");
+ tagList(request.putArray("Tags"), "env", "test");
+ service.createReplicationSubnetGroup(request, REGION);
+
+ ObjectNode listRequest = mapper.createObjectNode();
+ listRequest.putArray("ResourceArnList").add(arn("arn-list"));
+ List tags = service.listTagsForResource(listRequest, REGION);
+
+ assertEquals(List.of(new ResourceTag(arn("arn-list"), "env", "test")), tags);
+ }
+
+ @Test
+ void listTagsBySingleArnOmitsTheArnOnEachTag() {
+ ObjectNode request = createRequest("single-arn", "example", "subnet-a", "subnet-b");
+ tagList(request.putArray("Tags"), "env", "test");
+ service.createReplicationSubnetGroup(request, REGION);
+
+ assertEquals(List.of(new ResourceTag(null, "env", "test")),
+ service.listTagsForResource(arnRequest("single-arn"), REGION));
+ }
+
+ @Test
+ void tagOperationsOnAnUnknownArnFault() {
+ String missing = "arn:aws:dms:" + REGION + ":" + ACCOUNT_ID + ":subgrp:not-there";
+ ObjectNode listRequest = mapper.createObjectNode();
+ listRequest.put("ResourceArn", missing);
+
+ AwsException notFound = assertThrows(AwsException.class,
+ () -> service.listTagsForResource(listRequest, REGION));
+ assertEquals("ResourceNotFoundFault", notFound.getErrorCode());
+ }
+
+ @Test
+ void tagOperationsOnAnotherAccountsArnFault() {
+ ObjectNode request = createRequest("other-account", "example", "subnet-a", "subnet-b");
+ tagList(request.putArray("Tags"), "env", "test");
+ service.createReplicationSubnetGroup(request, REGION);
+
+ ObjectNode listRequest = mapper.createObjectNode();
+ listRequest.put("ResourceArn", "arn:aws:dms:" + REGION + ":999999999999:subgrp:other-account");
+
+ AwsException notFound = assertThrows(AwsException.class,
+ () -> service.listTagsForResource(listRequest, REGION));
+ assertEquals("ResourceNotFoundFault", notFound.getErrorCode());
+ }
+
+ @Test
+ void tagOperationsOnAnotherRegionsArnFault() {
+ ObjectNode request = createRequest("other-region", "example", "subnet-a", "subnet-b");
+ tagList(request.putArray("Tags"), "env", "test");
+ service.createReplicationSubnetGroup(request, REGION);
+
+ ObjectNode listRequest = mapper.createObjectNode();
+ listRequest.put("ResourceArn", "arn:aws:dms:eu-west-1:" + ACCOUNT_ID + ":subgrp:other-region");
+
+ AwsException notFound = assertThrows(AwsException.class,
+ () -> service.listTagsForResource(listRequest, REGION));
+ assertEquals("ResourceNotFoundFault", notFound.getErrorCode());
+ }
+
+ @Test
+ void tagOperationsOnANonSubnetGroupArnFault() {
+ ObjectNode listRequest = mapper.createObjectNode();
+ listRequest.put("ResourceArn", "arn:aws:dms:" + REGION + ":" + ACCOUNT_ID + ":rep:Example");
+
+ AwsException notFound = assertThrows(AwsException.class,
+ () -> service.listTagsForResource(listRequest, REGION));
+ assertEquals("ResourceNotFoundFault", notFound.getErrorCode());
+ }
+
+ @Test
+ void reservedTagKeyPrefixesAreRejected() {
+ ObjectNode request = createRequest("reserved-tag", "example", "subnet-a", "subnet-b");
+ tagList(request.putArray("Tags"), "aws:created-by", "someone");
+
+ AwsException reserved = assertThrows(AwsException.class,
+ () -> service.createReplicationSubnetGroup(request, REGION));
+ assertEquals("InvalidParameterValueException", reserved.getErrorCode());
+ }
+
+ @Test
+ void deletingAGroupDropsItsTags() {
+ ObjectNode request = createRequest("tags-die", "example", "subnet-a", "subnet-b");
+ tagList(request.putArray("Tags"), "env", "test");
+ service.createReplicationSubnetGroup(request, REGION);
+ service.deleteReplicationSubnetGroup(identifierRequest("tags-die"), REGION);
+
+ AwsException notFound = assertThrows(AwsException.class,
+ () -> service.listTagsForResource(arnRequest("tags-die"), REGION));
+ assertEquals("ResourceNotFoundFault", notFound.getErrorCode());
+ }
+
+ @Test
+ void createRejectsATagValueThatIsNotAString() {
+ ObjectNode request = createRequest("object-tag-value", "example", "subnet-a", "subnet-b");
+ request.putArray("Tags").addObject().put("Key", "env").putObject("Value").put("nested", 1);
+
+ AwsException wrongType = assertThrows(AwsException.class,
+ () -> service.createReplicationSubnetGroup(request, REGION));
+ assertEquals("SerializationException", wrongType.getErrorCode());
+ }
+
+ @Test
+ void createRejectsATagsMemberThatIsNotAList() {
+ ObjectNode request = createRequest("scalar-tags", "example", "subnet-a", "subnet-b");
+ request.put("Tags", "env=test");
+
+ AwsException wrongType = assertThrows(AwsException.class,
+ () -> service.createReplicationSubnetGroup(request, REGION));
+ assertEquals("SerializationException", wrongType.getErrorCode());
+ }
+
+ @Test
+ void createRejectsASubnetIdThatIsNotAString() {
+ ObjectNode request = identifierRequest("numeric-subnet");
+ request.put("ReplicationSubnetGroupDescription", "example");
+ request.putArray("SubnetIds").add("subnet-a").add(42);
+
+ AwsException wrongType = assertThrows(AwsException.class,
+ () -> service.createReplicationSubnetGroup(request, REGION));
+ assertEquals("SerializationException", wrongType.getErrorCode());
+ }
+
+ @Test
+ void describeRejectsFilterValuesThatAreNotAList() {
+ ObjectNode request = mapper.createObjectNode();
+ ObjectNode filter = request.putArray("Filters").addObject();
+ filter.put("Name", "replication-subnet-group-id");
+ filter.put("Values", "tf-example");
+
+ AwsException wrongType = assertThrows(AwsException.class,
+ () -> service.describeReplicationSubnetGroups(request, REGION));
+ assertEquals("SerializationException", wrongType.getErrorCode());
+ }
+
+ @Test
+ void describeRejectsAFilterValueThatIsNotAString() {
+ ObjectNode request = mapper.createObjectNode();
+ ObjectNode filter = request.putArray("Filters").addObject();
+ filter.put("Name", "replication-subnet-group-id");
+ filter.putArray("Values").addObject().put("Value", "tf-example");
+
+ AwsException wrongType = assertThrows(AwsException.class,
+ () -> service.describeReplicationSubnetGroups(request, REGION));
+ assertEquals("SerializationException", wrongType.getErrorCode());
+ }
+
+ @Test
+ void listTagsRejectsAnArnListElementThatIsNotAString() {
+ ObjectNode request = mapper.createObjectNode();
+ request.putArray("ResourceArnList").addObject().put("ResourceArn", arn("whatever"));
+
+ AwsException wrongType = assertThrows(AwsException.class,
+ () -> service.listTagsForResource(request, REGION));
+ assertEquals("SerializationException", wrongType.getErrorCode());
+ }
+
+ @Test
+ void removeTagsRejectsATagKeyThatIsNotAString() {
+ ObjectNode request = createRequest("bad-tag-keys", "example", "subnet-a", "subnet-b");
+ service.createReplicationSubnetGroup(request, REGION);
+
+ ObjectNode removeRequest = mapper.createObjectNode();
+ removeRequest.put("ResourceArn", arn("bad-tag-keys"));
+ removeRequest.putArray("TagKeys").add(7);
+
+ AwsException wrongType = assertThrows(AwsException.class,
+ () -> service.removeTagsFromResource(removeRequest, REGION));
+ assertEquals("SerializationException", wrongType.getErrorCode());
+ }
+
+ @Test
+ void createRejectsAnIdentifierThatIsNotAString() {
+ ObjectNode request = mapper.createObjectNode();
+ request.put("ReplicationSubnetGroupIdentifier", 12345);
+ request.put("ReplicationSubnetGroupDescription", "example");
+ request.putArray("SubnetIds").add("subnet-a").add("subnet-b");
+
+ AwsException wrongType = assertThrows(AwsException.class,
+ () -> service.createReplicationSubnetGroup(request, REGION));
+ assertEquals("SerializationException", wrongType.getErrorCode());
+ }
+
+ private Map tagsOf(String identifier) {
+ return service.listTagsForResource(arnRequest(identifier), REGION).stream()
+ .collect(Collectors.toMap(ResourceTag::key, ResourceTag::value));
+ }
+
+ private ObjectNode arnRequest(String identifier) {
+ ObjectNode request = mapper.createObjectNode();
+ request.put("ResourceArn", arn(identifier));
+ return request;
+ }
+
+ private String arn(String identifier) {
+ return "arn:aws:dms:" + REGION + ":" + ACCOUNT_ID + ":subgrp:" + identifier;
+ }
+
+ private static void tagList(ArrayNode tags, String... keysAndValues) {
+ for (int i = 0; i < keysAndValues.length; i += 2) {
+ tags.addObject().put("Key", keysAndValues[i]).put("Value", keysAndValues[i + 1]);
+ }
+ }
+
+ private ObjectNode createRequest(String identifier, String description, String... subnetIds) {
+ ObjectNode request = identifierRequest(identifier);
+ if (description != null) {
+ request.put("ReplicationSubnetGroupDescription", description);
+ }
+ ArrayNode subnets = request.putArray("SubnetIds");
+ for (String subnetId : subnetIds) {
+ subnets.add(subnetId);
+ }
+ return request;
+ }
+
+ private ObjectNode identifierRequest(String identifier) {
+ ObjectNode request = mapper.createObjectNode();
+ request.put("ReplicationSubnetGroupIdentifier", identifier);
+ return request;
+ }
+
+ private List createGroups(int count) {
+ List identifiers = new ArrayList<>();
+ for (int i = 0; i < count; i++) {
+ String identifier = String.format("page-%02d", i);
+ service.createReplicationSubnetGroup(
+ createRequest(identifier, "example", "subnet-a", "subnet-b"), REGION);
+ identifiers.add(identifier);
+ }
+ return identifiers;
+ }
+
+ private ObjectNode pageRequest(int maxRecords, String marker) {
+ ObjectNode request = mapper.createObjectNode();
+ request.put("MaxRecords", maxRecords);
+ if (marker != null) {
+ request.put("Marker", marker);
+ }
+ return request;
+ }
+
+ private ObjectNode filterRequest(String identifier) {
+ ObjectNode request = mapper.createObjectNode();
+ ObjectNode filter = request.putArray("Filters").addObject();
+ filter.put("Name", "replication-subnet-group-id");
+ filter.putArray("Values").add(identifier);
+ return request;
+ }
+
+ private static Subnet subnet(String subnetId) {
+ return switch (subnetId) {
+ case "subnet-a" -> subnet(subnetId, VPC_ID, "us-east-1a");
+ case "subnet-b" -> subnet(subnetId, VPC_ID, "us-east-1b");
+ case "subnet-a2" -> subnet(subnetId, VPC_ID, "us-east-1a");
+ case "subnet-no-az" -> subnet(subnetId, VPC_ID, null);
+ case "subnet-other-vpc" -> subnet(subnetId, "vpc-0other", "us-east-1b");
+ default -> null;
+ };
+ }
+
+ private static Subnet subnet(String subnetId, String vpcId, String availabilityZone) {
+ Subnet subnet = new Subnet();
+ subnet.setSubnetId(subnetId);
+ subnet.setVpcId(vpcId);
+ subnet.setAvailabilityZone(availabilityZone);
+ subnet.setRegion(REGION);
+ return subnet;
+ }
+}
diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml
index 53bbd06470..712036cb0b 100644
--- a/src/test/resources/application.yml
+++ b/src/test/resources/application.yml
@@ -510,3 +510,5 @@ floci:
enabled: true
marketplace:
enabled: true
+ dms:
+ enabled: true
diff --git a/tools/docs/services.yaml b/tools/docs/services.yaml
index cbc027996a..57142a43b5 100644
--- a/tools/docs/services.yaml
+++ b/tools/docs/services.yaml
@@ -179,6 +179,10 @@ services:
doc: docs/services/detective.md
sources:
- { path: src/main/java/io/github/hectorvent/floci/services/detective/DetectiveController.java, mode: rest }
+ - service: dms
+ doc: docs/services/dms.md
+ sources:
+ - { path: src/main/java/io/github/hectorvent/floci/services/dms/DmsJsonHandler.java, mode: switch }
- service: docdb
doc: docs/services/docdb.md
sources: