mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(rds): read the Parameters list the way every SDK sends it on ModifyDBParameterGroup (#3780)
The RDS service model declares the Parameters list with locationName Parameter, so the CLI and every SDK serialise it as Parameters.Parameter.N.ParameterName. ModifyDBParameterGroup and ModifyDBClusterParameterGroup only read Parameters.member.N, the plain Query encoding, so a real client's overrides were never seen: the call returned 200 and DescribeDBParameters stayed empty. Terraform's parameter blocks were dropped the same way while the apply reported success. Parse both encodings through one helper, keeping the member form for hand-built callers as ModifyOptionGroup does for OptionsToInclude. Closes #3779
This commit is contained in:
1 parent
892927ceb5
commit
958c5d9be0
2 files changed
+146
-23
No files matched your search
@@ -32,7 +32,6 @@ import jakarta.ws.rs.core.Response;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -772,17 +771,7 @@ public class RdsQueryHandler {
|
||||
if (name == null || name.isBlank()) {
|
||||
return AwsQueryResponse.error("InvalidParameterValue", "DBParameterGroupName is required.", AwsNamespaces.RDS, 400);
|
||||
}
|
||||
Map<String, String> parameters = new HashMap<>();
|
||||
for (int n = 1; ; n++) {
|
||||
String paramName = params.getFirst("Parameters.member." + n + ".ParameterName");
|
||||
if (paramName == null) {
|
||||
break;
|
||||
}
|
||||
String paramValue = params.getFirst("Parameters.member." + n + ".ParameterValue");
|
||||
if (paramValue != null) {
|
||||
parameters.put(paramName, paramValue);
|
||||
}
|
||||
}
|
||||
Map<String, String> parameters = parseParameterOverrides(params);
|
||||
try {
|
||||
DbParameterGroup group = service.modifyDbParameterGroup(name, parameters, region);
|
||||
String result = new XmlBuilder()
|
||||
@@ -794,6 +783,29 @@ public class RdsQueryHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the {@code Parameters} list of a modify request. The RDS model declares the list
|
||||
* with {@code locationName: Parameter}, so every SDK and the CLI send
|
||||
* {@code Parameters.Parameter.N.*}; the {@code Parameters.member.N.*} form is the plain Query
|
||||
* encoding older or hand-built callers use, and is accepted as well.
|
||||
*/
|
||||
private static Map<String, String> parseParameterOverrides(MultivaluedMap<String, String> params) {
|
||||
Map<String, String> parameters = new LinkedHashMap<>();
|
||||
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;
|
||||
}
|
||||
String paramValue = params.getFirst(prefix + "." + n + ".ParameterValue");
|
||||
if (paramValue != null) {
|
||||
parameters.put(paramName, paramValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
private Response handleDescribeDbParameters(
|
||||
MultivaluedMap<String, String> params, String region) {
|
||||
String name = params.getFirst("DBParameterGroupName");
|
||||
@@ -878,17 +890,7 @@ public class RdsQueryHandler {
|
||||
if (name == null || name.isBlank()) {
|
||||
return AwsQueryResponse.error("InvalidParameterValue", "DBClusterParameterGroupName is required.", AwsNamespaces.RDS, 400);
|
||||
}
|
||||
Map<String, String> parameters = new HashMap<>();
|
||||
for (int n = 1; ; n++) {
|
||||
String paramName = params.getFirst("Parameters.member." + n + ".ParameterName");
|
||||
if (paramName == null) {
|
||||
break;
|
||||
}
|
||||
String paramValue = params.getFirst("Parameters.member." + n + ".ParameterValue");
|
||||
if (paramValue != null) {
|
||||
parameters.put(paramName, paramValue);
|
||||
}
|
||||
}
|
||||
Map<String, String> parameters = parseParameterOverrides(params);
|
||||
try {
|
||||
DbClusterParameterGroup group = service.modifyDbClusterParameterGroup(
|
||||
name, parameters, region);
|
||||
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* The RDS model declares the {@code Parameters} list with {@code locationName: Parameter}, so the
|
||||
* CLI and every SDK send {@code Parameters.Parameter.N.*}. A modify sent that way must land in
|
||||
* the group; the plain {@code Parameters.member.N.*} encoding stays accepted for callers that
|
||||
* build the query by hand.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class RdsParameterGroupWireEncodingIntegrationTest {
|
||||
|
||||
private static final String PG = "wire-encoding-pg";
|
||||
private static final String CLUSTER_PG = "wire-encoding-cluster-pg";
|
||||
|
||||
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 modifyDbParameterGroupStoresTheParametersTheCliSends() {
|
||||
query("CreateDBParameterGroup")
|
||||
.formParam("DBParameterGroupName", PG)
|
||||
.formParam("DBParameterGroupFamily", "postgres15")
|
||||
.formParam("Description", "wire encoding")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
// Exactly what `aws rds modify-db-parameter-group --parameters ...` puts on the wire.
|
||||
query("ModifyDBParameterGroup")
|
||||
.formParam("DBParameterGroupName", PG)
|
||||
.formParam("Parameters.Parameter.1.ParameterName", "max_connections")
|
||||
.formParam("Parameters.Parameter.1.ParameterValue", "250")
|
||||
.formParam("Parameters.Parameter.1.ApplyMethod", "immediate")
|
||||
.formParam("Parameters.Parameter.2.ParameterName", "work_mem")
|
||||
.formParam("Parameters.Parameter.2.ParameterValue", "65536")
|
||||
.formParam("Parameters.Parameter.2.ApplyMethod", "pending-reboot")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<DBParameterGroupName>" + PG + "</DBParameterGroupName>"));
|
||||
|
||||
query("DescribeDBParameters")
|
||||
.formParam("DBParameterGroupName", PG)
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<ParameterName>max_connections</ParameterName>"))
|
||||
.body(containsString("<ParameterValue>250</ParameterValue>"))
|
||||
.body(containsString("<ParameterName>work_mem</ParameterName>"))
|
||||
.body(containsString("<ParameterValue>65536</ParameterValue>"));
|
||||
|
||||
// The plain Query encoding keeps working alongside it.
|
||||
query("ModifyDBParameterGroup")
|
||||
.formParam("DBParameterGroupName", PG)
|
||||
.formParam("Parameters.member.1.ParameterName", "shared_buffers")
|
||||
.formParam("Parameters.member.1.ParameterValue", "4096")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
query("DescribeDBParameters")
|
||||
.formParam("DBParameterGroupName", PG)
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<ParameterName>shared_buffers</ParameterName>"))
|
||||
.body(containsString("<ParameterName>max_connections</ParameterName>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void modifyDbClusterParameterGroupStoresTheParametersTheCliSends() {
|
||||
query("CreateDBClusterParameterGroup")
|
||||
.formParam("DBClusterParameterGroupName", CLUSTER_PG)
|
||||
.formParam("DBParameterGroupFamily", "aurora-postgresql15")
|
||||
.formParam("Description", "wire encoding")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
query("ModifyDBClusterParameterGroup")
|
||||
.formParam("DBClusterParameterGroupName", CLUSTER_PG)
|
||||
.formParam("Parameters.Parameter.1.ParameterName", "rds.force_ssl")
|
||||
.formParam("Parameters.Parameter.1.ParameterValue", "1")
|
||||
.formParam("Parameters.Parameter.1.ApplyMethod", "immediate")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<DBClusterParameterGroupName>" + CLUSTER_PG + "</DBClusterParameterGroupName>"));
|
||||
|
||||
query("DescribeDBClusterParameters")
|
||||
.formParam("DBClusterParameterGroupName", CLUSTER_PG)
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<ParameterName>rds.force_ssl</ParameterName>"))
|
||||
.body(containsString("<ParameterValue>1</ParameterValue>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void cleanUp() {
|
||||
query("DeleteDBParameterGroup").formParam("DBParameterGroupName", PG).when().post("/");
|
||||
query("DeleteDBClusterParameterGroup").formParam("DBClusterParameterGroupName", CLUSTER_PG).when().post("/");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user