From 0f4865e554f8ea94f2544cea732d7e867faa3755 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 17 Sep 2026 15:47:57 +0100 Subject: [PATCH] feat(rds): copy and reset parameter groups and copy option groups (#3781) Add CopyDBParameterGroup, CopyDBClusterParameterGroup, CopyOptionGroup, ResetDBParameterGroup and ResetDBClusterParameterGroup. The groups, their overrides and options were already modelled and served by the create, modify, describe and delete actions; these five answered UnsupportedOperation. A copy resolves its source by name or ARN, creates the target through the existing create path so the already-exists check and the ARN come from one place, and copies the family and overrides, or the engine, major version and options for an option group, with any Tags applied. Source and target names must pass AWS's identifier rule, which is how AWS refuses to copy a managed default group: its name carries periods, and the answer is InvalidParameterValue with the identifier message. A reset drops the named overrides or all of them; ResetAllParameters together with a Parameters list is InvalidParameterCombination, and a managed default cluster group answers InvalidDBParameterGroupState as Modify does. Responses use the model's result wrappers and shapes. The action table in docs/services/rds.md is regenerated and its note that CopyOptionGroup is unimplemented removed. Closes #3777 --- docs/services/rds.md | 7 +- .../floci/services/rds/RdsQueryHandler.java | 124 +++++++ .../floci/services/rds/RdsService.java | 136 +++++++ ...arameterGroupCopyResetIntegrationTest.java | 350 ++++++++++++++++++ 4 files changed, 616 insertions(+), 1 deletion(-) create mode 100644 src/test/java/io/github/hectorvent/floci/services/rds/RdsParameterGroupCopyResetIntegrationTest.java diff --git a/docs/services/rds.md b/docs/services/rds.md index 1ba13ca52e..8ad7ea705a 100644 --- a/docs/services/rds.md +++ b/docs/services/rds.md @@ -32,13 +32,18 @@ RDS Data API (`rds-data`) is documented separately because it uses REST JSON rou | `DescribeDBParameterGroups` | List parameter groups | | `DeleteDBParameterGroup` | Delete a parameter group | | `ModifyDBParameterGroup` | Update parameter group settings | +| `CopyDBParameterGroup` | Copy a parameter group (by name or ARN) with its family and parameter overrides into a new group | +| `ResetDBParameterGroup` | Reset named parameters, or all of them, to engine defaults | | `DescribeDBParameters` | List parameters in a group | | `CreateDBClusterParameterGroup` | Create an Aurora-compatible cluster parameter group | | `DescribeDBClusterParameterGroups` | List cluster parameter groups | | `DeleteDBClusterParameterGroup` | Delete a cluster parameter group | | `ModifyDBClusterParameterGroup` | Update cluster parameter group settings | +| `CopyDBClusterParameterGroup` | Copy a cluster parameter group into a new group; a managed `default.*` group cannot be copied, as on AWS | +| `ResetDBClusterParameterGroup` | Reset named cluster parameters, or all of them, to engine defaults | | `DescribeDBClusterParameters` | List parameters in a cluster group | | `CreateOptionGroup` | Create an option group | +| `CopyOptionGroup` | Copy an option group with its engine, major version and options into a new group | | `DescribeOptionGroups` | List option groups, including the implicit `default:` groups | | `ModifyOptionGroup` | Add, update, or remove options in an option group | | `DeleteOptionGroup` | Delete an option group | @@ -306,7 +311,7 @@ Known gaps, all deliberate: | Behavior | Status | |---|---| -| `CopyOptionGroup`, `DescribeOptionGroupOptions` | Not implemented — separate actions, not part of option group CRUD | +| `DescribeOptionGroupOptions` | Not implemented: the per-engine option catalog is not modeled | | `OptionGroupQuotaExceededFault` (AWS caps an account at 20 groups) | Not enforced — capping a local emulator would only get in a test's way | | `OptionSetting` metadata (`DataType`, `ApplyType`, `AllowedValues`, `DefaultValue`, `Description`) | Omitted — it would require the per-engine option catalog `DescribeOptionGroupOptions` serves | | `MaxRecords` / `Marker` pagination | Every group is returned in one page, as with every other RDS list action | diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java index 802b4e5976..8ee61ba762 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 @@ -31,6 +31,7 @@ import jakarta.ws.rs.core.MultivaluedMap; import jakarta.ws.rs.core.Response; import org.jboss.logging.Logger; +import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; @@ -85,13 +86,18 @@ public class RdsQueryHandler { case "DescribeDBParameterGroups" -> handleDescribeDbParameterGroups(params, region); case "DeleteDBParameterGroup" -> handleDeleteDbParameterGroup(params, region); case "ModifyDBParameterGroup" -> handleModifyDbParameterGroup(params, region); + case "CopyDBParameterGroup" -> handleCopyDbParameterGroup(params, region); + case "ResetDBParameterGroup" -> handleResetDbParameterGroup(params, region); case "DescribeDBParameters" -> handleDescribeDbParameters(params, region); case "CreateDBClusterParameterGroup" -> handleCreateDbClusterParameterGroup(params, region); case "DescribeDBClusterParameterGroups" -> handleDescribeDbClusterParameterGroups(params, region); case "DeleteDBClusterParameterGroup" -> handleDeleteDbClusterParameterGroup(params, region); case "ModifyDBClusterParameterGroup" -> handleModifyDbClusterParameterGroup(params, region); + case "CopyDBClusterParameterGroup" -> handleCopyDbClusterParameterGroup(params, region); + case "ResetDBClusterParameterGroup" -> handleResetDbClusterParameterGroup(params, region); case "DescribeDBClusterParameters" -> handleDescribeDbClusterParameters(params, region); case "CreateOptionGroup" -> handleCreateOptionGroup(params, region); + case "CopyOptionGroup" -> handleCopyOptionGroup(params, region); case "DescribeOptionGroups" -> handleDescribeOptionGroups(params, region); case "ModifyOptionGroup" -> handleModifyOptionGroup(params, region); case "DeleteOptionGroup" -> handleDeleteOptionGroup(params, region); @@ -806,6 +812,64 @@ public class RdsQueryHandler { return parameters; } + private Response handleCopyDbParameterGroup( + MultivaluedMap params, String region) { + String source = params.getFirst("SourceDBParameterGroupIdentifier"); + String target = params.getFirst("TargetDBParameterGroupIdentifier"); + String description = params.getFirst("TargetDBParameterGroupDescription"); + Response missing = firstMissingParam( + "SourceDBParameterGroupIdentifier", source, + "TargetDBParameterGroupIdentifier", target, + "TargetDBParameterGroupDescription", description); + if (missing != null) { + return missing; + } + try { + DbParameterGroup group = service.copyDbParameterGroup(source, target, description, region); + Map tags = parseTags(params); + if (!tags.isEmpty()) { + service.addTagsToResource(group.getDbParameterGroupArn(), tags, region); + } + return Response.ok(AwsQueryResponse.envelope("CopyDBParameterGroup", AwsNamespaces.RDS, + paramGroupXml(group))).build(); + } catch (AwsException e) { + return AwsQueryResponse.error(e.getErrorCode(), e.getMessage(), AwsNamespaces.RDS, e.getHttpStatus()); + } + } + + private Response handleResetDbParameterGroup( + MultivaluedMap params, String region) { + String name = params.getFirst("DBParameterGroupName"); + if (name == null || name.isBlank()) { + return AwsQueryResponse.error("InvalidParameterValue", "DBParameterGroupName is required.", AwsNamespaces.RDS, 400); + } + try { + DbParameterGroup group = service.resetDbParameterGroup(name, + Boolean.parseBoolean(params.getFirst("ResetAllParameters")), parameterNames(params), region); + String result = new XmlBuilder() + .elem("DBParameterGroupName", group.getDbParameterGroupName()) + .build(); + return Response.ok(AwsQueryResponse.envelope("ResetDBParameterGroup", AwsNamespaces.RDS, result)).build(); + } catch (AwsException e) { + return AwsQueryResponse.error(e.getErrorCode(), e.getMessage(), AwsNamespaces.RDS, e.getHttpStatus()); + } + } + + /** The parameter names of a modify or reset request, in either list encoding. */ + private static List parameterNames(MultivaluedMap params) { + List names = new ArrayList<>(); + for (String prefix : List.of("Parameters.Parameter", "Parameters.member")) { + for (int n = 1; ; n++) { + String paramName = params.getFirst(prefix + "." + n + ".ParameterName"); + if (paramName == null) { + break; + } + names.add(paramName); + } + } + return names; + } + private Response handleDescribeDbParameters( MultivaluedMap params, String region) { String name = params.getFirst("DBParameterGroupName"); @@ -903,6 +967,49 @@ public class RdsQueryHandler { } } + private Response handleCopyDbClusterParameterGroup( + MultivaluedMap params, String region) { + String source = params.getFirst("SourceDBClusterParameterGroupIdentifier"); + String target = params.getFirst("TargetDBClusterParameterGroupIdentifier"); + String description = params.getFirst("TargetDBClusterParameterGroupDescription"); + Response missing = firstMissingParam( + "SourceDBClusterParameterGroupIdentifier", source, + "TargetDBClusterParameterGroupIdentifier", target, + "TargetDBClusterParameterGroupDescription", description); + if (missing != null) { + return missing; + } + try { + DbClusterParameterGroup group = service.copyDbClusterParameterGroup(source, target, description, region); + Map tags = parseTags(params); + if (!tags.isEmpty()) { + service.addTagsToResource(group.getDbClusterParameterGroupArn(), tags, region); + } + return Response.ok(AwsQueryResponse.envelope("CopyDBClusterParameterGroup", AwsNamespaces.RDS, + clusterParamGroupXml(group))).build(); + } catch (AwsException e) { + return AwsQueryResponse.error(e.getErrorCode(), e.getMessage(), AwsNamespaces.RDS, e.getHttpStatus()); + } + } + + private Response handleResetDbClusterParameterGroup( + MultivaluedMap params, String region) { + String name = params.getFirst("DBClusterParameterGroupName"); + if (name == null || name.isBlank()) { + return AwsQueryResponse.error("InvalidParameterValue", "DBClusterParameterGroupName is required.", AwsNamespaces.RDS, 400); + } + try { + DbClusterParameterGroup group = service.resetDbClusterParameterGroup(name, + Boolean.parseBoolean(params.getFirst("ResetAllParameters")), parameterNames(params), region); + String result = new XmlBuilder() + .elem("DBClusterParameterGroupName", group.getDbClusterParameterGroupName()) + .build(); + return Response.ok(AwsQueryResponse.envelope("ResetDBClusterParameterGroup", AwsNamespaces.RDS, result)).build(); + } catch (AwsException e) { + return AwsQueryResponse.error(e.getErrorCode(), e.getMessage(), AwsNamespaces.RDS, e.getHttpStatus()); + } + } + private Response handleDescribeDbClusterParameters( MultivaluedMap params, String region) { String name = params.getFirst("DBClusterParameterGroupName"); @@ -948,6 +1055,23 @@ public class RdsQueryHandler { "CreateOptionGroup", AwsNamespaces.RDS, optionGroupXml(group))).build(); } + private Response handleCopyOptionGroup( + MultivaluedMap params, String region) { + String source = params.getFirst("SourceOptionGroupIdentifier"); + String target = params.getFirst("TargetOptionGroupIdentifier"); + String description = params.getFirst("TargetOptionGroupDescription"); + Response missing = firstMissingParam( + "SourceOptionGroupIdentifier", source, + "TargetOptionGroupIdentifier", target, + "TargetOptionGroupDescription", description); + if (missing != null) { + return missing; + } + OptionGroup group = service.copyOptionGroup(source, target, description, parseTags(params), region); + return Response.ok(AwsQueryResponse.envelope( + "CopyOptionGroup", AwsNamespaces.RDS, optionGroupXml(group))).build(); + } + private Response handleDescribeOptionGroups( MultivaluedMap params, String region) { Collection result = service.listOptionGroups( 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.java index bf8ffb56f6..17eb0ea492 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 @@ -3427,6 +3427,78 @@ public class RdsService implements Resettable, ResourceProvider { return group; } + /** + * CopyDBParameterGroup: a new group with the source's family and parameter overrides. The + * source may be named by identifier or ARN; the target must not exist yet. Both names must + * be valid identifiers, which is how AWS refuses to copy a {@code default.*} group: its name + * contains periods, and the reference says to create a custom group for the family instead. + */ + public DbParameterGroup copyDbParameterGroup( + String sourceIdentifier, String targetName, String targetDescription, String region) { + String effectiveRegion = effectiveRegion(region); + String sourceName = groupNameFromIdentifier(sourceIdentifier); + requireParameterGroupIdentifier(sourceName); + requireParameterGroupIdentifier(targetName); + DbParameterGroup source = getDbParameterGroup(sourceName, effectiveRegion); + DbParameterGroup target = createDbParameterGroup( + targetName, source.getDbParameterGroupFamily(), targetDescription, effectiveRegion); + target.getParameters().putAll(source.getParameters()); + putParameterGroupForRegion(targetName, effectiveRegion, target); + return target; + } + + /** + * ResetDBParameterGroup: drops the overrides for the named parameters, or every override when + * {@code resetAllParameters} is set, so the group answers with engine defaults again. + */ + public DbParameterGroup resetDbParameterGroup( + String name, boolean resetAllParameters, List parameterNames, String region) { + String effectiveRegion = effectiveRegion(region); + DbParameterGroup group = getDbParameterGroup(name, effectiveRegion); + resetParameters(group.getParameters(), resetAllParameters, parameterNames); + putParameterGroupForRegion(name, effectiveRegion, group); + return group; + } + + /** + * The identifier rule AWS applies to a copy's source and target parameter group names. A + * managed {@code default.*} group fails it on the period, which is the documented way a + * default group cannot be copied. + */ + private static void requireParameterGroupIdentifier(String name) { + if (name == null || !name.matches("[A-Za-z](?:[A-Za-z0-9]|-(?!-))*") || name.endsWith("-")) { + throw new AwsException("InvalidParameterValue", + "The parameter DBParameterGroupName is not a valid identifier. Identifiers must begin with a " + + "letter; must contain only ASCII letters, digits, and hyphens; and must not end with " + + "a hyphen or contain two consecutive hyphens.", 400); + } + } + + /** + * The group name behind an identifier that may be an ARN + * ({@code arn:aws:rds:region:account:pg:name}); names cannot contain a colon. + */ + private static String groupNameFromIdentifier(String identifier) { + if (identifier != null && identifier.startsWith("arn:")) { + return identifier.substring(identifier.lastIndexOf(':') + 1); + } + return identifier; + } + + private static void resetParameters(Map overrides, boolean resetAllParameters, + List parameterNames) { + boolean namesGiven = parameterNames != null && !parameterNames.isEmpty(); + if (resetAllParameters && namesGiven) { + throw new AwsException("InvalidParameterCombination", + "You can't specify Parameters when ResetAllParameters is enabled.", 400); + } + if (namesGiven) { + parameterNames.forEach(overrides::remove); + } else { + overrides.clear(); + } + } + public DbSubnetGroup getDbSubnetGroup(String name) { return getDbSubnetGroup(name, regionResolver.getDefaultRegion()); } @@ -3632,6 +3704,39 @@ public class RdsService implements Resettable, ResourceProvider { return group; } + /** + * CopyDBClusterParameterGroup: a new group with the source's family and parameter overrides. + * The source is a customer group named by identifier or ARN; a managed {@code default.*} + * group fails the identifier rule, as on AWS. The target must not exist yet. + */ + public DbClusterParameterGroup copyDbClusterParameterGroup( + String sourceIdentifier, String targetName, String targetDescription, String region) { + String effectiveRegion = effectiveRegion(region); + String sourceName = groupNameFromIdentifier(sourceIdentifier); + requireParameterGroupIdentifier(sourceName); + requireParameterGroupIdentifier(targetName); + DbClusterParameterGroup source = getDbClusterParameterGroup(sourceName, effectiveRegion); + DbClusterParameterGroup target = createDbClusterParameterGroup( + targetName, source.getDbParameterGroupFamily(), targetDescription, effectiveRegion); + target.getParameters().putAll(source.getParameters()); + putClusterParameterGroupForRegion(targetName, effectiveRegion, target); + return target; + } + + /** ResetDBClusterParameterGroup; the managed {@code default.*} groups cannot be reset. */ + public DbClusterParameterGroup resetDbClusterParameterGroup( + String name, boolean resetAllParameters, List parameterNames, String region) { + String effectiveRegion = effectiveRegion(region); + if (managedClusterParameterGroup(name) != null) { + throw new AwsException("InvalidDBParameterGroupState", + "The default DB cluster parameter group cannot be modified.", 400); + } + DbClusterParameterGroup group = getDbClusterParameterGroup(name, effectiveRegion); + resetParameters(group.getParameters(), resetAllParameters, parameterNames); + putClusterParameterGroupForRegion(name, effectiveRegion, group); + return group; + } + // ── Option Groups ───────────────────────────────────────────────────────── public OptionGroup createOptionGroup( @@ -3660,6 +3765,37 @@ public class RdsService implements Resettable, ResourceProvider { return group; } + /** + * CopyOptionGroup: a new group for the source's engine and major version carrying copies of + * its options. The source may be a customer group or a managed {@code default:*} group, named + * by identifier or ARN; the target must not exist yet. + */ + public OptionGroup copyOptionGroup(String sourceIdentifier, String targetName, + String targetDescription, Map tags, String region) { + String effectiveRegion = effectiveRegion(region); + OptionGroup source = getOptionGroup(groupNameFromIdentifier(sourceIdentifier), effectiveRegion); + OptionGroup target = createOptionGroup(targetName, source.getEngineName(), + source.getMajorEngineVersion(), targetDescription, tags, effectiveRegion); + for (OptionGroupOption option : source.getOptions()) { + target.getOptions().add(copyOption(option)); + } + putOptionGroupForRegion(targetName, effectiveRegion, target); + return target; + } + + private static OptionGroupOption copyOption(OptionGroupOption source) { + OptionGroupOption copy = new OptionGroupOption(source.getOptionName()); + copy.setOptionDescription(source.getOptionDescription()); + copy.setOptionVersion(source.getOptionVersion()); + copy.setPort(source.getPort()); + copy.setPersistent(source.isPersistent()); + copy.setPermanent(source.isPermanent()); + copy.setOptionSettings(new LinkedHashMap<>(source.getOptionSettings())); + copy.setVpcSecurityGroupMemberships(new ArrayList<>(source.getVpcSecurityGroupMemberships())); + copy.setDbSecurityGroupMemberships(new ArrayList<>(source.getDbSecurityGroupMemberships())); + return copy; + } + public OptionGroup getOptionGroup(String name) { return getOptionGroup(name, regionResolver.getDefaultRegion()); } diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsParameterGroupCopyResetIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsParameterGroupCopyResetIntegrationTest.java new file mode 100644 index 0000000000..dd8845a770 --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsParameterGroupCopyResetIntegrationTest.java @@ -0,0 +1,350 @@ +package io.github.hectorvent.floci.services.rds; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.specification.RequestSpecification; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import static io.restassured.RestAssured.given; +import static io.restassured.http.ContentType.URLENC; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.not; + +/** + * CopyDBParameterGroup, CopyDBClusterParameterGroup, CopyOptionGroup, ResetDBParameterGroup and + * ResetDBClusterParameterGroup: a copy carries the source's family (or engine and major version), + * overrides and options into a group that must not exist yet; a reset drops overrides so the + * group answers with engine defaults again. + */ +@QuarkusTest +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +class RdsParameterGroupCopyResetIntegrationTest { + + private static final String SOURCE_PG = "copy-test-source-pg"; + private static final String TARGET_PG = "copy-test-target-pg"; + private static final String SOURCE_PG_ARN = "arn:aws:rds:us-east-1:000000000000:pg:" + SOURCE_PG; + private static final String SOURCE_CLUSTER_PG = "copy-test-source-cluster-pg"; + private static final String TARGET_CLUSTER_PG = "copy-test-target-cluster-pg"; + private static final String FROM_DEFAULT_CLUSTER_PG = "copy-test-from-default-cluster-pg"; + private static final String SOURCE_OG = "copy-test-source-og"; + private static final String TARGET_OG = "copy-test-target-og"; + + private static final String AUTH = + "AWS4-HMAC-SHA256 Credential=test/20260615/us-east-1/rds/aws4_request, " + + "SignedHeaders=content-type;host, Signature=test"; + + private static RequestSpecification query(String action) { + return given().header("Authorization", AUTH) + .contentType(URLENC) + .formParam("Action", action) + .formParam("Version", "2014-10-31"); + } + + @Test + @Order(1) + void copyDbParameterGroupCarriesFamilyOverridesAndTags() { + query("CreateDBParameterGroup") + .formParam("DBParameterGroupName", SOURCE_PG) + .formParam("DBParameterGroupFamily", "postgres15") + .formParam("Description", "source") + .when().post("/").then().statusCode(200); + query("ModifyDBParameterGroup") + .formParam("DBParameterGroupName", SOURCE_PG) + .formParam("Parameters.member.1.ParameterName", "max_connections") + .formParam("Parameters.member.1.ParameterValue", "250") + .formParam("Parameters.member.2.ParameterName", "log_min_duration_statement") + .formParam("Parameters.member.2.ParameterValue", "500") + .when().post("/").then().statusCode(200); + + // The source may be named by ARN, as the API reference allows. + query("CopyDBParameterGroup") + .formParam("SourceDBParameterGroupIdentifier", SOURCE_PG_ARN) + .formParam("TargetDBParameterGroupIdentifier", TARGET_PG) + .formParam("TargetDBParameterGroupDescription", "copied") + .formParam("Tags.Tag.1.Key", "env") + .formParam("Tags.Tag.1.Value", "prod") + .when().post("/") + .then() + .statusCode(200) + .body(containsString("")) + .body(containsString("" + TARGET_PG + "")) + .body(containsString("postgres15")) + .body(containsString("copied")) + .body(containsString(":pg:" + TARGET_PG + "")); + + query("DescribeDBParameters") + .formParam("DBParameterGroupName", TARGET_PG) + .when().post("/") + .then() + .statusCode(200) + .body(containsString("max_connections")) + .body(containsString("250")) + .body(containsString("log_min_duration_statement")); + + query("ListTagsForResource") + .formParam("ResourceName", "arn:aws:rds:us-east-1:000000000000:pg:" + TARGET_PG) + .when().post("/") + .then() + .statusCode(200) + .body(containsString("env")) + .body(containsString("prod")); + } + + @Test + @Order(2) + void copyIsIndependentOfItsSourceAndRefusesAnExistingTarget() { + query("ModifyDBParameterGroup") + .formParam("DBParameterGroupName", SOURCE_PG) + .formParam("Parameters.member.1.ParameterName", "max_connections") + .formParam("Parameters.member.1.ParameterValue", "999") + .when().post("/").then().statusCode(200); + + query("DescribeDBParameters") + .formParam("DBParameterGroupName", TARGET_PG) + .when().post("/") + .then() + .statusCode(200) + .body(containsString("250")) + .body(not(containsString("999"))); + + query("CopyDBParameterGroup") + .formParam("SourceDBParameterGroupIdentifier", SOURCE_PG) + .formParam("TargetDBParameterGroupIdentifier", TARGET_PG) + .formParam("TargetDBParameterGroupDescription", "again") + .when().post("/") + .then() + .statusCode(400) + .body(containsString("DBParameterGroupAlreadyExists")); + + query("CopyDBParameterGroup") + .formParam("SourceDBParameterGroupIdentifier", "no-such-group") + .formParam("TargetDBParameterGroupIdentifier", "copy-test-never-created") + .formParam("TargetDBParameterGroupDescription", "x") + .when().post("/") + .then() + .statusCode(404) + .body(containsString("DBParameterGroupNotFound")); + + query("CopyDBParameterGroup") + .formParam("SourceDBParameterGroupIdentifier", SOURCE_PG) + .formParam("TargetDBParameterGroupIdentifier", "copy-test-never-created") + .when().post("/") + .then() + .statusCode(400) + .body(containsString("TargetDBParameterGroupDescription")); + + query("CopyDBParameterGroup") + .formParam("SourceDBParameterGroupIdentifier", "default.postgres15") + .formParam("TargetDBParameterGroupIdentifier", "copy-test-never-created") + .formParam("TargetDBParameterGroupDescription", "x") + .when().post("/") + .then() + .statusCode(400) + .body(containsString("InvalidParameterValue")) + .body(containsString("is not a valid identifier")); + } + + @Test + @Order(3) + void resetDbParameterGroupDropsNamedOverridesOrAllOfThem() { + // Named the way `aws rds reset-db-parameter-group --parameters ...` puts it on the wire. + query("ResetDBParameterGroup") + .formParam("DBParameterGroupName", TARGET_PG) + .formParam("Parameters.Parameter.1.ParameterName", "max_connections") + .formParam("Parameters.Parameter.1.ApplyMethod", "immediate") + .when().post("/") + .then() + .statusCode(200) + .body(containsString("")) + .body(containsString("" + TARGET_PG + "")); + + query("DescribeDBParameters") + .formParam("DBParameterGroupName", TARGET_PG) + .when().post("/") + .then() + .statusCode(200) + .body(not(containsString("max_connections"))) + .body(containsString("log_min_duration_statement")); + + query("ResetDBParameterGroup") + .formParam("DBParameterGroupName", TARGET_PG) + .formParam("ResetAllParameters", "true") + .when().post("/") + .then() + .statusCode(200); + + query("DescribeDBParameters") + .formParam("DBParameterGroupName", TARGET_PG) + .when().post("/") + .then() + .statusCode(200) + .body(not(containsString(""))); + + query("ResetDBParameterGroup") + .formParam("DBParameterGroupName", TARGET_PG) + .formParam("ResetAllParameters", "true") + .formParam("Parameters.Parameter.1.ParameterName", "max_connections") + .when().post("/") + .then() + .statusCode(400) + .body(containsString("InvalidParameterCombination")); + + query("ResetDBParameterGroup") + .formParam("DBParameterGroupName", "no-such-group") + .when().post("/") + .then() + .statusCode(404) + .body(containsString("DBParameterGroupNotFound")); + } + + @Test + @Order(4) + void clusterParameterGroupCopyAndResetBehaveTheSameWay() { + query("CreateDBClusterParameterGroup") + .formParam("DBClusterParameterGroupName", SOURCE_CLUSTER_PG) + .formParam("DBParameterGroupFamily", "aurora-postgresql15") + .formParam("Description", "source") + .when().post("/").then().statusCode(200); + query("ModifyDBClusterParameterGroup") + .formParam("DBClusterParameterGroupName", SOURCE_CLUSTER_PG) + .formParam("Parameters.member.1.ParameterName", "rds.force_ssl") + .formParam("Parameters.member.1.ParameterValue", "1") + .when().post("/").then().statusCode(200); + + query("CopyDBClusterParameterGroup") + .formParam("SourceDBClusterParameterGroupIdentifier", SOURCE_CLUSTER_PG) + .formParam("TargetDBClusterParameterGroupIdentifier", TARGET_CLUSTER_PG) + .formParam("TargetDBClusterParameterGroupDescription", "copied") + .when().post("/") + .then() + .statusCode(200) + .body(containsString("")) + .body(containsString("" + TARGET_CLUSTER_PG + "")) + .body(containsString("aurora-postgresql15")) + .body(containsString(":cluster-pg:" + TARGET_CLUSTER_PG + "")); + + query("DescribeDBClusterParameters") + .formParam("DBClusterParameterGroupName", TARGET_CLUSTER_PG) + .when().post("/") + .then() + .statusCode(200) + .body(containsString("rds.force_ssl")); + + // A managed default group cannot be copied. AWS refuses it through the identifier rule, + // since default group names carry periods; the reference says to create a custom group + // for the family instead. + query("CopyDBClusterParameterGroup") + .formParam("SourceDBClusterParameterGroupIdentifier", "default.aurora-postgresql15") + .formParam("TargetDBClusterParameterGroupIdentifier", FROM_DEFAULT_CLUSTER_PG) + .formParam("TargetDBClusterParameterGroupDescription", "from default") + .when().post("/") + .then() + .statusCode(400) + .body(containsString("InvalidParameterValue")) + .body(containsString("is not a valid identifier")); + query("DescribeDBClusterParameterGroups") + .formParam("DBClusterParameterGroupName", FROM_DEFAULT_CLUSTER_PG) + .when().post("/") + .then() + .statusCode(404); + + query("ResetDBClusterParameterGroup") + .formParam("DBClusterParameterGroupName", TARGET_CLUSTER_PG) + .formParam("ResetAllParameters", "true") + .when().post("/") + .then() + .statusCode(200) + .body(containsString("")) + .body(containsString("" + TARGET_CLUSTER_PG + "")); + + query("DescribeDBClusterParameters") + .formParam("DBClusterParameterGroupName", TARGET_CLUSTER_PG) + .when().post("/") + .then() + .statusCode(200) + .body(not(containsString("rds.force_ssl"))); + + query("ResetDBClusterParameterGroup") + .formParam("DBClusterParameterGroupName", "default.aurora-postgresql15") + .when().post("/") + .then() + .statusCode(400) + .body(containsString("InvalidDBParameterGroupState")); + } + + @Test + @Order(5) + void copyOptionGroupCarriesEngineVersionAndOptions() { + query("CreateOptionGroup") + .formParam("OptionGroupName", SOURCE_OG) + .formParam("EngineName", "mysql") + .formParam("MajorEngineVersion", "8.0") + .formParam("OptionGroupDescription", "source") + .when().post("/").then().statusCode(200); + query("ModifyOptionGroup") + .formParam("OptionGroupName", SOURCE_OG) + .formParam("OptionsToInclude.member.1.OptionName", "MARIADB_AUDIT_PLUGIN") + .formParam("OptionsToInclude.member.1.OptionSettings.member.1.Name", "SERVER_AUDIT_EVENTS") + .formParam("OptionsToInclude.member.1.OptionSettings.member.1.Value", "CONNECT") + .formParam("ApplyImmediately", "true") + .when().post("/").then().statusCode(200); + + query("CopyOptionGroup") + .formParam("SourceOptionGroupIdentifier", SOURCE_OG) + .formParam("TargetOptionGroupIdentifier", TARGET_OG) + .formParam("TargetOptionGroupDescription", "copied") + .formParam("Tags.Tag.1.Key", "env") + .formParam("Tags.Tag.1.Value", "prod") + .when().post("/") + .then() + .statusCode(200) + .body(containsString("")) + .body(containsString("" + TARGET_OG + "")) + .body(containsString("mysql")) + .body(containsString("8.0")) + .body(containsString("copied")) + .body(containsString("MARIADB_AUDIT_PLUGIN")) + .body(containsString("CONNECT")); + + query("ListTagsForResource") + .formParam("ResourceName", "arn:aws:rds:us-east-1:000000000000:og:" + TARGET_OG) + .when().post("/") + .then() + .statusCode(200) + .body(containsString("env")); + + query("CopyOptionGroup") + .formParam("SourceOptionGroupIdentifier", SOURCE_OG) + .formParam("TargetOptionGroupIdentifier", TARGET_OG) + .formParam("TargetOptionGroupDescription", "again") + .when().post("/") + .then() + .statusCode(400) + .body(containsString("OptionGroupAlreadyExistsFault")); + + query("CopyOptionGroup") + .formParam("SourceOptionGroupIdentifier", "no-such-option-group") + .formParam("TargetOptionGroupIdentifier", "copy-test-never-created-og") + .formParam("TargetOptionGroupDescription", "x") + .when().post("/") + .then() + .statusCode(404) + .body(containsString("OptionGroupNotFoundFault")); + } + + @Test + @Order(9) + void cleanUp() { + for (String name : new String[] {SOURCE_PG, TARGET_PG}) { + query("DeleteDBParameterGroup").formParam("DBParameterGroupName", name).when().post("/"); + } + for (String name : new String[] {SOURCE_CLUSTER_PG, TARGET_CLUSTER_PG, FROM_DEFAULT_CLUSTER_PG}) { + query("DeleteDBClusterParameterGroup").formParam("DBClusterParameterGroupName", name).when().post("/"); + } + for (String name : new String[] {SOURCE_OG, TARGET_OG}) { + query("DeleteOptionGroup").formParam("OptionGroupName", name).when().post("/"); + } + } +}