feat(rds): add and remove a subscription's source identifiers (#4363)

* feat(rds): add and remove a subscription's source identifiers

SourceIds was write-once. CreateEventSubscription accepts the list and
ModifyEventSubscription has no SourceIds member, so
AddSourceIdentifierToSubscription and RemoveSourceIdentifierFromSubscription
are the only way to change it and neither existed.

Adding an id the subscription already carries is a no-op. The model declares
only SourceNotFoundFault and SubscriptionNotFoundFault for these operations,
so no fault fits a duplicate. Removing an id the subscription does not carry is
SourceNotFound, which is the fault that does fit.

* fix(rds): refuse a missing SubscriptionName as a parameter error

SubscriptionName and SourceIdentifier are both required by the model, and only
the identifier was checked. A missing name fell through to the subscription
lookup and came back as SubscriptionNotFound, telling the caller the
subscription does not exist when the request simply did not name one. The two
required members now fail the same way on both operations.

Also imports assertEquals in the new test rather than qualifying it inline.
This commit is contained in:
lex00 authored and GitHub committed 2026-09-25 07:08:02 -04:00
1 parent 08c6ce0768
commit 6cd1bb3794
4 files changed
+203

No files matched your search

@@ -95,6 +95,10 @@ public class RdsQueryHandler {
case "DescribeEventSubscriptions" -> handleDescribeEventSubscriptions(params, region);
case "ModifyEventSubscription" -> handleModifyEventSubscription(params, region);
case "DeleteEventSubscription" -> handleDeleteEventSubscription(params, region);
case "AddSourceIdentifierToSubscription" ->
handleAddSourceIdentifierToSubscription(params, region);
case "RemoveSourceIdentifierFromSubscription" ->
handleRemoveSourceIdentifierFromSubscription(params, region);
case "CreateDBSubnetGroup" -> handleCreateDbSubnetGroup(params, region);
case "DescribeDBSubnetGroups" -> handleDescribeDbSubnetGroups(params, region);
case "ModifyDBSubnetGroup" -> handleModifyDbSubnetGroup(params, region);
@@ -308,6 +312,22 @@ public class RdsQueryHandler {
new XmlBuilder().raw(eventSubscriptionXml(subscription)).build())).build();
}
private Response handleAddSourceIdentifierToSubscription(
MultivaluedMap<String, String> params, String region) {
EventSubscription subscription = service.addSourceIdentifierToSubscription(region,
params.getFirst("SubscriptionName"), params.getFirst("SourceIdentifier"));
return Response.ok(AwsQueryResponse.envelope("AddSourceIdentifierToSubscription",
AwsNamespaces.RDS, new XmlBuilder().raw(eventSubscriptionXml(subscription)).build())).build();
}
private Response handleRemoveSourceIdentifierFromSubscription(
MultivaluedMap<String, String> params, String region) {
EventSubscription subscription = service.removeSourceIdentifierFromSubscription(region,
params.getFirst("SubscriptionName"), params.getFirst("SourceIdentifier"));
return Response.ok(AwsQueryResponse.envelope("RemoveSourceIdentifierFromSubscription",
AwsNamespaces.RDS, new XmlBuilder().raw(eventSubscriptionXml(subscription)).build())).build();
}
private Response handleDeleteEventSubscription(MultivaluedMap<String, String> params, String region) {
EventSubscription subscription = service.deleteEventSubscription(region,
params.getFirst("SubscriptionName"));
@@ -8588,6 +8588,59 @@ public class RdsService implements Resettable, ResourceProvider {
return subscription;
}
/**
* AddSourceIdentifierToSubscription. The list is otherwise write-once, because
* ModifyEventSubscription carries no SourceIds member.
*
* <p>Adding an id the subscription already carries is a no-op rather than an error. The model
* declares only SourceNotFoundFault and SubscriptionNotFoundFault for this operation, so there
* is no fault to raise for a duplicate.
*/
public synchronized EventSubscription addSourceIdentifierToSubscription(
String region, String subscriptionName, String sourceIdentifier) {
requireSourceIdentifierRequest(subscriptionName, sourceIdentifier);
EventSubscription subscription = requireEventSubscription(region, subscriptionName);
List<String> ids = new ArrayList<>(subscription.getSourceIdsList());
if (!ids.contains(sourceIdentifier)) {
ids.add(sourceIdentifier);
subscription.setSourceIdsList(ids);
eventSubscriptions.put(eventSubscriptionKey(region, subscriptionName), subscription);
}
return subscription;
}
/**
* RemoveSourceIdentifierFromSubscription. An id the subscription does not carry is
* SourceNotFound, which is the fault the model declares and the only one that fits.
*/
public synchronized EventSubscription removeSourceIdentifierFromSubscription(
String region, String subscriptionName, String sourceIdentifier) {
requireSourceIdentifierRequest(subscriptionName, sourceIdentifier);
EventSubscription subscription = requireEventSubscription(region, subscriptionName);
List<String> ids = new ArrayList<>(subscription.getSourceIdsList());
if (!ids.remove(sourceIdentifier)) {
throw new AwsException("SourceNotFound",
"Source " + sourceIdentifier + " not found in subscription " + subscriptionName + ".", 404);
}
subscription.setSourceIdsList(ids);
eventSubscriptions.put(eventSubscriptionKey(region, subscriptionName), subscription);
return subscription;
}
/**
* Both members are required by the model, so both fail the same way. Letting a missing
* SubscriptionName fall through to the lookup would answer SubscriptionNotFound, which tells
* the caller the subscription does not exist when the request simply did not name one.
*/
private static void requireSourceIdentifierRequest(String subscriptionName, String sourceIdentifier) {
if (subscriptionName == null || subscriptionName.isBlank()) {
throw new AwsException("InvalidParameterValue", "SubscriptionName is required.", 400);
}
if (sourceIdentifier == null || sourceIdentifier.isBlank()) {
throw new AwsException("InvalidParameterValue", "SourceIdentifier is required.", 400);
}
}
public synchronized EventSubscription deleteEventSubscription(String region, String subscriptionName) {
EventSubscription subscription = requireEventSubscription(region, subscriptionName);
eventSubscriptions.delete(eventSubscriptionKey(region, subscriptionName));