mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
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
This commit is contained in:
1 parent
ebb79ed3c2
commit
0f4865e554
4 files changed
+616
-1
No files matched your search
@@ -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<String, String> 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<String, String> 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<String, String> 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<String> parameterNames(MultivaluedMap<String, String> params) {
|
||||
List<String> 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<String, String> params, String region) {
|
||||
String name = params.getFirst("DBParameterGroupName");
|
||||
@@ -903,6 +967,49 @@ public class RdsQueryHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private Response handleCopyDbClusterParameterGroup(
|
||||
MultivaluedMap<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> params, String region) {
|
||||
Collection<OptionGroup> result = service.listOptionGroups(
|
||||
|
||||
@@ -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<String> 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<String, String> overrides, boolean resetAllParameters,
|
||||
List<String> 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<String> 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<String, String> 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());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user