Light, fluffy, and always free - The AWS Local Emulator alternative
fix(apigatewayv2): return stage tags across protocols (#2413)
Saatvik Arya5744082c5eb3
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/ApiGatewayV2ManagementTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/ApiGatewayV2ManagementTest.javaindex 015011cc16..21ec5ab97d 100644--- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/ApiGatewayV2ManagementTest.java+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/ApiGatewayV2ManagementTest.java@@ -40,6 +40,7 @@ import software.amazon.awssdk.services.apigatewayv2.model.NotFoundException;import software.amazon.awssdk.services.apigatewayv2.model.ProtocolType;import java.util.List;+import java.util.Map;import static org.assertj.core.api.Assertions.assertThat;import static org.assertj.core.api.Assertions.assertThatThrownBy;@@ -311,6 +312,7 @@ class ApiGatewayV2ManagementTest {.stageName(stageName).deploymentId(deploymentId).autoDeploy(false)+ .tags(Map.of("environment", "test", "owner", "platform")).build());assertThat(response.stageName()).isEqualTo(stageName);@@ -318,6 +320,9 @@ class ApiGatewayV2ManagementTest {assertThat(response.autoDeploy()).isFalse();assertThat(response.createdDate()).isNotNull();assertThat(response.lastUpdatedDate()).isNotNull();+ assertThat(response.tags())+ .containsEntry("environment", "test")+ .containsEntry("owner", "platform");stageCreated = true;}@@ -333,6 +338,9 @@ class ApiGatewayV2ManagementTest {assertThat(getResponse.stageName()).isEqualTo(stageName);assertThat(getResponse.deploymentId()).isEqualTo(deploymentId);+ assertThat(getResponse.tags())+ .containsEntry("environment", "test")+ .containsEntry("owner", "platform");var listResponse = apigwv2.getStages(GetStagesRequest.builder().apiId(apiId)@@ -347,6 +355,13 @@ class ApiGatewayV2ManagementTest {.first().extracting(item -> item.deploymentId()).isEqualTo(deploymentId);+ assertThat(listResponse.items())+ .filteredOn(item -> stageName.equals(item.stageName()))+ .first()+ .extracting(item -> item.tags())+ .satisfies(tags -> assertThat(tags)+ .containsEntry("environment", "test")+ .containsEntry("owner", "platform"));}@Testdiff --git a/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayController.java b/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayController.javaindex 2f982684f9..3353c2f706 100644--- a/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayController.java+++ b/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayController.java@@ -2181,6 +2181,10 @@ public class ApiGatewayController {ObjectNode stageVariables = node.putObject("stageVariables");s.getStageVariables().forEach(stageVariables::put);}+ if (s.getTags() != null && !s.getTags().isEmpty()) {+ ObjectNode tags = node.putObject("tags");+ s.getTags().forEach(tags::put);+ }return node;}diff --git a/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2JsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2JsonHandler.javaindex 86f9848010..24b68f0304 100644--- a/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2JsonHandler.java+++ b/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2JsonHandler.java@@ -632,6 +632,10 @@ public class ApiGatewayV2JsonHandler {ObjectNode stageVariables = node.putObject("StageVariables");s.getStageVariables().forEach(stageVariables::put);}+ if (s.getTags() != null && !s.getTags().isEmpty()) {+ ObjectNode tags = node.putObject("Tags");+ s.getTags().forEach(tags::put);+ }return node;}@@ -711,7 +715,8 @@ public class ApiGatewayV2JsonHandler {if (!key.isEmpty() && Character.isUpperCase(key.charAt(0))) {key = Character.toLowerCase(key.charAt(0)) + key.substring(1);}- result.put(key, normalizeValue(entry.getValue()));+ Object value = "tags".equals(key) ? entry.getValue() : normalizeValue(entry.getValue());+ result.put(key, value);}return result;}diff --git a/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2Service.java b/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2Service.javaindex 93b0650587..bfe7d515b4 100644--- a/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2Service.java+++ b/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2Service.java@@ -593,6 +593,12 @@ public class ApiGatewayV2Service {Map<String, String> stageVariables = (Map<String, String>) request.get("stageVariables");stage.setStageVariables(stageVariables);+ @SuppressWarnings("unchecked")+ Map<String, String> tags = (Map<String, String>) request.get("tags");+ if (tags != null) {+ stage.setTags(ReservedTags.stripApiGatewayReservedTags(tags));+ }+stageStore.put(stageKey(region, apiId, stage.getStageName()), stage);LOG.infov("Created stage: {0} for API {1}", stage.getStageName(), apiId);return stage;diff --git a/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/model/Stage.java b/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/model/Stage.javaindex 8f5cc9fa71..d7e86155e1 100644--- a/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/model/Stage.java+++ b/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/model/Stage.java@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.apigatewayv2.model;import com.fasterxml.jackson.annotation.JsonIgnoreProperties;import io.quarkus.runtime.annotations.RegisterForReflection;+import java.util.HashMap;import java.util.Map;@RegisterForReflection@@ -14,6 +15,7 @@ public class Stage {private long createdDate;private long lastUpdatedDate;private Map<String, String> stageVariables;+ private Map<String, String> tags = new HashMap<>();public Stage() {}@@ -34,4 +36,7 @@ public class Stage {public Map<String, String> getStageVariables() { return stageVariables; }public void setStageVariables(Map<String, String> stageVariables) { this.stageVariables = stageVariables; }++ public Map<String, String> getTags() { return tags; }+ public void setTags(Map<String, String> tags) { this.tags = tags; }}diff --git a/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2IntegrationTest.javaindex f58cb8ff9b..0405be2589 100644--- a/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2IntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2IntegrationTest.java@@ -243,14 +243,17 @@ class ApiGatewayV2IntegrationTest {given().contentType(ContentType.JSON).body("""- {"stageName":"prod","deploymentId":"%s","autoDeploy":false}+ {"stageName":"prod","deploymentId":"%s","autoDeploy":false,"tags":{"environment":"test","owner":"platform","floci:internal":"hidden"}}""".formatted(deploymentId)).when().post("/v2/apis/" + apiId + "/stages").then().statusCode(201).body("stageName", equalTo("prod")).body("autoDeploy", equalTo(false))- .body("deploymentId", equalTo(deploymentId));+ .body("deploymentId", equalTo(deploymentId))+ .body("tags.environment", equalTo("test"))+ .body("tags.owner", equalTo("platform"))+ .body("tags", not(hasKey("floci:internal")));}@Test @Order(51)@@ -261,7 +264,9 @@ class ApiGatewayV2IntegrationTest {.statusCode(200).body("stageName", equalTo("prod")).body("deploymentId", equalTo(deploymentId))- .body("autoDeploy", equalTo(false));+ .body("autoDeploy", equalTo(false))+ .body("tags.environment", equalTo("test"))+ .body("tags.owner", equalTo("platform"));}@Test @Order(52)@@ -270,7 +275,24 @@ class ApiGatewayV2IntegrationTest {.when().get("/v2/apis/" + apiId + "/stages").then().statusCode(200)- .body("items.stageName", hasItem("prod"));+ .body("items.stageName", hasItem("prod"))+ .body("items.find { it.stageName == 'prod' }.tags.environment", equalTo("test"))+ .body("items.find { it.stageName == 'prod' }.tags.owner", equalTo("platform"));+ }++ @Test @Order(53)+ void updateStageReturnsTags() {+ given()+ .contentType(ContentType.JSON)+ .body("""+ {"autoDeploy":true}+ """)+ .when().patch("/v2/apis/" + apiId + "/stages/prod")+ .then()+ .statusCode(200)+ .body("autoDeploy", equalTo(true))+ .body("tags.environment", equalTo("test"))+ .body("tags.owner", equalTo("platform"));}// ──────────────────────────── Cleanup ────────────────────────────diff --git a/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2JsonHandlerTest.java b/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2JsonHandlerTest.javaindex 7fb51b7498..d810b3605f 100644--- a/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2JsonHandlerTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2JsonHandlerTest.java@@ -98,7 +98,7 @@ class ApiGatewayV2JsonHandlerTest {@Test@Order(3)- void json11CreateDeploymentAndStage() {+ void json11StageResponsesReturnTags() {deploymentId = given().contentType(AMZ_JSON).header("X-Amz-Target", TARGET_PREFIX + "CreateDeployment")@@ -117,13 +117,55 @@ class ApiGatewayV2JsonHandlerTest {.header("X-Amz-Target", TARGET_PREFIX + "CreateStage").header("Authorization", AUTH_HEADER).body("""- {"ApiId":"%s","StageName":"prod","DeploymentId":"%s"}+ {"ApiId":"%s","StageName":"prod","DeploymentId":"%s","Tags":{"Environment":"test","Owner":"platform"}}""".formatted(apiId, deploymentId)).when().post("/").then().statusCode(201).body("StageName", equalTo("prod"))- .body("DeploymentId", equalTo(deploymentId));+ .body("DeploymentId", equalTo(deploymentId))+ .body("Tags.Environment", equalTo("test"))+ .body("Tags.Owner", equalTo("platform"));++ given()+ .contentType(AMZ_JSON)+ .header("X-Amz-Target", TARGET_PREFIX + "GetStage")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"ApiId":"%s","StageName":"prod"}+ """.formatted(apiId))+ .when().post("/")+ .then()+ .statusCode(200)+ .body("Tags.Environment", equalTo("test"))+ .body("Tags.Owner", equalTo("platform"));++ given()+ .contentType(AMZ_JSON)+ .header("X-Amz-Target", TARGET_PREFIX + "GetStages")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"ApiId":"%s"}+ """.formatted(apiId))+ .when().post("/")+ .then()+ .statusCode(200)+ .body("Items.find { it.StageName == 'prod' }.Tags.Environment", equalTo("test"))+ .body("Items.find { it.StageName == 'prod' }.Tags.Owner", equalTo("platform"));++ given()+ .contentType(AMZ_JSON)+ .header("X-Amz-Target", TARGET_PREFIX + "UpdateStage")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"ApiId":"%s","StageName":"prod","AutoDeploy":true}+ """.formatted(apiId))+ .when().post("/")+ .then()+ .statusCode(200)+ .body("AutoDeploy", equalTo(true))+ .body("Tags.Environment", equalTo("test"))+ .body("Tags.Owner", equalTo("platform"));}@Test