Light, fluffy, and always free - The AWS Local Emulator alternative
feat(rds): support instance snapshot lifecycle operations (#4066)
XuJian12cad7961649
diff --git a/docs/services/rds.md b/docs/services/rds.mdindex da99068f9c..45247c3ce1 100644--- a/docs/services/rds.md+++ b/docs/services/rds.md@@ -52,6 +52,9 @@ RDS Data API (`rds-data`) is documented separately because it uses REST JSON rou| `ModifyOptionGroup` | Add, update, or remove options in an option group || `DeleteOptionGroup` | Delete an option group || `CreateDBSnapshot` | Create a snapshot of a DB instance |+| `DeleteDBSnapshot` | Delete an available manual DB snapshot and its saved data |+| `CopyDBSnapshot` | Copy an available DB snapshot, optionally copying tags or overriding the option group and KMS key |+| `ModifyDBSnapshot` | Change the engine version or option group of an available manual DB snapshot || `RestoreDBInstanceFromDBSnapshot` | Create a new DB instance from a snapshot || `DescribeDBSnapshots` | List DB instance snapshots || `DescribeDBSnapshotAttributes` | Return a snapshot's `restore` attribute (accounts authorized to copy/restore it) |@@ -97,9 +100,9 @@ checked against the instance's other window. Modifications apply immediately —`CreateDBSnapshot` accepts `Tags`, and `TagResource`/`UntagResource`/`ListTagsForResource`work against a snapshot's ARN like they do for other tagged resource types.`DescribeDBSnapshotAttributes`/`ModifyDBSnapshotAttribute` are modeled as plain in-memory- state (no real cross-account sharing). `DeleteDBSnapshot` is not implemented, so a snapshot- persists for the life of the account; Terraform's `aws_db_snapshot` can be created but not- destroyed. Snapshots are region-scoped like DB instances and clusters: `DBSnapshotArn` reflects+ state (no real cross-account sharing). Available manual snapshots can be deleted, copied by+ identifier or ARN, and modified. Copies retain the source data and can copy source tags or add+ request tags. Snapshots are region-scoped like DB instances and clusters: `DBSnapshotArn` reflectsthe request's signed region, and a snapshot is only visible to `Describe`/`Tag` calls signedfor that same region. Aurora cluster snapshots and RDS reserved instances aren't modeled atall (`DescribeDBClusterSnapshots` always returns an empty list, and there's nodiff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.javaindex b726b9ced7..a0602a7f12 100644--- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java+++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java@@ -21,6 +21,7 @@ import io.github.hectorvent.floci.services.rds.model.DbProxy;import io.github.hectorvent.floci.services.rds.model.DbProxyAuth;import io.github.hectorvent.floci.services.rds.model.DbProxyTarget;import io.github.hectorvent.floci.services.rds.model.DbProxyTargetGroup;+import io.github.hectorvent.floci.services.rds.model.DbSnapshot;import io.github.hectorvent.floci.services.rds.model.DbSubnetGroup;import io.github.hectorvent.floci.services.rds.model.GlobalCluster;import io.github.hectorvent.floci.services.rds.model.GlobalClusterMember;@@ -109,6 +110,9 @@ public class RdsQueryHandler {case "ModifyOptionGroup" -> handleModifyOptionGroup(params, region);case "DeleteOptionGroup" -> handleDeleteOptionGroup(params, region);case "CreateDBSnapshot" -> handleCreateDbSnapshot(params, region);+ case "DeleteDBSnapshot" -> handleDeleteDbSnapshot(params, region);+ case "CopyDBSnapshot" -> handleCopyDbSnapshot(params, region);+ case "ModifyDBSnapshot" -> handleModifyDbSnapshot(params, region);case "RestoreDBInstanceFromDBSnapshot" -> handleRestoreDbInstanceFromDbSnapshot(params, region);case "DescribeDBSnapshots" -> handleDescribeDbSnapshots(params, region);case "DescribeDBSnapshotAttributes" -> handleDescribeDbSnapshotAttributes(params, region);@@ -1344,6 +1348,47 @@ public class RdsQueryHandler {}}+ private Response handleDeleteDbSnapshot(MultivaluedMap<String, String> params, String region) {+ String snapshotId = params.getFirst("DBSnapshotIdentifier");+ Response missing = firstMissingParam("DBSnapshotIdentifier", snapshotId);+ if (missing != null) {+ return missing;+ }+ DbSnapshot snapshot = service.deleteDbSnapshot(snapshotId, region);+ return Response.ok(AwsQueryResponse.envelope(+ "DeleteDBSnapshot", AwsNamespaces.RDS, dbSnapshotXml(snapshot))).build();+ }++ private Response handleCopyDbSnapshot(MultivaluedMap<String, String> params, String region) {+ String sourceId = params.getFirst("SourceDBSnapshotIdentifier");+ String targetId = params.getFirst("TargetDBSnapshotIdentifier");+ Response missing = firstMissingParam(+ "SourceDBSnapshotIdentifier", sourceId,+ "TargetDBSnapshotIdentifier", targetId);+ if (missing != null) {+ return missing;+ }+ Boolean copyTags = parseOptionalBoolean(params, "CopyTags");+ DbSnapshot snapshot = service.copyDbSnapshot(+ sourceId, targetId, Boolean.TRUE.equals(copyTags), parseTags(params),+ params.getFirst("OptionGroupName"), params.getFirst("KmsKeyId"), region);+ return Response.ok(AwsQueryResponse.envelope(+ "CopyDBSnapshot", AwsNamespaces.RDS, dbSnapshotXml(snapshot))).build();+ }++ private Response handleModifyDbSnapshot(MultivaluedMap<String, String> params, String region) {+ String snapshotId = params.getFirst("DBSnapshotIdentifier");+ Response missing = firstMissingParam("DBSnapshotIdentifier", snapshotId);+ if (missing != null) {+ return missing;+ }+ DbSnapshot snapshot = service.modifyDbSnapshot(+ snapshotId, params.getFirst("EngineVersion"),+ params.getFirst("OptionGroupName"), region);+ return Response.ok(AwsQueryResponse.envelope(+ "ModifyDBSnapshot", AwsNamespaces.RDS, dbSnapshotXml(snapshot))).build();+ }+private Response handleRestoreDbInstanceFromDbSnapshot(MultivaluedMap<String, String> params, String region) {String instanceId = params.getFirst("DBInstanceIdentifier");String snapshotId = params.getFirst("DBSnapshotIdentifier");@@ -1920,7 +1965,7 @@ public class RdsQueryHandler {return new XmlBuilder().start("DBInstance").raw(dbInstanceInnerXml(i)).end("DBInstance").build();}- private String dbSnapshotXml(io.github.hectorvent.floci.services.rds.model.DbSnapshot s) {+ private String dbSnapshotXml(DbSnapshot s) {String engineStr = s.getEngine() != null ? s.getEngine().name().toLowerCase() : "";XmlBuilder xml = new XmlBuilder().start("DBSnapshot").elem("DBSnapshotIdentifier", s.getDbSnapshotIdentifier())@@ -1930,7 +1975,19 @@ public class RdsQueryHandler {.elem("EngineVersion", s.getEngineVersion()).elem("AllocatedStorage", s.getAllocatedStorage()).elem("Status", s.getStatus())- .elem("MasterUsername", s.getMasterUsername());+ .elem("MasterUsername", s.getMasterUsername())+ .elem("SnapshotType", s.getSnapshotType() != null+ && !s.getSnapshotType().isBlank() ? s.getSnapshotType() : "manual");+ if (s.getSourceDbSnapshotIdentifier() != null+ && !s.getSourceDbSnapshotIdentifier().isBlank()) {+ xml.elem("SourceDBSnapshotIdentifier", s.getSourceDbSnapshotIdentifier());+ }+ if (s.getOptionGroupName() != null && !s.getOptionGroupName().isBlank()) {+ xml.elem("OptionGroupName", s.getOptionGroupName());+ }+ if (s.getKmsKeyId() != null && !s.getKmsKeyId().isBlank()) {+ xml.elem("KmsKeyId", s.getKmsKeyId());+ }if (s.getAvailabilityZone() != null) xml.elem("AvailabilityZone", s.getAvailabilityZone());if (s.getVpcId() != null) xml.elem("VpcId", s.getVpcId());xml.elem("InstanceCreateTime", s.getInstanceCreateTime() != null ? s.getInstanceCreateTime().toString() : "")diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.javaindex 04748b52fc..53a53b2496 100644--- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java+++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java@@ -803,6 +803,9 @@ public class RdsService implements Resettable, ResourceProvider {instance.getCreatedAt(), instance.getEndpoint() != null ? instance.getEndpoint().port() : instance.getProxyPort(),instance.isIamDatabaseAuthenticationEnabled(), instance.getDbiResourceId(), instance.getDbInstanceClass());snapshot.setDbName(instance.getDbName());+ snapshot.setSnapshotType("manual");+ snapshot.setOptionGroupName(instance.getOptionGroupName());+ snapshot.setKmsKeyId(instance.getKmsKeyId());snapshot.setTags(tags != null ? new java.util.LinkedHashMap<>(tags) : new java.util.LinkedHashMap<>());snapshot.setDbSnapshotArn(regionResolver.buildArn("rds", effectiveRegion, "snapshot:" + snapshotId));@@ -821,6 +824,199 @@ public class RdsService implements Resettable, ResourceProvider {return snapshot;}+ public DbSnapshot deleteDbSnapshot(String snapshotId) {+ return deleteDbSnapshot(snapshotId, regionResolver.getDefaultRegion());+ }++ public synchronized DbSnapshot deleteDbSnapshot(String snapshotId, String region) {+ String effectiveRegion = effectiveRegion(region);+ String accountId = currentAccountId();+ DbSnapshot snapshot = Optional.ofNullable(findSnapshotForScope(accountId, effectiveRegion, snapshotId))+ .orElseThrow(() -> new AwsException("DBSnapshotNotFound",+ "DBSnapshot " + snapshotId + " not found.", 404));+ if (!"available".equalsIgnoreCase(snapshot.getStatus())) {+ throw new AwsException("InvalidDBSnapshotState",+ "DBSnapshot " + snapshotId + " is not in an available state.", 400);+ }++ DbSnapshot deleted = copySnapshot(snapshot);+ deleted.setStatus("deleted");+ deleteSnapshotForScope(accountId, effectiveRegion, snapshotId);+ deleteSnapshotDataForScope(accountId, effectiveRegion, snapshotId);+ return deleted;+ }++ public DbSnapshot copyDbSnapshot(+ String sourceIdentifier, String targetIdentifier, boolean copyTags,+ Map<String, String> tags, String optionGroupName, String kmsKeyId) {+ return copyDbSnapshot(sourceIdentifier, targetIdentifier, copyTags, tags,+ optionGroupName, kmsKeyId, regionResolver.getDefaultRegion());+ }++ public synchronized DbSnapshot copyDbSnapshot(+ String sourceIdentifier, String targetIdentifier, boolean copyTags,+ Map<String, String> tags, String optionGroupName, String kmsKeyId, String region) {+ String targetRegion = effectiveRegion(region);+ String accountId = currentAccountId();+ SnapshotReference sourceReference = resolveSnapshotReference(sourceIdentifier, targetRegion);+ DbSnapshot source = sourceReference.snapshot();+ if (!"available".equalsIgnoreCase(source.getStatus())) {+ throw new AwsException("InvalidDBSnapshotState",+ "DBSnapshot " + source.getDbSnapshotIdentifier() + " is not in an available state.", 400);+ }+ if (findSnapshotForScope(accountId, targetRegion, targetIdentifier) != null) {+ throw new AwsException("DBSnapshotAlreadyExists",+ "DBSnapshot " + targetIdentifier + " already exists.", 400);+ }+ String sourceData = getSnapshotDataForScope(+ sourceReference.accountId(), sourceReference.region(), source.getDbSnapshotIdentifier())+ .orElseThrow(() -> new AwsException("DBSnapshotNotFound",+ "DBSnapshot data for " + source.getDbSnapshotIdentifier() + " not found.", 404));++ DbSnapshot copy = copySnapshot(source);+ copy.setDbSnapshotIdentifier(targetIdentifier);+ copy.setDbSnapshotArn(regionResolver.buildArn("rds", targetRegion, "snapshot:" + targetIdentifier));+ copy.setSnapshotCreateTime(Instant.now());+ copy.setStatus("available");+ copy.setSnapshotType("manual");+ copy.setSourceDbSnapshotIdentifier(source.getDbSnapshotArn());+ copy.setOptionGroupName(optionGroupName != null && !optionGroupName.isBlank()+ ? optionGroupName : source.getOptionGroupName());+ copy.setKmsKeyId(kmsKeyId != null && !kmsKeyId.isBlank() ? kmsKeyId : source.getKmsKeyId());+ copy.setRestoreAccountIds(new ArrayList<>());+ Map<String, String> copiedTags = new LinkedHashMap<>();+ if (copyTags) {+ copiedTags.putAll(source.getTags());+ }+ if (tags != null) {+ copiedTags.putAll(tags);+ }+ copy.setTags(copiedTags);+ putSnapshotDataForScope(accountId, targetRegion, targetIdentifier, sourceData);+ putSnapshotForScope(accountId, targetRegion, targetIdentifier, copy);+ return copy;+ }++ public DbSnapshot modifyDbSnapshot(+ String snapshotId, String engineVersion, String optionGroupName) {+ return modifyDbSnapshot(snapshotId, engineVersion, optionGroupName,+ regionResolver.getDefaultRegion());+ }++ public synchronized DbSnapshot modifyDbSnapshot(+ String snapshotId, String engineVersion, String optionGroupName, String region) {+ String effectiveRegion = effectiveRegion(region);+ String accountId = currentAccountId();+ DbSnapshot snapshot = Optional.ofNullable(findSnapshotForScope(accountId, effectiveRegion, snapshotId))+ .orElseThrow(() -> new AwsException("DBSnapshotNotFound",+ "DBSnapshot " + snapshotId + " not found.", 404));+ if (!"available".equalsIgnoreCase(snapshot.getStatus())) {+ throw new AwsException("InvalidDBSnapshotState",+ "DBSnapshot " + snapshotId + " is not in an available state.", 400);+ }+ if ((engineVersion == null || engineVersion.isBlank())+ && (optionGroupName == null || optionGroupName.isBlank())) {+ throw new AwsException("InvalidParameterCombination",+ "At least one snapshot attribute must be specified.", 400);+ }+ if (engineVersion != null && !engineVersion.isBlank()) {+ snapshot.setEngineVersion(engineVersion);+ }+ if (optionGroupName != null && !optionGroupName.isBlank()) {+ snapshot.setOptionGroupName(optionGroupName);+ }+ putSnapshotForScope(accountId, effectiveRegion, snapshotId, snapshot);+ return snapshot;+ }++ private DbSnapshot copySnapshot(DbSnapshot source) {+ DbSnapshot copy = new DbSnapshot();+ copy.setDbSnapshotIdentifier(source.getDbSnapshotIdentifier());+ copy.setDbSnapshotArn(source.getDbSnapshotArn());+ copy.setSnapshotType(source.getSnapshotType());+ copy.setSourceDbSnapshotIdentifier(source.getSourceDbSnapshotIdentifier());+ copy.setDbInstanceIdentifier(source.getDbInstanceIdentifier());+ copy.setSnapshotCreateTime(source.getSnapshotCreateTime());+ copy.setEngine(source.getEngine());+ copy.setEngineVersion(source.getEngineVersion());+ copy.setAllocatedStorage(source.getAllocatedStorage());+ copy.setStatus(source.getStatus());+ copy.setMasterUsername(source.getMasterUsername());+ copy.setMasterPassword(source.getMasterPassword());+ copy.setAvailabilityZone(source.getAvailabilityZone());+ copy.setVpcId(source.getVpcId());+ copy.setInstanceCreateTime(source.getInstanceCreateTime());+ copy.setPort(source.getPort());+ copy.setIamDatabaseAuthenticationEnabled(source.isIamDatabaseAuthenticationEnabled());+ copy.setDbiResourceId(source.getDbiResourceId());+ copy.setDbName(source.getDbName());+ copy.setDbInstanceClass(source.getDbInstanceClass());+ copy.setOptionGroupName(source.getOptionGroupName());+ copy.setKmsKeyId(source.getKmsKeyId());+ copy.setTags(new LinkedHashMap<>(source.getTags()));+ copy.setRestoreAccountIds(new ArrayList<>(source.getRestoreAccountIds()));+ return copy;+ }++ private SnapshotReference resolveSnapshotReference(String sourceIdentifier, String targetRegion) {+ String sourceId = sourceIdentifier;+ String sourceRegion = targetRegion;+ String sourceAccount = currentAccountId();+ if (sourceIdentifier != null && sourceIdentifier.startsWith("arn:")) {+ try {+ AwsArnUtils.Arn parsed = AwsArnUtils.parse(sourceIdentifier);+ if (!"aws".equals(parsed.partition()) || !"rds".equals(parsed.service())+ || !parsed.resource().startsWith("snapshot:")) {+ throw new IllegalArgumentException("not an RDS snapshot ARN");+ }+ sourceId = parsed.resource().substring("snapshot:".length());+ sourceRegion = parsed.region();+ sourceAccount = parsed.accountId();+ } catch (IllegalArgumentException e) {+ throw new AwsException("InvalidParameterValue",+ "SourceDBSnapshotIdentifier must be a snapshot identifier or ARN.", 400);+ }+ }+ if (!Objects.equals(sourceAccount, currentAccountId())) {+ throw new AwsException("DBSnapshotNotFound",+ "DBSnapshot " + sourceIdentifier + " not found.", 404);+ }+ DbSnapshot source = findSnapshotForScope(sourceAccount, sourceRegion, sourceId);+ if (source == null) {+ throw new AwsException("DBSnapshotNotFound",+ "DBSnapshot " + sourceIdentifier + " not found.", 404);+ }+ return new SnapshotReference(sourceAccount, sourceRegion, source);+ }++ private Optional<String> getSnapshotDataForScope(String accountId, String region, String snapshotId) {+ String key = dbResourceKey(region, snapshotId);+ if (snapshotData instanceof AccountAwareStorageBackend<String> aware) {+ return aware.getForAccount(accountId, key);+ }+ return snapshotData.get(key);+ }++ private void putSnapshotDataForScope(String accountId, String region, String snapshotId, String data) {+ String key = dbResourceKey(region, snapshotId);+ if (snapshotData instanceof AccountAwareStorageBackend<String> aware) {+ aware.putForAccount(accountId, key, data);+ } else {+ snapshotData.put(key, data);+ }+ }++ private void deleteSnapshotDataForScope(String accountId, String region, String snapshotId) {+ String key = dbResourceKey(region, snapshotId);+ if (snapshotData instanceof AccountAwareStorageBackend<String> aware) {+ aware.deleteForAccount(accountId, key);+ } else {+ snapshotData.delete(key);+ }+ }++ private record SnapshotReference(String accountId, String region, DbSnapshot snapshot) {}+public DbInstance restoreDbInstanceFromDbSnapshot(String instanceId, String snapshotId, String dbInstanceClass, String availabilityZone, boolean multiAz, String dbSubnetGroupName, java.util.List<String> vpcSecurityGroupIds, java.util.Map<String, String> tags) {return restoreDbInstanceFromDbSnapshot(instanceId, snapshotId, dbInstanceClass, availabilityZone,multiAz, dbSubnetGroupName, vpcSecurityGroupIds, tags, regionResolver.getDefaultRegion());@@ -6494,6 +6690,15 @@ public class RdsService implements Resettable, ResourceProvider {}}+ private void deleteSnapshotForScope(String accountId, String region, String snapshotId) {+ String key = dbResourceKey(region, snapshotId);+ if (snapshots instanceof AccountAwareStorageBackend<DbSnapshot> aware) {+ aware.deleteForAccount(accountId, key);+ } else {+ snapshots.delete(key);+ }+ }+private synchronized DbSubnetGroup findSubnetGroupForScope(String accountId, String region, String groupName) {String effectiveRegion = effectiveRegion(region);diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/model/DbSnapshot.java b/src/main/java/io/github/hectorvent/floci/services/rds/model/DbSnapshot.javaindex c627571bc0..37d0163574 100644--- a/src/main/java/io/github/hectorvent/floci/services/rds/model/DbSnapshot.java+++ b/src/main/java/io/github/hectorvent/floci/services/rds/model/DbSnapshot.java@@ -13,6 +13,8 @@ public class DbSnapshot {private String dbSnapshotIdentifier;private String dbSnapshotArn;+ private String snapshotType;+ private String sourceDbSnapshotIdentifier;private String dbInstanceIdentifier;private Instant snapshotCreateTime;private DatabaseEngine engine;@@ -29,6 +31,8 @@ public class DbSnapshot {private String dbiResourceId;private String dbName;private String dbInstanceClass;+ private String optionGroupName;+ private String kmsKeyId;private Map<String, String> tags = new LinkedHashMap<>();/** Account IDs authorized to copy/restore this snapshot; the "restore" DBSnapshotAttribute. */private List<String> restoreAccountIds = new ArrayList<>();@@ -63,6 +67,14 @@ public class DbSnapshot {public String getDbSnapshotArn() { return dbSnapshotArn; }public void setDbSnapshotArn(String dbSnapshotArn) { this.dbSnapshotArn = dbSnapshotArn; }+ public String getSnapshotType() { return snapshotType; }+ public void setSnapshotType(String snapshotType) { this.snapshotType = snapshotType; }++ public String getSourceDbSnapshotIdentifier() { return sourceDbSnapshotIdentifier; }+ public void setSourceDbSnapshotIdentifier(String sourceDbSnapshotIdentifier) {+ this.sourceDbSnapshotIdentifier = sourceDbSnapshotIdentifier;+ }+public String getDbInstanceIdentifier() { return dbInstanceIdentifier; }public void setDbInstanceIdentifier(String dbInstanceIdentifier) { this.dbInstanceIdentifier = dbInstanceIdentifier; }@@ -118,4 +130,10 @@ public class DbSnapshot {public String getDbInstanceClass() { return dbInstanceClass; }public void setDbInstanceClass(String dbInstanceClass) { this.dbInstanceClass = dbInstanceClass; }++ public String getOptionGroupName() { return optionGroupName; }+ public void setOptionGroupName(String optionGroupName) { this.optionGroupName = optionGroupName; }++ public String getKmsKeyId() { return kmsKeyId; }+ public void setKmsKeyId(String kmsKeyId) { this.kmsKeyId = kmsKeyId; }}diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.javaindex 6b0e8de551..454ca788a2 100644--- a/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java@@ -15,6 +15,7 @@ import io.github.hectorvent.floci.services.rds.model.DbProxy;import io.github.hectorvent.floci.services.rds.model.DbProxyAuth;import io.github.hectorvent.floci.services.rds.model.DbProxyTarget;import io.github.hectorvent.floci.services.rds.model.DbProxyTargetGroup;+import io.github.hectorvent.floci.services.rds.model.DbSnapshot;import io.github.hectorvent.floci.services.rds.model.DbSubnetGroup;import io.github.hectorvent.floci.services.rds.model.OptionGroup;import io.github.hectorvent.floci.services.rds.model.OptionGroupOption;@@ -1104,10 +1105,13 @@ class RdsQueryHandlerTest {@Testvoid describeDbSnapshots_returnsSnapshotListWith200() {- io.github.hectorvent.floci.services.rds.model.DbSnapshot snapshot = new io.github.hectorvent.floci.services.rds.model.DbSnapshot();+ DbSnapshot snapshot = new DbSnapshot();snapshot.setDbSnapshotIdentifier("mysnap");snapshot.setDbInstanceIdentifier("mydb");snapshot.setEngine(io.github.hectorvent.floci.services.rds.model.DatabaseEngine.POSTGRES);+ snapshot.setSnapshotType("manual");+ snapshot.setSourceDbSnapshotIdentifier(+ "arn:aws:rds:us-east-1:123456789012:snapshot:source");when(service.describeDbSnapshots(eq("mysnap"), eq("mydb"), isNull())).thenReturn(List.of(snapshot));MultivaluedMap<String, String> p = params();@@ -1120,6 +1124,8 @@ class RdsQueryHandlerTest {assertTrue(body.contains("<DescribeDBSnapshotsResult>"));assertTrue(body.contains("<DBSnapshotIdentifier>mysnap</DBSnapshotIdentifier>"));assertTrue(body.contains("<DBInstanceIdentifier>mydb</DBInstanceIdentifier>"));+ assertTrue(body.contains("<SnapshotType>manual</SnapshotType>"));+ assertTrue(body.contains("<SourceDBSnapshotIdentifier>arn:aws:rds:us-east-1:123456789012:snapshot:source</SourceDBSnapshotIdentifier>"));}@Test@@ -1835,6 +1841,78 @@ class RdsQueryHandlerTest {assertTrue(body.contains("<Value>platform</Value>"));}+ @Test+ void deleteDbSnapshot_success() {+ DbSnapshot snapshot = new DbSnapshot();+ snapshot.setDbSnapshotIdentifier("mysnap");+ snapshot.setStatus("deleted");+ when(service.deleteDbSnapshot(eq("mysnap"), isNull())).thenReturn(snapshot);++ MultivaluedMap<String, String> p = params();+ p.add("DBSnapshotIdentifier", "mysnap");+ Response response = handler.handle("DeleteDBSnapshot", p);++ assertEquals(200, response.getStatus());+ String body = (String) response.getEntity();+ assertTrue(body.contains("<DeleteDBSnapshotResult>"));+ assertTrue(body.contains("<DBSnapshotIdentifier>mysnap</DBSnapshotIdentifier>"));+ assertTrue(body.contains("<Status>deleted</Status>"));+ verify(service).deleteDbSnapshot("mysnap", null);+ }++ @Test+ void copyDbSnapshot_forwardsSourceTagsAndOverrides() {+ DbSnapshot snapshot = new DbSnapshot();+ snapshot.setDbSnapshotIdentifier("copy");+ snapshot.setSnapshotType("manual");+ snapshot.setSourceDbSnapshotIdentifier(+ "arn:aws:rds:us-east-1:123456789012:snapshot:source");+ when(service.copyDbSnapshot(eq("source"), eq("copy"), eq(true),+ eq(Map.of("owner", "platform")), eq("custom-options"), eq("kms-key"), isNull()))+ .thenReturn(snapshot);++ MultivaluedMap<String, String> p = params();+ p.add("SourceDBSnapshotIdentifier", "source");+ p.add("TargetDBSnapshotIdentifier", "copy");+ p.add("CopyTags", "true");+ p.add("OptionGroupName", "custom-options");+ p.add("KmsKeyId", "kms-key");+ p.add("Tags.Tag.1.Key", "owner");+ p.add("Tags.Tag.1.Value", "platform");+ Response response = handler.handle("CopyDBSnapshot", p);++ assertEquals(200, response.getStatus());+ String body = (String) response.getEntity();+ assertTrue(body.contains("<CopyDBSnapshotResult>"));+ assertTrue(body.contains("<SnapshotType>manual</SnapshotType>"));+ assertTrue(body.contains("<SourceDBSnapshotIdentifier>arn:aws:rds:us-east-1:123456789012:snapshot:source</SourceDBSnapshotIdentifier>"));+ verify(service).copyDbSnapshot("source", "copy", true,+ Map.of("owner", "platform"), "custom-options", "kms-key", null);+ }++ @Test+ void modifyDbSnapshot_forwardsMutableFields() {+ DbSnapshot snapshot = new DbSnapshot();+ snapshot.setDbSnapshotIdentifier("mysnap");+ snapshot.setEngineVersion("14");+ snapshot.setOptionGroupName("new-options");+ when(service.modifyDbSnapshot(eq("mysnap"), eq("14"), eq("new-options"), isNull()))+ .thenReturn(snapshot);++ MultivaluedMap<String, String> p = params();+ p.add("DBSnapshotIdentifier", "mysnap");+ p.add("EngineVersion", "14");+ p.add("OptionGroupName", "new-options");+ Response response = handler.handle("ModifyDBSnapshot", p);++ assertEquals(200, response.getStatus());+ String body = (String) response.getEntity();+ assertTrue(body.contains("<ModifyDBSnapshotResult>"));+ assertTrue(body.contains("<EngineVersion>14</EngineVersion>"));+ assertTrue(body.contains("<OptionGroupName>new-options</OptionGroupName>"));+ verify(service).modifyDbSnapshot("mysnap", "14", "new-options", null);+ }+@Testvoid describeDbSnapshotAttributes_returnsRestoreAttribute() {io.github.hectorvent.floci.services.rds.model.DbSnapshot snapshot = new io.github.hectorvent.floci.services.rds.model.DbSnapshot();diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.javaindex cdd1af7141..69b22af980 100644--- a/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java@@ -28,6 +28,7 @@ import io.github.hectorvent.floci.services.rds.model.DbProxy;import io.github.hectorvent.floci.services.rds.model.DbProxyAuth;import io.github.hectorvent.floci.services.rds.model.DbProxyTarget;import io.github.hectorvent.floci.services.rds.model.DbProxyTargetGroup;+import io.github.hectorvent.floci.services.rds.model.DbSnapshot;import io.github.hectorvent.floci.services.rds.model.DbSubnetGroup;import io.github.hectorvent.floci.services.rds.model.GlobalCluster;import io.github.hectorvent.floci.services.rds.model.GlobalClusterMember;@@ -2858,6 +2859,92 @@ class RdsServiceTest {verify(containerManager).createPostgresSnapshot(any(), eq("admin"));}+ @Test+ void deleteDbSnapshotReturnsDeletedSnapshotAndRemovesItsData() {+ rdsService.createDbInstance("mydb", "postgres", "13",+ "admin", "password", "dbname", "db.t3.micro",+ 20, false, null, null, null, null, false);+ when(containerManager.createPostgresSnapshot(any(), eq("admin"))).thenReturn("MOCK_DUMP_DATA");+ rdsService.createDbSnapshot("mysnap", "mydb");++ DbSnapshot deleted = rdsService.deleteDbSnapshot("mysnap", "us-east-1");++ assertEquals("deleted", deleted.getStatus());+ assertThrows(AwsException.class,+ () -> rdsService.describeDbSnapshots("mysnap", null, "us-east-1"));+ assertThrows(AwsException.class,+ () -> rdsService.restoreDbInstanceFromDbSnapshot(+ "restored", "mysnap", "db.t3.micro", null, false,+ null, null, Map.of(), "us-east-1"));+ }++ @Test+ void copyDbSnapshotCopiesDataTagsAndSourceArn() {+ rdsService.createDbInstance("mydb", "postgres", "13",+ "admin", "password", "dbname", "db.t3.micro",+ 20, false, null, null, null, null, false);+ when(containerManager.createPostgresSnapshot(any(), eq("admin"))).thenReturn("MOCK_DUMP_DATA");+ DbSnapshot source = rdsService.createDbSnapshot("source", "mydb", Map.of("owner", "platform"));+ rdsService.modifyDbSnapshotAttribute(+ "source", "restore", List.of("123456789012"), List.of(), "us-east-1");++ DbSnapshot copy = rdsService.copyDbSnapshot(+ source.getDbSnapshotArn(), "copy", true,+ Map.of("Name", "copy"), "custom-options", "kms-key", "us-east-1");++ assertEquals("copy", copy.getDbSnapshotIdentifier());+ assertEquals("manual", copy.getSnapshotType());+ assertEquals(source.getDbSnapshotArn(), copy.getSourceDbSnapshotIdentifier());+ assertEquals(Map.of("owner", "platform", "Name", "copy"), copy.getTags());+ assertEquals("custom-options", copy.getOptionGroupName());+ assertEquals("kms-key", copy.getKmsKeyId());+ assertTrue(copy.getRestoreAccountIds().isEmpty());++ rdsService.restoreDbInstanceFromDbSnapshot(+ "restored", "copy", "db.t3.micro", null, false,+ null, null, Map.of(), "us-east-1");+ verify(containerManager).restorePostgresSnapshot(any(), eq("admin"), eq("MOCK_DUMP_DATA"));+ }++ @Test+ void copyDbSnapshotRejectsDuplicateTargetsAndUnavailableSources() {+ rdsService.createDbInstance("mydb", "postgres", "13",+ "admin", "password", "dbname", "db.t3.micro",+ 20, false, null, null, null, null, false);+ when(containerManager.createPostgresSnapshot(any(), eq("admin"))).thenReturn("MOCK_DUMP_DATA");+ DbSnapshot source = rdsService.createDbSnapshot("source", "mydb");+ rdsService.copyDbSnapshot("source", "copy", false, Map.of(), null, null, "us-east-1");++ AwsException duplicate = assertThrows(AwsException.class, () ->+ rdsService.copyDbSnapshot(source.getDbSnapshotArn(), "copy", false,+ Map.of(), null, null, "us-east-1"));+ assertEquals("DBSnapshotAlreadyExists", duplicate.getErrorCode());++ source.setStatus("creating");+ AwsException unavailable = assertThrows(AwsException.class, () ->+ rdsService.copyDbSnapshot("source", "other", false,+ Map.of(), null, null, "us-east-1"));+ assertEquals("InvalidDBSnapshotState", unavailable.getErrorCode());+ }++ @Test+ void modifyDbSnapshotUpdatesEngineVersionAndOptionGroup() {+ rdsService.createDbInstance("mydb", "postgres", "13",+ "admin", "password", "dbname", "db.t3.micro",+ 20, false, null, null, null, null, false);+ when(containerManager.createPostgresSnapshot(any(), eq("admin"))).thenReturn("MOCK_DUMP_DATA");+ rdsService.createDbSnapshot("mysnap", "mydb");++ DbSnapshot modified = rdsService.modifyDbSnapshot(+ "mysnap", "14", "new-options", "us-east-1");++ assertEquals("14", modified.getEngineVersion());+ assertEquals("new-options", modified.getOptionGroupName());+ AwsException missingChange = assertThrows(AwsException.class, () ->+ rdsService.modifyDbSnapshot("mysnap", null, null, "us-east-1"));+ assertEquals("InvalidParameterCombination", missingChange.getErrorCode());+ }+@Testvoid createDbSnapshotStoresTagsGivenAtCreation() {rdsService.createDbInstance("mydb", "postgres", "13",