mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(apigateway): create the stage when CreateDeployment carries a stageName (#2130)
CreateDeployment ignored the stageName parameter: the deployment was created but no stage was, so GetStages stayed empty and invoking the deployed API returned {"message":"Stage not found"}. Calling CreateStage explicitly afterwards was the only way to make the API reachable.
CreateDeployment creates the named stage pointing at the new deployment. When the stage already exists, repoint it while preserving its other settings so repeated Terraform applies remain usable. The API does not document this collision behavior. Stage variables from the request are applied either way, and omitting stageName still creates no stage.
Adds ApiGatewayDeploymentStageNameIntegrationTest (7 cases) following the reproduction from the report: the stage appears in GetStages, the deployed route answers 200 instead of "Stage not found", a redeploy moves the same single stage to the new deployment id, and no-stageName is unchanged.
This commit is contained in:
1 parent
7e5afae61b
commit
f34e0b5655
2 files changed
+239
No files matched your search
@@ -469,9 +469,44 @@ public class ApiGatewayService {
|
||||
Deployment deployment = new Deployment(shortId(10), description, System.currentTimeMillis() / 1000L);
|
||||
deploymentStore.put(deploymentKey(region, apiId, deployment.id()), deployment);
|
||||
LOG.infov("Created deployment {0} for API {1}", deployment.id(), apiId);
|
||||
|
||||
String stageName = (String) request.get("stageName");
|
||||
if (stageName != null && !stageName.isBlank()) {
|
||||
deployStage(region, apiId, stageName, deployment.id(), request);
|
||||
}
|
||||
return deployment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Points {@code stageName} at {@code deploymentId}, creating the stage if it doesn't exist.
|
||||
*
|
||||
* <p>The API does not document collision behavior. Repointing preserves existing stage
|
||||
* settings and supports repeated deployments.
|
||||
*/
|
||||
private void deployStage(String region, String apiId, String stageName, String deploymentId,
|
||||
Map<String, Object> request) {
|
||||
String key = stageKey(region, apiId, stageName);
|
||||
long now = System.currentTimeMillis() / 1000L;
|
||||
Stage stage = stageStore.get(key).orElse(null);
|
||||
if (stage == null) {
|
||||
stage = new Stage();
|
||||
stage.setStageName(stageName);
|
||||
stage.setCreatedDate(now);
|
||||
stage.setDescription((String) request.get("stageDescription"));
|
||||
}
|
||||
stage.setDeploymentId(deploymentId);
|
||||
stage.setLastUpdatedDate(now);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> variables = (Map<String, String>) request.get("variables");
|
||||
if (variables != null) {
|
||||
stage.setVariables(variables);
|
||||
}
|
||||
|
||||
stageStore.put(key, stage);
|
||||
LOG.infov("Deployed stage {0} of API {1} to deployment {2}", stageName, apiId, deploymentId);
|
||||
}
|
||||
|
||||
public List<Deployment> getDeployments(String region, String apiId) {
|
||||
getRestApi(region, apiId);
|
||||
String prefix = region + "::" + apiId + "::";
|
||||
|
||||
Reference in new issue
Block a user