mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
fix(apigatewayv2): return stage tags across protocols (#2413)
* fix(apigatewayv2): return stage tags across protocols * test(apigatewayv2): cover reserved stage tag stripping
This commit is contained in:
1 parent
5ed3a8cad9
commit
5744082c5e
7 files changed
+107
-8
No files matched your search
+15
@@ -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"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+6
-1
@@ -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;
|
||||
}
|
||||
|
||||
+6
@@ -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;
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
+26
-4
@@ -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 ────────────────────────────
|
||||
|
||||
+45
-3
@@ -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
|
||||
|
||||
Reference in new issue
Block a user