mirror of
https://github.com/floci-io/floci.git
synced 2026-11-26 15:21:05 -05:00
fix(events): word not-found, already-exists and invalid-state errors as AWS does (#9295)
Word EventBridge's not-found, already-exists and invalid-state errors as AWS does, built in EventBridgeErrors: rules name their bus, event buses, archives and replays use "X does not exist." and "X already exists.", connection and api-destination describe and update name the failing call, and CancelReplay on a settled replay answers IllegalStatusException. StartReplay naming a missing archive now answers ValidationException. Paths with no recorded AWS answer keep Floci's text.
This commit is contained in:
1 parent
66d84afb16
commit
8a4880f7b3
8 files changed
+364
-76
No files matched your search
+2
-2
@@ -429,8 +429,8 @@ public class EventsCfnProvisioner implements CfnResourceProvisioner {
|
||||
/**
|
||||
* Provisions an {@code AWS::Events::EventBus} (a custom EventBridge event bus). Without this the
|
||||
* resource would fall through to the generic stub, which assigns a physical id but never registers
|
||||
* the bus with the EventBridge service, so any {@code AWS::Events::Rule} (or PutEvents) targeting
|
||||
* the bus fails "EventBus not found". Per the AWS spec, {@code Ref} returns the bus <em>name</em>
|
||||
* the bus with the EventBridge service, so any {@code AWS::Events::Rule} targeting the bus fails with
|
||||
* "Event bus ... does not exist.". Per the AWS spec, {@code Ref} returns the bus <em>name</em>
|
||||
* (not the ARN), so the physical id is the name; {@code Fn::GetAtt "Arn"} exposes the ARN.
|
||||
*/
|
||||
private void provisionEventBus(StackResource r, JsonNode props, ProvisionContext ctx) {
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
package io.floci.aws.services.eventbridge;
|
||||
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
|
||||
/**
|
||||
* The client errors EventBridge words one way for every operation that runs into the same
|
||||
* condition, so a missing rule, bus, archive, replay, connection or API destination reads the same
|
||||
* whichever call found it.
|
||||
*/
|
||||
final class EventBridgeErrors {
|
||||
|
||||
private EventBridgeErrors() {
|
||||
}
|
||||
|
||||
static AwsException ruleNotFound(String rule, String bus) {
|
||||
return notFound("Rule " + rule + " does not exist on EventBus " + bus + ".");
|
||||
}
|
||||
|
||||
static AwsException busNotFound(String bus) {
|
||||
return notFound("Event bus " + bus + " does not exist.");
|
||||
}
|
||||
|
||||
static AwsException archiveNotFound(String archive) {
|
||||
return notFound("Archive " + archive + " does not exist.");
|
||||
}
|
||||
|
||||
static AwsException replayNotFound(String replay) {
|
||||
return notFound("Replay " + replay + " does not exist.");
|
||||
}
|
||||
|
||||
/** {@code verb} is the failing call: describe or update. */
|
||||
static AwsException connectionNotFound(String verb, String connection) {
|
||||
return notFound("Failed to " + verb + " the connection(s). " + connectionMissing(connection));
|
||||
}
|
||||
|
||||
static AwsException apiDestinationNotFound(String verb, String name) {
|
||||
return notFound("Failed to " + verb + " the api-destination(s). An api-destination '" + name
|
||||
+ "' does not exist.");
|
||||
}
|
||||
|
||||
/** An API destination write that names a connection ARN no connection answers to. */
|
||||
static AwsException apiDestinationConnectionNotFound(String verb, String connectionArn) {
|
||||
return notFound("Failed to " + verb + " the api-destination(s). " + connectionMissing(connectionArn));
|
||||
}
|
||||
|
||||
/** An internal lookup by ARN, whose message reaches the dead-letter queue; unquoted, unlike the API's. */
|
||||
static AwsException plainConnectionNotFound(String connectionArn) {
|
||||
return notFound("Connection " + connectionArn + " does not exist.");
|
||||
}
|
||||
|
||||
static AwsException busAlreadyExists(String bus) {
|
||||
return alreadyExists("Event bus " + bus + " already exists.");
|
||||
}
|
||||
|
||||
static AwsException archiveAlreadyExists(String archive) {
|
||||
return alreadyExists("Archive " + archive + " already exists.");
|
||||
}
|
||||
|
||||
static AwsException replayAlreadyExists(String replay) {
|
||||
return alreadyExists("Replay " + replay + " already exists.");
|
||||
}
|
||||
|
||||
static AwsException replayNotCancellable(String replay) {
|
||||
return new AwsException("IllegalStatusException",
|
||||
"Replay " + replay + " is not in a valid state for this operation.", 400);
|
||||
}
|
||||
|
||||
static AwsException cannotDeleteDefaultBus() {
|
||||
return validation("Cannot delete event bus default.");
|
||||
}
|
||||
|
||||
static AwsException busHasRules() {
|
||||
return validation("EventBus can't be deleted since it has rules.");
|
||||
}
|
||||
|
||||
static AwsException ruleHasTargets() {
|
||||
return validation("Rule can't be deleted since it has targets.");
|
||||
}
|
||||
|
||||
static AwsException replaySourceArchiveNotFound(String archive) {
|
||||
return validation("Parameter EventSourceArn is not valid. Reason: Archive " + archive
|
||||
+ " does not exist.");
|
||||
}
|
||||
|
||||
private static AwsException validation(String message) {
|
||||
return new AwsException("ValidationException", message, 400);
|
||||
}
|
||||
|
||||
private static String connectionMissing(String connection) {
|
||||
return "Connection '" + connection + "' does not exist.";
|
||||
}
|
||||
|
||||
private static AwsException notFound(String message) {
|
||||
return new AwsException("ResourceNotFoundException", message, 400);
|
||||
}
|
||||
|
||||
private static AwsException alreadyExists(String message) {
|
||||
return new AwsException("ResourceAlreadyExistsException", message, 400);
|
||||
}
|
||||
}
|
||||
@@ -214,8 +214,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
validateEventBusDescription(description);
|
||||
String key = busKey(region, name);
|
||||
if (busStore.get(key).isPresent()) {
|
||||
throw new AwsException("ResourceAlreadyExistsException",
|
||||
"EventBus already exists: " + name, 400);
|
||||
throw EventBridgeErrors.busAlreadyExists(name);
|
||||
}
|
||||
EventBus bus = new EventBus(
|
||||
name,
|
||||
@@ -249,7 +248,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
String effectiveName = resolvedBusName(name);
|
||||
validateEventBusNameForMutation(effectiveName);
|
||||
if ("default".equals(effectiveName)) {
|
||||
throw new AwsException("ValidationException", "Cannot delete the default event bus.", 400);
|
||||
throw EventBridgeErrors.cannotDeleteDefaultBus();
|
||||
}
|
||||
String key = busKey(region, effectiveName);
|
||||
EventBus bus = busStore.get(key).orElse(null);
|
||||
@@ -260,8 +259,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
boolean hasRules = ruleStore.scan(k -> k.startsWith(rulePrefix)).stream()
|
||||
.anyMatch(rule -> effectiveName.equals(rule.getEventBusName()));
|
||||
if (hasRules) {
|
||||
throw new AwsException("ValidationException",
|
||||
"Cannot delete event bus with existing rules: " + name, 400);
|
||||
throw EventBridgeErrors.busHasRules();
|
||||
}
|
||||
busStore.delete(key);
|
||||
resourceGroupsTaggingService.deleteResources(List.of(bus.getArn()), region);
|
||||
@@ -275,7 +273,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
return getOrCreateDefaultBus(region);
|
||||
}
|
||||
return busStore.get(busKey(region, effectiveName))
|
||||
.orElseThrow(() -> eventBusNotFound(name));
|
||||
.orElseThrow(() -> EventBridgeErrors.busNotFound(effectiveName));
|
||||
}
|
||||
|
||||
public EventBus updateEventBus(String name,
|
||||
@@ -293,8 +291,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
EventBus bus = "default".equals(effectiveName)
|
||||
? getOrCreateDefaultBus(region)
|
||||
: busStore.get(busKey(region, effectiveName))
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"EventBus not found: " + effectiveName, 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.busNotFound(effectiveName));
|
||||
|
||||
// Description accepts an explicit empty string so callers can clear it. A null value means
|
||||
// the field was omitted and must remain unchanged.
|
||||
@@ -491,8 +488,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
}
|
||||
List<Target> targets = targetStore.get(key).orElse(List.of());
|
||||
if (!targets.isEmpty()) {
|
||||
throw new AwsException("ValidationException",
|
||||
"Rule still has targets. Remove targets before deleting the rule.", 400);
|
||||
throw EventBridgeErrors.ruleHasTargets();
|
||||
}
|
||||
|
||||
if (ruleScheduler != null) {
|
||||
@@ -517,8 +513,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
String effectiveBus = resolvedBusName(busName);
|
||||
validateRuleReference("name", name, effectiveBus, region);
|
||||
return ruleOfBus(ruleKey(region, effectiveBus, name), effectiveBus)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Rule not found: " + name, 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.ruleNotFound(name, effectiveBus));
|
||||
}
|
||||
|
||||
public List<Rule> listRules(String busName, String namePrefix, String region) {
|
||||
@@ -579,8 +574,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
validateRuleReference("name", name, effectiveBus, region);
|
||||
String key = ruleKey(region, effectiveBus, name);
|
||||
Rule rule = ruleOfBus(key, effectiveBus)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Rule not found: " + name, 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.ruleNotFound(name, effectiveBus));
|
||||
rule.setState(RuleState.ENABLED);
|
||||
ruleStore.put(key, rule);
|
||||
startSchedulerIfNeeded(rule);
|
||||
@@ -591,8 +585,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
validateRuleReference("name", name, effectiveBus, region);
|
||||
String key = ruleKey(region, effectiveBus, name);
|
||||
Rule rule = ruleOfBus(key, effectiveBus)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Rule not found: " + name, 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.ruleNotFound(name, effectiveBus));
|
||||
rule.setState(RuleState.DISABLED);
|
||||
ruleStore.put(key, rule);
|
||||
|
||||
@@ -623,8 +616,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
validateRuleReference("rule", ruleName, effectiveBus, region);
|
||||
String key = ruleKey(region, effectiveBus, ruleName);
|
||||
Rule rule = ruleOfBus(key, effectiveBus)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Rule not found: " + ruleName, 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.ruleNotFound(ruleName, effectiveBus));
|
||||
List<Target> existing = new ArrayList<>(targetStore.get(key).orElse(new ArrayList<>()));
|
||||
for (Target newTarget : newTargets) {
|
||||
EcsParameters ecs = newTarget.getEcsParameters();
|
||||
@@ -781,7 +773,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
private void requireBusForRead(String busName, String region) {
|
||||
Optional<EventBus> bus = readInAccount(busStore, regionResolver.getAccountId(), busKey(region, busName));
|
||||
if (bus.isEmpty() && !"default".equals(busName)) {
|
||||
throw eventBusNotFound(busName);
|
||||
throw EventBridgeErrors.busNotFound(busName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -815,8 +807,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
validateRuleReference("rule", ruleName, effectiveBus, region);
|
||||
String key = ruleKey(region, effectiveBus, ruleName);
|
||||
ruleOfBus(key, effectiveBus)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Rule not found: " + ruleName, 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.ruleNotFound(ruleName, effectiveBus));
|
||||
return targetStore.get(key).orElse(List.of());
|
||||
}
|
||||
|
||||
@@ -858,8 +849,20 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
|
||||
private TagResource requireTagResource(String resourceArn, String region, String resource) {
|
||||
return findTagResource(regionResolver.getAccountId(), region, resource)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Resource not found: " + resourceArn, 400));
|
||||
.orElseThrow(() -> tagResourceNotFound(resourceArn, resource));
|
||||
}
|
||||
|
||||
/** Words a missing tag target like the same resource missing from any other call. */
|
||||
private static AwsException tagResourceNotFound(String resourceArn, String resource) {
|
||||
if (resource.startsWith("event-bus/")) {
|
||||
return EventBridgeErrors.busNotFound(resource.substring("event-bus/".length()));
|
||||
}
|
||||
if (resource.startsWith("rule/")) {
|
||||
RuleRef ref = parseRuleResource(resource);
|
||||
return EventBridgeErrors.ruleNotFound(ref.ruleName(), ref.busName());
|
||||
}
|
||||
// Only rules and event buses take tags in AWS; no answer is recorded for any other kind.
|
||||
return new AwsException("ResourceNotFoundException", "Resource not found: " + resourceArn, 400);
|
||||
}
|
||||
|
||||
/** EventBridge tag operations only address resources in the caller's account and Region. */
|
||||
@@ -924,8 +927,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
}
|
||||
String key = busKey(region, effectiveBus);
|
||||
EventBus bus = busStore.get(key)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"EventBus not found: " + effectiveBus, 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.busNotFound(effectiveBus));
|
||||
|
||||
try {
|
||||
if (policyJson != null && !policyJson.isBlank()) {
|
||||
@@ -1007,8 +1009,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
}
|
||||
String key = busKey(region, effectiveBus);
|
||||
EventBus bus = busStore.get(key)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"EventBus not found: " + effectiveBus, 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.busNotFound(effectiveBus));
|
||||
|
||||
if (removeAll) {
|
||||
bus.setPolicy(null);
|
||||
@@ -1684,11 +1685,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
return;
|
||||
}
|
||||
busStore.get(busKey(region, busName))
|
||||
.orElseThrow(() -> eventBusNotFound(busName));
|
||||
}
|
||||
|
||||
private static AwsException eventBusNotFound(String busName) {
|
||||
return new AwsException("ResourceNotFoundException", "EventBus not found: " + busName, 400);
|
||||
.orElseThrow(() -> EventBridgeErrors.busNotFound(busName));
|
||||
}
|
||||
|
||||
private static boolean isBlank(Object value) {
|
||||
@@ -1815,8 +1812,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
requireArchiveSource(eventSourceArn, region);
|
||||
String key = archiveKey(region, archiveName);
|
||||
if (archiveStore.get(key).isPresent()) {
|
||||
throw new AwsException("ResourceAlreadyExistsException",
|
||||
"Archive already exists: " + archiveName, 400);
|
||||
throw EventBridgeErrors.archiveAlreadyExists(archiveName);
|
||||
}
|
||||
Archive archive = new Archive();
|
||||
archive.setArchiveName(archiveName);
|
||||
@@ -1880,14 +1876,13 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
? getOrCreateDefaultBus(region)
|
||||
: busStore.get(busKey(region, busName)).orElse(null);
|
||||
if (bus == null || !eventSourceArn.equals(bus.getArn())) {
|
||||
throw new AwsException("ResourceNotFoundException", "Event bus " + busName + " does not exist.", 400);
|
||||
throw EventBridgeErrors.busNotFound(busName);
|
||||
}
|
||||
}
|
||||
|
||||
public Archive describeArchive(String archiveName, String region) {
|
||||
return archiveStore.get(archiveKey(region, archiveName))
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Archive not found: " + archiveName, 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.archiveNotFound(archiveName));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1899,8 +1894,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
requireArchiveFields(description, eventPattern, retentionDays);
|
||||
String key = archiveKey(region, archiveName);
|
||||
Archive archive = archiveStore.get(key)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Archive not found: " + archiveName, 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.archiveNotFound(archiveName));
|
||||
if (description != null) {
|
||||
archive.setDescription(description.isEmpty() ? null : description);
|
||||
}
|
||||
@@ -1917,8 +1911,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
public void deleteArchive(String archiveName, String region) {
|
||||
String key = archiveKey(region, archiveName);
|
||||
Archive archive = archiveStore.get(key)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Archive not found: " + archiveName, 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.archiveNotFound(archiveName));
|
||||
archiveStore.delete(key);
|
||||
archivedEventStore.delete(archivedEventKey(region, archiveName));
|
||||
resourceGroupsTaggingService.deleteResources(List.of(archive.getArchiveArn()), region);
|
||||
@@ -1962,6 +1955,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
}
|
||||
String key = connectionKey(region, name);
|
||||
if (connectionStore.get(key).isPresent()) {
|
||||
// AWS's wording for this duplicate is not recorded, so it keeps Floci's own.
|
||||
throw new AwsException("ResourceAlreadyExistsException",
|
||||
"Connection " + name + " already exists.", 400);
|
||||
}
|
||||
@@ -2036,8 +2030,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
|
||||
public Connection describeConnection(String name, String region) {
|
||||
return connectionStore.get(connectionKey(region, name))
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Connection " + name + " does not exist.", 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.connectionNotFound("describe", name));
|
||||
}
|
||||
|
||||
public Connection updateConnection(String name, String description, String authorizationType,
|
||||
@@ -2057,8 +2050,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
String kmsKeyIdentifier, Set<String> cleared, String region) {
|
||||
String key = connectionKey(region, name);
|
||||
Connection connection = connectionStore.get(key)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Connection " + name + " does not exist.", 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.connectionNotFound("update", name));
|
||||
if (authorizationType != null) {
|
||||
validateAuthorizationType(authorizationType);
|
||||
if (!authorizationType.equals(connection.getAuthorizationType()) && authParameters == null) {
|
||||
@@ -2122,6 +2114,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
public Connection deleteConnection(String name, String region) {
|
||||
String key = connectionKey(region, name);
|
||||
Connection connection = connectionStore.get(key)
|
||||
// AWS's delete wording is not recorded (the suite covers describe, update and create), so it keeps Floci's own.
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Connection " + name + " does not exist.", 400));
|
||||
connectionStore.delete(key);
|
||||
@@ -2189,7 +2182,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
if (connectionArn == null || connectionArn.isBlank()) {
|
||||
throw new AwsException("ValidationException", "ConnectionArn is required.", 400);
|
||||
}
|
||||
findConnectionByArn(connectionArn, region);
|
||||
connectionByArn(connectionArn, region, "create");
|
||||
if (invocationEndpoint == null || invocationEndpoint.isBlank()) {
|
||||
throw new AwsException("ValidationException", "InvocationEndpoint is required.", 400);
|
||||
}
|
||||
@@ -2202,6 +2195,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
|
||||
String key = apiDestinationKey(region, name);
|
||||
if (apiDestinationStore.get(key).isPresent()) {
|
||||
// AWS's wording for this duplicate is not recorded, so it keeps Floci's own.
|
||||
throw new AwsException("ResourceAlreadyExistsException",
|
||||
"ApiDestination " + name + " already exists.", 400);
|
||||
}
|
||||
@@ -2228,8 +2222,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
|
||||
public ApiDestination describeApiDestination(String name, String region) {
|
||||
return apiDestinationStore.get(apiDestinationKey(region, name))
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"ApiDestination " + name + " does not exist.", 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.apiDestinationNotFound("describe", name));
|
||||
}
|
||||
|
||||
public synchronized ApiDestination updateApiDestination(String name, String description, String connectionArn,
|
||||
@@ -2237,12 +2230,11 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
Integer invocationRateLimitPerSecond, String region) {
|
||||
String key = apiDestinationKey(region, name);
|
||||
ApiDestination destination = apiDestinationStore.get(key)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"ApiDestination " + name + " does not exist.", 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.apiDestinationNotFound("update", name));
|
||||
|
||||
// Validate everything before assigning: the in-memory store returns the same instance, so a rejected update must not leave partial changes
|
||||
if (connectionArn != null) {
|
||||
findConnectionByArn(connectionArn, region);
|
||||
connectionByArn(connectionArn, region, "update");
|
||||
}
|
||||
if (invocationEndpoint != null) {
|
||||
validateInvocationEndpoint(invocationEndpoint);
|
||||
@@ -2283,8 +2275,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
Integer invocationRateLimitPerSecond, String region) {
|
||||
String key = apiDestinationKey(region, name);
|
||||
ApiDestination destination = apiDestinationStore.get(key)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"ApiDestination " + name + " does not exist.", 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.apiDestinationNotFound("update", name));
|
||||
destination.setDescription(description);
|
||||
destination.setConnectionArn(connectionArn);
|
||||
destination.setInvocationEndpoint(invocationEndpoint);
|
||||
@@ -2299,6 +2290,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
public synchronized ApiDestination deleteApiDestination(String name, String region) {
|
||||
String key = apiDestinationKey(region, name);
|
||||
ApiDestination destination = apiDestinationStore.get(key)
|
||||
// AWS's delete wording is not recorded (the suite covers describe, update and create), so it keeps Floci's own.
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"ApiDestination " + name + " does not exist.", 400));
|
||||
apiDestinationStore.delete(key);
|
||||
@@ -2331,6 +2323,11 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
}
|
||||
|
||||
public Connection findConnectionByArn(String connectionArn, String region) {
|
||||
return connectionByArn(connectionArn, region, null);
|
||||
}
|
||||
|
||||
/** {@code verb} names the failing api-destination call in the not-found message, as AWS words it; null keeps the plain wording for internal callers. */
|
||||
private Connection connectionByArn(String connectionArn, String region, String verb) {
|
||||
if (connectionArn == null || connectionArn.isBlank()) {
|
||||
throw new AwsException("ResourceNotFoundException", "Connection ARN is required.", 400);
|
||||
}
|
||||
@@ -2352,8 +2349,9 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
return connectionStore.scan(k -> {
|
||||
Connection c = connectionStore.get(k).orElse(null);
|
||||
return c != null && connectionArn.equals(c.getConnectionArn());
|
||||
}).stream().findFirst().orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Connection " + connectionArn + " does not exist.", 400));
|
||||
}).stream().findFirst().orElseThrow(() -> verb == null
|
||||
? EventBridgeErrors.plainConnectionNotFound(connectionArn)
|
||||
: EventBridgeErrors.apiDestinationConnectionNotFound(verb, connectionArn));
|
||||
}
|
||||
|
||||
public ApiDestination findApiDestinationByArn(String arn, String region) {
|
||||
@@ -2469,15 +2467,13 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
}
|
||||
String key = replayKey(region, replayName);
|
||||
if (replayStore.get(key).isPresent()) {
|
||||
throw new AwsException("ResourceAlreadyExistsException",
|
||||
"Replay already exists: " + replayName, 400);
|
||||
throw EventBridgeErrors.replayAlreadyExists(replayName);
|
||||
}
|
||||
|
||||
// resolve archive
|
||||
String archiveName = archiveNameFromArn(eventSourceArn);
|
||||
Archive archive = archiveStore.get(archiveKey(region, archiveName))
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Archive not found: " + archiveName, 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.replaySourceArchiveNotFound(archiveName));
|
||||
|
||||
List<ArchivedEvent> events = archivedEventStore
|
||||
.get(archivedEventKey(region, archiveName))
|
||||
@@ -2512,18 +2508,15 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
|
||||
public Replay describeReplay(String replayName, String region) {
|
||||
return replayStore.get(replayKey(region, replayName))
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Replay not found: " + replayName, 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.replayNotFound(replayName));
|
||||
}
|
||||
|
||||
public Replay cancelReplay(String replayName, String region) {
|
||||
String key = replayKey(region, replayName);
|
||||
Replay replay = replayStore.get(key)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Replay not found: " + replayName, 400));
|
||||
.orElseThrow(() -> EventBridgeErrors.replayNotFound(replayName));
|
||||
if (replay.getState() != ReplayState.RUNNING && replay.getState() != ReplayState.STARTING) {
|
||||
throw new AwsException("IllegalStatusException",
|
||||
"Replay is not in a cancellable state: " + replay.getState(), 400);
|
||||
throw EventBridgeErrors.replayNotCancellable(replayName);
|
||||
}
|
||||
boolean signalled = replayDispatcher.requestCancel(replay.getReplayArn());
|
||||
if (!signalled) {
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
* <p>Previously the type had no provisioner case, so it fell through to the generic stub: the resource
|
||||
* reported CREATE_COMPLETE with a physical id but the bus was never registered with the EventBridge
|
||||
* service. Any {@code AWS::Events::Rule} referencing it via {@code {"Ref": bus}} then failed
|
||||
* "EventBus not found", rolling the whole stack back. Per the AWS spec {@code Ref} returns the bus
|
||||
* "Event bus ... does not exist.", rolling the whole stack back. Per the AWS spec {@code Ref} returns the bus
|
||||
* <em>name</em> and {@code Fn::GetAtt "Arn"} the ARN.
|
||||
*
|
||||
* <p>All resources are metadata-only (no container), so the test is Docker-free.
|
||||
@@ -266,7 +266,7 @@ class CloudFormationEventBusIntegrationTest {
|
||||
String busName = "domain-events-" + suffix;
|
||||
String stackName = "eventbus-stack-" + suffix;
|
||||
|
||||
// The stub-only behaviour failed the Rule with "EventBus not found" -> ROLLBACK.
|
||||
// The stub-only behaviour failed the Rule with "Event bus ... does not exist." -> ROLLBACK.
|
||||
createStack(stackName, eventBusAndRuleTemplate(busName));
|
||||
assertStackStatus(stackName, "CREATE_COMPLETE");
|
||||
|
||||
@@ -401,7 +401,7 @@ class CloudFormationEventBusIntegrationTest {
|
||||
throw new AssertionError("collision failure was not preserved: " + resources);
|
||||
}
|
||||
String events = describeStackEvents(stackB);
|
||||
if (!events.contains("EventBus already exists: " + busName)) {
|
||||
if (!events.contains("Event bus " + busName + " already exists.")) {
|
||||
throw new AssertionError("collision reason was not preserved: " + events);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -89,7 +89,7 @@ class EventsArchiveCfnProvisionerTest {
|
||||
when(events.describeArchive(anyString(), eq(REGION))).thenAnswer(i -> {
|
||||
Archive archive = archives.get(i.<String>getArgument(0));
|
||||
if (archive == null) {
|
||||
throw new AwsException("ResourceNotFoundException", "Archive not found: " + i.getArgument(0), 400);
|
||||
throw new AwsException("ResourceNotFoundException", "Archive " + i.getArgument(0) + " does not exist.", 400);
|
||||
}
|
||||
return archive;
|
||||
});
|
||||
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
package io.floci.aws.services.eventbridge;
|
||||
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/** Exact code, message and status of the not-found, already-exists and invalid-state refusals. */
|
||||
@QuarkusTest
|
||||
class EventBridgeErrorMessagesIntegrationTest {
|
||||
|
||||
private static final String BUS_ARN = "arn:aws:events:us-east-1:000000000000:event-bus/";
|
||||
|
||||
@BeforeAll
|
||||
static void configure() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static ValidatableResponse call(String op, String body) {
|
||||
return RestAssuredJsonUtils.awsAction("AWSEvents", op, body).then();
|
||||
}
|
||||
|
||||
private static void ok(String op, String body) {
|
||||
call(op, body).statusCode(200);
|
||||
}
|
||||
|
||||
private static void refused(String op, String body, String type, String message) {
|
||||
call(op, body).statusCode(400).body("__type", equalTo(type)).body("message", equalTo(message));
|
||||
}
|
||||
|
||||
private static void createBus(String name) {
|
||||
ok("CreateEventBus", "{\"Name\":\"" + name + "\"}");
|
||||
}
|
||||
|
||||
private static void createArchive(String name, String bus) {
|
||||
ok("CreateArchive", "{\"ArchiveName\":\"" + name + "\",\"EventSourceArn\":\"" + BUS_ARN + bus + "\"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
void notFoundIsWordedPerResourceKind() {
|
||||
String nf = "ResourceNotFoundException";
|
||||
createBus("emsg-bus");
|
||||
|
||||
refused("DescribeEventBus", "{\"Name\":\"emsg-nobus\"}", nf, "Event bus emsg-nobus does not exist.");
|
||||
refused("DescribeRule", "{\"Name\":\"emsg-norule\"}", nf,
|
||||
"Rule emsg-norule does not exist on EventBus default.");
|
||||
refused("DescribeRule", "{\"Name\":\"emsg-norule\",\"EventBusName\":\"emsg-bus\"}", nf,
|
||||
"Rule emsg-norule does not exist on EventBus emsg-bus.");
|
||||
refused("EnableRule", "{\"Name\":\"emsg-norule\"}", nf,
|
||||
"Rule emsg-norule does not exist on EventBus default.");
|
||||
refused("PutTargets", "{\"Rule\":\"emsg-norule\",\"Targets\":[{\"Id\":\"1\","
|
||||
+ "\"Arn\":\"arn:aws:sqs:us-east-1:000000000000:q\"}]}", nf,
|
||||
"Rule emsg-norule does not exist on EventBus default.");
|
||||
refused("DescribeArchive", "{\"ArchiveName\":\"emsg-noarch\"}", nf,
|
||||
"Archive emsg-noarch does not exist.");
|
||||
refused("DescribeReplay", "{\"ReplayName\":\"emsg-noreplay\"}", nf,
|
||||
"Replay emsg-noreplay does not exist.");
|
||||
refused("DescribeConnection", "{\"Name\":\"emsg-noconn\"}", nf,
|
||||
"Failed to describe the connection(s). Connection 'emsg-noconn' does not exist.");
|
||||
refused("DescribeApiDestination", "{\"Name\":\"emsg-nodest\"}", nf,
|
||||
"Failed to describe the api-destination(s). An api-destination 'emsg-nodest' does not exist.");
|
||||
String ghost = "arn:aws:events:us-east-1:000000000000:connection/emsg-ghost/"
|
||||
+ "00000000-0000-0000-0000-000000000000";
|
||||
refused("CreateApiDestination", "{\"Name\":\"emsg-d\",\"ConnectionArn\":\"" + ghost + "\","
|
||||
+ "\"InvocationEndpoint\":\"https://example.com\",\"HttpMethod\":\"POST\"}", nf,
|
||||
"Failed to create the api-destination(s). Connection '" + ghost + "' does not exist.");
|
||||
refused("TagResource", "{\"ResourceARN\":\"" + BUS_ARN + "emsg-nobus\",\"Tags\":[]}", nf,
|
||||
"Event bus emsg-nobus does not exist.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletedResourcesReadBackAsNotFound() {
|
||||
createBus("emsg-del-bus");
|
||||
ok("DeleteEventBus", "{\"Name\":\"emsg-del-bus\"}");
|
||||
refused("DescribeEventBus", "{\"Name\":\"emsg-del-bus\"}", "ResourceNotFoundException",
|
||||
"Event bus emsg-del-bus does not exist.");
|
||||
|
||||
createArchive("emsg-del-arch", "default");
|
||||
ok("DeleteArchive", "{\"ArchiveName\":\"emsg-del-arch\"}");
|
||||
refused("DescribeArchive", "{\"ArchiveName\":\"emsg-del-arch\"}", "ResourceNotFoundException",
|
||||
"Archive emsg-del-arch does not exist.");
|
||||
|
||||
ok("PutRule", "{\"Name\":\"emsg-del-rule\",\"EventPattern\":\"{\\\"source\\\":[\\\"x\\\"]}\"}");
|
||||
ok("DeleteRule", "{\"Name\":\"emsg-del-rule\"}");
|
||||
refused("DescribeRule", "{\"Name\":\"emsg-del-rule\"}", "ResourceNotFoundException",
|
||||
"Rule emsg-del-rule does not exist on EventBus default.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void duplicateCreatesAreAlreadyExists() {
|
||||
String ae = "ResourceAlreadyExistsException";
|
||||
createBus("emsg-dup-bus");
|
||||
refused("CreateEventBus", "{\"Name\":\"emsg-dup-bus\"}", ae, "Event bus emsg-dup-bus already exists.");
|
||||
|
||||
createArchive("emsg-dup-arch", "default");
|
||||
refused("CreateArchive", "{\"ArchiveName\":\"emsg-dup-arch\",\"EventSourceArn\":\"" + BUS_ARN
|
||||
+ "default\"}", ae, "Archive emsg-dup-arch already exists.");
|
||||
|
||||
String conn = "{\"Name\":\"emsg-dup-conn\",\"AuthorizationType\":\"API_KEY\",\"AuthParameters\":"
|
||||
+ "{\"ApiKeyAuthParameters\":{\"ApiKeyName\":\"k\",\"ApiKeyValue\":\"v\"}}}";
|
||||
ok("CreateConnection", conn);
|
||||
refused("CreateConnection", conn, ae,
|
||||
"Connection emsg-dup-conn already exists.");
|
||||
|
||||
String replay = "{\"ReplayName\":\"emsg-dup-replay\",\"EventSourceArn\":\"arn:aws:events:us-east-1:"
|
||||
+ "000000000000:archive/emsg-dup-arch\",\"EventStartTime\":1700000000,\"EventEndTime\":1700000100,"
|
||||
+ "\"Destination\":{\"Arn\":\"" + BUS_ARN + "default\"}}";
|
||||
ok("StartReplay", replay);
|
||||
refused("StartReplay", replay, ae, "Replay emsg-dup-replay already exists.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidStateAndPreconditionRefusals() {
|
||||
refused("DeleteEventBus", "{\"Name\":\"default\"}", "ValidationException",
|
||||
"Cannot delete event bus default.");
|
||||
|
||||
createBus("emsg-rules-bus");
|
||||
ok("PutRule", "{\"Name\":\"r1\",\"EventBusName\":\"emsg-rules-bus\","
|
||||
+ "\"EventPattern\":\"{\\\"source\\\":[\\\"x\\\"]}\"}");
|
||||
refused("DeleteEventBus", "{\"Name\":\"emsg-rules-bus\"}", "ValidationException",
|
||||
"EventBus can't be deleted since it has rules.");
|
||||
|
||||
ok("PutTargets", "{\"Rule\":\"r1\",\"EventBusName\":\"emsg-rules-bus\",\"Targets\":[{\"Id\":\"1\","
|
||||
+ "\"Arn\":\"arn:aws:sqs:us-east-1:000000000000:q\"}]}");
|
||||
refused("DeleteRule", "{\"Name\":\"r1\",\"EventBusName\":\"emsg-rules-bus\"}", "ValidationException",
|
||||
"Rule can't be deleted since it has targets.");
|
||||
|
||||
refused("StartReplay", "{\"ReplayName\":\"emsg-bad-src\",\"EventSourceArn\":\"arn:aws:events:us-east-1:"
|
||||
+ "000000000000:archive/emsg-gone\",\"EventStartTime\":1700000000,\"EventEndTime\":1700000100,"
|
||||
+ "\"Destination\":{\"Arn\":\"" + BUS_ARN + "default\"}}", "ValidationException",
|
||||
"Parameter EventSourceArn is not valid. Reason: Archive emsg-gone does not exist.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void connectionAndApiDestinationWritesOnMissingResourcesNameTheCall() {
|
||||
String nf = "ResourceNotFoundException";
|
||||
refused("UpdateConnection", "{\"Name\":\"emsg-w-conn\",\"Description\":\"d\"}", nf,
|
||||
"Failed to update the connection(s). Connection 'emsg-w-conn' does not exist.");
|
||||
refused("DeleteConnection", "{\"Name\":\"emsg-w-conn\"}", nf,
|
||||
"Connection emsg-w-conn does not exist.");
|
||||
refused("UpdateApiDestination", "{\"Name\":\"emsg-w-dest\",\"Description\":\"d\"}", nf,
|
||||
"Failed to update the api-destination(s). An api-destination 'emsg-w-dest' does not exist.");
|
||||
refused("DeleteApiDestination", "{\"Name\":\"emsg-w-dest\"}", nf,
|
||||
"ApiDestination emsg-w-dest does not exist.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void untagOnMissingRuleArnNamesRuleAndBus() {
|
||||
refused("UntagResource", "{\"ResourceARN\":\"arn:aws:events:us-east-1:000000000000:rule/emsg-untag\","
|
||||
+ "\"TagKeys\":[\"k\"]}", "ResourceNotFoundException",
|
||||
"Rule emsg-untag does not exist on EventBus default.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagCallsOnMissingResourcesUseThePerKindWording() {
|
||||
String nf = "ResourceNotFoundException";
|
||||
String events = "arn:aws:events:us-east-1:000000000000:";
|
||||
refused("ListTagsForResource", "{\"ResourceARN\":\"" + events + "archive/emsg-tag-arch\"}", nf,
|
||||
"Resource not found: " + events + "archive/emsg-tag-arch");
|
||||
refused("TagResource", "{\"ResourceARN\":\"" + events + "rule/emsg-tag-bus/emsg-tag-rule\","
|
||||
+ "\"Tags\":[]}", nf, "Rule emsg-tag-rule does not exist on EventBus emsg-tag-bus.");
|
||||
refused("UntagResource", "{\"ResourceARN\":\"" + events + "event-bus/emsg-tag-bus\","
|
||||
+ "\"TagKeys\":[\"k\"]}", nf, "Event bus emsg-tag-bus does not exist.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void listRuleNamesByTargetOnMissingBusUsesTheBusWording() {
|
||||
refused("ListRuleNamesByTarget", "{\"TargetArn\":\"arn:aws:sqs:us-east-1:000000000000:q\","
|
||||
+ "\"EventBusName\":\"emsg-lrnbt-bus\"}", "ResourceNotFoundException",
|
||||
"Event bus emsg-lrnbt-bus does not exist.");
|
||||
}
|
||||
}
|
||||
+18
-5
@@ -265,6 +265,19 @@ class EventBridgeReplayIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void completedReplayCannotBeCancelled() {
|
||||
given()
|
||||
.contentType(EB_CT)
|
||||
.header("X-Amz-Target", "AWSEvents.CancelReplay")
|
||||
.body("{\"ReplayName\":\"test-replay-1\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("IllegalStatusException"))
|
||||
.body("message", equalTo("Replay test-replay-1 is not in a valid state for this operation."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void updateArchive() {
|
||||
given()
|
||||
.contentType(EB_CT)
|
||||
@@ -291,7 +304,7 @@ class EventBridgeReplayIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
@Order(13)
|
||||
void deleteArchive() {
|
||||
given()
|
||||
.contentType(EB_CT)
|
||||
@@ -310,7 +323,7 @@ class EventBridgeReplayIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
@Order(14)
|
||||
void missingReplayUsesAwsResourceNotFoundStatus() {
|
||||
given()
|
||||
.contentType(EB_CT)
|
||||
@@ -322,7 +335,7 @@ class EventBridgeReplayIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(14)
|
||||
@Order(15)
|
||||
void updateArchiveKeepsTheFieldsTheRequestOmits() {
|
||||
createPartialUpdateArchive("partial-keep-archive");
|
||||
|
||||
@@ -338,7 +351,7 @@ class EventBridgeReplayIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(15)
|
||||
@Order(16)
|
||||
void updateArchiveClearsTheDescriptionAndPatternGivenAsEmptyStrings() {
|
||||
createPartialUpdateArchive("partial-clear-archive");
|
||||
|
||||
@@ -354,7 +367,7 @@ class EventBridgeReplayIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
@Order(17)
|
||||
void updateArchiveSetsAnExplicitZeroRetention() {
|
||||
createPartialUpdateArchive("partial-zero-archive");
|
||||
|
||||
|
||||
@@ -2497,4 +2497,11 @@ class EventBridgeServiceTest {
|
||||
assertEquals(0, ((ArrayNode) EventBridgeService.serviceEventEntry("s", "d", "{}", null).get("Resources")).size());
|
||||
assertEquals(0, ((ArrayNode) EventBridgeService.serviceEventEntry("s", "d", "{}", " ").get("Resources")).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void findConnectionByArnKeepsThePlainMessageForInternalCallers() {
|
||||
String arn = "arn:aws:events:us-east-1:000000000000:connection/nope/abc";
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.findConnectionByArn(arn, "us-east-1"));
|
||||
assertEquals("Connection " + arn + " does not exist.", e.getMessage());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user