Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix: issues 226 227 (#257)

edwintian81f1a01c39c0
diff --git a/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeHandler.java b/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeHandler.java
index 383572d004..171e319ed2 100644
--- a/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeHandler.java
@@ -57,6 +57,7 @@ public class EventBridgeHandler {
case "RemoveTargets" -> handleRemoveTargets(request, region);
case "ListTargetsByRule" -> handleListTargetsByRule(request, region);
case "PutEvents" -> handlePutEvents(request, region);
+ case "ListTagsForResource" -> handleListTagsForResource(request, region);
default -> Response.status(400)
.entity(new AwsErrorResponse("UnsupportedOperation", "Operation " + action + " is not supported."))
.build();
@@ -264,6 +265,23 @@ public class EventBridgeHandler {
return Response.ok(response).build();
}
+ private Response handleListTagsForResource(JsonNode request, String region) {
+ String resourceArn = request.path("ResourceARN").asText(null);
+ if (resourceArn == null || resourceArn.isBlank()) {
+ throw new AwsException("InvalidParameterValue", "ResourceARN is required.", 400);
+ }
+ Map<String, String> tags = eventBridgeService.listTagsForResource(resourceArn, region);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode tagsArray = response.putArray("Tags");
+ tags.forEach((key, value) -> {
+ ObjectNode tagNode = objectMapper.createObjectNode();
+ tagNode.put("Key", key);
+ tagNode.put("Value", value);
+ tagsArray.add(tagNode);
+ });
+ return Response.ok(response).build();
+ }
+
// ──────────────────────────── Helpers ────────────────────────────
private ObjectNode buildBusNode(EventBus bus) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java b/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java
index ecf23b283d..8b75cd3f87 100644
--- a/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java
@@ -305,6 +305,40 @@ public class EventBridgeService {
return targetStore.get(key).orElse(List.of());
}
+ // ──────────────────────────── Tags ────────────────────────────
+
+ public Map<String, String> listTagsForResource(String resourceArn, String region) {
+ // Check if it's an event bus ARN (contains "event-bus/")
+ if (resourceArn.contains("event-bus/")) {
+ String busName = resourceArn.substring(resourceArn.lastIndexOf("event-bus/") + "event-bus/".length());
+ String key = busKey(region, busName);
+ return busStore.get(key)
+ .map(EventBus::getTags)
+ .orElse(Map.of());
+ }
+ // Check if it's a rule ARN (contains "rule/")
+ if (resourceArn.contains("rule/")) {
+ String afterRule = resourceArn.substring(resourceArn.lastIndexOf("rule/") + "rule/".length());
+ String busName;
+ String ruleName;
+ if (afterRule.contains("/")) {
+ // Custom bus: rule/{busName}/{ruleName}
+ int slashIdx = afterRule.indexOf('/');
+ busName = afterRule.substring(0, slashIdx);
+ ruleName = afterRule.substring(slashIdx + 1);
+ } else {
+ // Default bus: rule/{ruleName}
+ busName = "default";
+ ruleName = afterRule;
+ }
+ String key = ruleKey(region, busName, ruleName);
+ return ruleStore.get(key)
+ .map(Rule::getTags)
+ .orElse(Map.of());
+ }
+ return Map.of();
+ }
+
// ──────────────────────────── PutEvents ────────────────────────────
public record PutEventsResult(int failedCount, List<Map<String, String>> entries) {}
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java
index 35e9a06679..fe100c01a6 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java
@@ -148,6 +148,22 @@ public class LambdaController {
return Response.noContent().build();
}
+ // ──────────────────────────── GetFunctionCodeSigningConfig ────────────────────────────
+
+ @GET
+ @Path("/functions/{functionName}/code-signing-config")
+ public Response getFunctionCodeSigningConfig(@Context HttpHeaders headers,
+ @PathParam("functionName") String functionName) {
+ String region = regionResolver.resolveRegion(headers);
+ // Verify the function exists
+ lambdaService.getFunction(region, functionName);
+ // Return empty code signing config — floci does not enforce code signing
+ ObjectNode root = objectMapper.createObjectNode();
+ root.put("CodeSigningConfigArn", "");
+ root.put("FunctionName", functionName);
+ return Response.ok(root).build();
+ }
+
// ──────────────────────────── Invoke ────────────────────────────
@POST
diff --git a/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeListTagsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeListTagsIntegrationTest.java
new file mode 100644
index 0000000000..5048cbaf06
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeListTagsIntegrationTest.java
@@ -0,0 +1,131 @@
+package io.github.hectorvent.floci.services.eventbridge;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.config.EncoderConfig;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.*;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.*;
+
+@QuarkusTest
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+class EventBridgeListTagsIntegrationTest {
+
+ private static final String EVENT_BRIDGE_CONTENT_TYPE = "application/x-amz-json-1.1";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssured.config = RestAssured.config().encoderConfig(
+ EncoderConfig.encoderConfig()
+ .encodeContentTypeAs(EVENT_BRIDGE_CONTENT_TYPE, ContentType.TEXT)
+ );
+ }
+
+ @Test
+ @Order(1)
+ void createRuleWithTags() {
+ given()
+ .contentType(EVENT_BRIDGE_CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSEvents.PutRule")
+ .body("""
+ {
+ "Name": "tagged-rule",
+ "Tags": [
+ {"Key": "env", "Value": "test"},
+ {"Key": "team", "Value": "platform"}
+ ]
+ }
+ """)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("RuleArn", notNullValue());
+ }
+
+ @Test
+ @Order(2)
+ void listTagsForRuleResource() {
+ // First get the rule ARN
+ String ruleArn = given()
+ .contentType(EVENT_BRIDGE_CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSEvents.DescribeRule")
+ .body("{\"Name\":\"tagged-rule\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .extract().jsonPath().getString("Arn");
+
+ // Now list tags for the rule
+ given()
+ .contentType(EVENT_BRIDGE_CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSEvents.ListTagsForResource")
+ .body("{\"ResourceARN\":\"" + ruleArn + "\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("Tags", hasSize(2))
+ .body("Tags.find { it.Key == 'env' }.Value", equalTo("test"))
+ .body("Tags.find { it.Key == 'team' }.Value", equalTo("platform"));
+ }
+
+ @Test
+ @Order(3)
+ void listTagsForResourceWithNoTags() {
+ // Create a rule with no tags
+ given()
+ .contentType(EVENT_BRIDGE_CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSEvents.PutRule")
+ .body("{\"Name\":\"untagged-rule\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ String ruleArn = given()
+ .contentType(EVENT_BRIDGE_CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSEvents.DescribeRule")
+ .body("{\"Name\":\"untagged-rule\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .extract().jsonPath().getString("Arn");
+
+ given()
+ .contentType(EVENT_BRIDGE_CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSEvents.ListTagsForResource")
+ .body("{\"ResourceARN\":\"" + ruleArn + "\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("Tags", hasSize(0));
+ }
+
+ @Test
+ @Order(4)
+ void cleanup() {
+ given()
+ .contentType(EVENT_BRIDGE_CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSEvents.DeleteRule")
+ .body("{\"Name\":\"tagged-rule\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ given()
+ .contentType(EVENT_BRIDGE_CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSEvents.DeleteRule")
+ .body("{\"Name\":\"untagged-rule\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningConfigIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningConfigIntegrationTest.java
new file mode 100644
index 0000000000..6c450c0f43
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningConfigIntegrationTest.java
@@ -0,0 +1,71 @@
+package io.github.hectorvent.floci.services.lambda;
+
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.*;
+
+@QuarkusTest
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+class LambdaCodeSigningConfigIntegrationTest {
+
+ private static final String BASE_PATH = "/2015-03-31";
+ private static final String FUNCTION_NAME = "code-signing-test-function";
+
+ @Test
+ @Order(1)
+ void createFunction() {
+ given()
+ .contentType("application/json")
+ .body(String.format("""
+ {
+ "FunctionName": "%s",
+ "Runtime": "nodejs20.x",
+ "Role": "arn:aws:iam::000000000000:role/lambda-role",
+ "Handler": "index.handler",
+ "Description": "Code signing config test function"
+ }
+ """, FUNCTION_NAME))
+ .when()
+ .post(BASE_PATH + "/functions")
+ .then()
+ .statusCode(201)
+ .body("FunctionName", equalTo(FUNCTION_NAME));
+ }
+
+ @Test
+ @Order(2)
+ void getFunctionCodeSigningConfig() {
+ given()
+ .when()
+ .get(BASE_PATH + "/functions/" + FUNCTION_NAME + "/code-signing-config")
+ .then()
+ .statusCode(200)
+ .body("FunctionName", equalTo(FUNCTION_NAME))
+ .body("CodeSigningConfigArn", notNullValue());
+ }
+
+ @Test
+ @Order(3)
+ void getFunctionCodeSigningConfigNotFound() {
+ given()
+ .when()
+ .get(BASE_PATH + "/functions/nonexistent-function/code-signing-config")
+ .then()
+ .statusCode(404);
+ }
+
+ @Test
+ @Order(4)
+ void cleanup() {
+ given()
+ .when()
+ .delete(BASE_PATH + "/functions/" + FUNCTION_NAME)
+ .then()
+ .statusCode(204);
+ }
+}