mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -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
@@ -8,7 +8,7 @@
|
||||
<!-- floci:actions:start -->
|
||||
| Action | Description |
|
||||
| --- | --- |
|
||||
| `CreateEventBus` | Create a custom event bus |
|
||||
| `CreateEventBus` | Create a custom event bus, with its description, KMS key, dead-letter config and log config |
|
||||
| `DeleteEventBus` | Delete an event bus |
|
||||
| `DescribeEventBus` | Get event bus details |
|
||||
| `UpdateEventBus` | Update event bus description, KMS key, dead-letter config, or log config |
|
||||
|
||||
+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);
|
||||
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package io.github.hectorvent.floci.services.eventbridge;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
* CreateEventBus keeps the KMS key, dead-letter queue and log configuration it is given, as
|
||||
* {@code terraform-aws-modules/eventbridge} sets them on a bus with {@code log_config}: the create
|
||||
* response echoes them, and DescribeEventBus and ListEventBuses report them afterwards.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class EventBridgeCreateEventBusIntegrationTest {
|
||||
|
||||
private static final String CT = "application/x-amz-json-1.1";
|
||||
private static final String CREATE = "AWSEvents.CreateEventBus";
|
||||
private static final String DESCRIBE = "AWSEvents.DescribeEventBus";
|
||||
private static final String LIST = "AWSEvents.ListEventBuses";
|
||||
private static final String DELETE = "AWSEvents.DeleteEventBus";
|
||||
private static final String DLQ = "arn:aws:sqs:us-east-1:000000000000:bus-dlq";
|
||||
private static final String KEY = "arn:aws:kms:us-east-1:000000000000:key/1234abcd-12ab-34cd-56ef-1234567890ab";
|
||||
|
||||
@BeforeAll
|
||||
static void configure() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void theConfigurationGivenOnCreateIsKeptAndEchoed() {
|
||||
String bus = "create-config-bus";
|
||||
given().contentType(CT).header("X-Amz-Target", CREATE)
|
||||
.body("""
|
||||
{"Name": "%s", "Description": "orders",
|
||||
"KmsKeyIdentifier": "%s",
|
||||
"DeadLetterConfig": {"Arn": "%s"},
|
||||
"LogConfig": {"IncludeDetail": "NONE", "Level": "ERROR"}}
|
||||
""".formatted(bus, KEY, DLQ))
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("EventBusArn", endsWith(":event-bus/" + bus))
|
||||
.body("Description", equalTo("orders"))
|
||||
.body("KmsKeyIdentifier", equalTo(KEY))
|
||||
.body("DeadLetterConfig.Arn", equalTo(DLQ))
|
||||
.body("LogConfig.IncludeDetail", equalTo("NONE"))
|
||||
.body("LogConfig.Level", equalTo("ERROR"))
|
||||
.body("Name", nullValue())
|
||||
.body("CreationTime", nullValue());
|
||||
|
||||
given().contentType(CT).header("X-Amz-Target", DESCRIBE)
|
||||
.body("{\"Name\":\"" + bus + "\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("KmsKeyIdentifier", equalTo(KEY))
|
||||
.body("DeadLetterConfig.Arn", equalTo(DLQ))
|
||||
.body("LogConfig.IncludeDetail", equalTo("NONE"))
|
||||
.body("LogConfig.Level", equalTo("ERROR"));
|
||||
given().contentType(CT).header("X-Amz-Target", LIST)
|
||||
.body("{\"NamePrefix\":\"" + bus + "\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("EventBuses.LogConfig.Level", hasItem("ERROR"));
|
||||
|
||||
delete(bus);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aBusCreatedWithoutConfigurationOrWithEmptyObjectsHasNone() {
|
||||
String bus = "create-bare-bus";
|
||||
given().contentType(CT).header("X-Amz-Target", CREATE)
|
||||
.body("{\"Name\":\"" + bus + "\",\"DeadLetterConfig\":{},\"LogConfig\":{}}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("EventBusArn", endsWith(":event-bus/" + bus))
|
||||
.body("DeadLetterConfig", nullValue())
|
||||
.body("LogConfig", nullValue());
|
||||
|
||||
given().contentType(CT).header("X-Amz-Target", DESCRIBE)
|
||||
.body("{\"Name\":\"" + bus + "\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("KmsKeyIdentifier", nullValue())
|
||||
.body("DeadLetterConfig", nullValue())
|
||||
.body("LogConfig", nullValue());
|
||||
|
||||
delete(bus);
|
||||
}
|
||||
|
||||
private static void delete(String bus) {
|
||||
given().contentType(CT).header("X-Amz-Target", DELETE)
|
||||
.body("{\"Name\":\"" + bus + "\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user