mirror of
https://github.com/floci-io/floci.git
synced 2026-11-26 23:29:28 -05:00
fix(eventbridge): keep the KMS key, dead-letter and log config given to CreateEventBus (#7444)
CreateEventBus dropped KmsKeyIdentifier, DeadLetterConfig and LogConfig, which UpdateEventBus already stored, so a bus created with them read back without them. Store them on create and echo them in the response, as the model's CreateEventBusResponse does.
This commit is contained in:
1 parent
342c79806d
commit
999abb3467
4 files changed
+136
-8
No files matched your search
+14
-7
@@ -118,10 +118,16 @@ public class EventBridgeHandler {
|
||||
private Response handleCreateEventBus(JsonNode request, String region) {
|
||||
String name = request.path("Name").asText(null);
|
||||
String description = request.path("Description").asText(null);
|
||||
String kmsKey = request.path("KmsKeyIdentifier").asText(null);
|
||||
Map<String, String> tags = parseTagsArray(request.path("Tags"));
|
||||
EventBus bus = eventBridgeService.createEventBus(name, description, tags, region);
|
||||
EventBus bus = eventBridgeService.createEventBus(name, description, kmsKey,
|
||||
configJson(request.path("DeadLetterConfig")), configJson(request.path("LogConfig")), tags, region);
|
||||
// CreateEventBus answers with the bus's ARN and the configuration it was given.
|
||||
ObjectNode configuration = buildBusNode(bus);
|
||||
configuration.remove(List.of("Name", "Arn", "CreationTime", "Policy"));
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("EventBusArn", bus.getArn());
|
||||
response.setAll(configuration);
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
@@ -143,15 +149,16 @@ public class EventBridgeHandler {
|
||||
String kmsKey = request.path("KmsKeyIdentifier").asText(null);
|
||||
// Empty {} is treated as "no change", matching how omitted/null inputs flow.
|
||||
// Only a populated object triggers a write to the bus's nested config field.
|
||||
JsonNode dlqNode = request.path("DeadLetterConfig");
|
||||
String dlq = (dlqNode.isObject() && !dlqNode.isEmpty()) ? dlqNode.toString() : null;
|
||||
JsonNode logNode = request.path("LogConfig");
|
||||
String logCfg = (logNode.isObject() && !logNode.isEmpty()) ? logNode.toString() : null;
|
||||
EventBus bus = eventBridgeService.updateEventBus(
|
||||
name, description, kmsKey, dlq, logCfg, region);
|
||||
EventBus bus = eventBridgeService.updateEventBus(name, description, kmsKey,
|
||||
configJson(request.path("DeadLetterConfig")), configJson(request.path("LogConfig")), region);
|
||||
return Response.ok(buildBusNode(bus)).build();
|
||||
}
|
||||
|
||||
/** A nested configuration object as its JSON; empty {} or absent means not given. */
|
||||
private static String configJson(JsonNode node) {
|
||||
return node.isObject() && !node.isEmpty() ? node.toString() : null;
|
||||
}
|
||||
|
||||
private Response handleListEventBuses(JsonNode request, String region) {
|
||||
String namePrefix = request.path("NamePrefix").asText(null);
|
||||
List<EventBus> buses = eventBridgeService.listEventBuses(namePrefix, region);
|
||||
|
||||
@@ -175,6 +175,17 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
|
||||
public EventBus createEventBus(String name, String description,
|
||||
Map<String, String> tags, String region) {
|
||||
return createEventBus(name, description, null, null, null, tags, region);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a custom bus with the KMS key, dead-letter queue and log configuration the request
|
||||
* gives, as {@code CreateEventBus} takes them; a null member leaves the bus without it. The
|
||||
* dead-letter and log configurations are stored as their JSON, as {@link #updateEventBus} does.
|
||||
*/
|
||||
public EventBus createEventBus(String name, String description, String kmsKeyIdentifier,
|
||||
String deadLetterConfig, String logConfig,
|
||||
Map<String, String> tags, String region) {
|
||||
validateCustomEventBusName(name);
|
||||
validateEventBusDescription(description);
|
||||
String key = busKey(region, name);
|
||||
@@ -188,6 +199,15 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
description,
|
||||
Instant.now()
|
||||
);
|
||||
if (kmsKeyIdentifier != null && !kmsKeyIdentifier.isBlank()) {
|
||||
bus.setKmsKeyIdentifier(kmsKeyIdentifier);
|
||||
}
|
||||
if (deadLetterConfig != null && !deadLetterConfig.isBlank()) {
|
||||
bus.setDeadLetterConfig(deadLetterConfig);
|
||||
}
|
||||
if (logConfig != null && !logConfig.isBlank()) {
|
||||
bus.setLogConfig(logConfig);
|
||||
}
|
||||
if (tags != null) {
|
||||
bus.getTags().putAll(tags);
|
||||
resourceGroupsTaggingService.tagResources(List.of(bus.getArn()), tags, region);
|
||||
|
||||
Reference in new issue
Block a user