mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(apigatewayv2): cascade-delete child resources and 404 references … (#1300)
* fix(apigatewayv2): cascade-delete child resources and 404 references on DeleteApi Closes #1218. DeleteApi removed only the Api row, leaving routes, integrations, stages, deployments, authorizers, models, route responses, and integration responses orphaned under their region::apiId::* keys. The list endpoints also silently returned empty lists for unknown apiIds instead of 404. Both diverge from real AWS (children deleted; subsequent reads return NotFoundException). - deleteApi now cascades through every api-scoped child store, mirroring the existing apigateway v1 deleteRestApi pattern (api row first, then inline stream-based deletes per store, then LOG.infov). - VpcLink is region-scoped (region::vpcLinkId — shared across APIs) and intentionally excluded from the cascade. - getRoutes / getStages / getIntegrations / getAuthorizers / getModels / getDeployments / getRouteResponses / getIntegrationResponses now call getApi(region, apiId) first so they 404 when the API doesn't exist, matching real AWS behavior. Verified end-to-end with boto3 against running Floci: the reproduction from #1218 went from 6 leaked child types on main to 0 with this branch. * refactor(apigatewayv2): extract deleteByPrefix helper, consolidate cascade tests
This commit is contained in:
1 parent
1ffa9a4e21
commit
bb5a37d19e
2 files changed
+202
No files matched your search
+24
@@ -125,6 +125,22 @@ public class ApiGatewayV2Service {
|
||||
public void deleteApi(String region, String apiId) {
|
||||
getApi(region, apiId);
|
||||
apiStore.delete(apiKey(region, apiId));
|
||||
// Cascade-delete every child resource keyed under region::apiId::*.
|
||||
// VpcLink is region-scoped (region::vpcLinkId, shared across APIs) and excluded.
|
||||
String prefix = region + "::" + apiId + "::";
|
||||
deleteByPrefix(routeStore, prefix);
|
||||
deleteByPrefix(integrationStore, prefix);
|
||||
deleteByPrefix(authorizerStore, prefix);
|
||||
deleteByPrefix(deploymentStore, prefix);
|
||||
deleteByPrefix(stageStore, prefix);
|
||||
deleteByPrefix(modelStore, prefix);
|
||||
deleteByPrefix(routeResponseStore, prefix);
|
||||
deleteByPrefix(integrationResponseStore, prefix);
|
||||
LOG.infov("Deleted HTTP API: {0} in {1}", apiId, region);
|
||||
}
|
||||
|
||||
private static void deleteByPrefix(StorageBackend<String, ?> store, String prefix) {
|
||||
store.keys().stream().filter(k -> k.startsWith(prefix)).forEach(store::delete);
|
||||
}
|
||||
|
||||
public Api updateApi(String region, String apiId, Map<String, Object> request) {
|
||||
@@ -220,6 +236,7 @@ public class ApiGatewayV2Service {
|
||||
}
|
||||
|
||||
public List<Authorizer> getAuthorizers(String region, String apiId) {
|
||||
getApi(region, apiId);
|
||||
String prefix = region + "::" + apiId + "::";
|
||||
return authorizerStore.scan(k -> k.startsWith(prefix));
|
||||
}
|
||||
@@ -296,6 +313,7 @@ public class ApiGatewayV2Service {
|
||||
}
|
||||
|
||||
public List<Route> getRoutes(String region, String apiId) {
|
||||
getApi(region, apiId);
|
||||
String prefix = region + "::" + apiId + "::";
|
||||
return routeStore.scan(k -> k.startsWith(prefix));
|
||||
}
|
||||
@@ -433,6 +451,7 @@ public class ApiGatewayV2Service {
|
||||
}
|
||||
|
||||
public List<Integration> getIntegrations(String region, String apiId) {
|
||||
getApi(region, apiId);
|
||||
String prefix = region + "::" + apiId + "::";
|
||||
return integrationStore.scan(k -> k.startsWith(prefix));
|
||||
}
|
||||
@@ -516,6 +535,7 @@ public class ApiGatewayV2Service {
|
||||
}
|
||||
|
||||
public List<Stage> getStages(String region, String apiId) {
|
||||
getApi(region, apiId);
|
||||
String prefix = region + "::" + apiId + "::";
|
||||
return stageStore.scan(k -> k.startsWith(prefix));
|
||||
}
|
||||
@@ -583,6 +603,7 @@ public class ApiGatewayV2Service {
|
||||
}
|
||||
|
||||
public List<Deployment> getDeployments(String region, String apiId) {
|
||||
getApi(region, apiId);
|
||||
String prefix = region + "::" + apiId + "::";
|
||||
return deploymentStore.scan(k -> k.startsWith(prefix));
|
||||
}
|
||||
@@ -634,6 +655,7 @@ public class ApiGatewayV2Service {
|
||||
}
|
||||
|
||||
public List<RouteResponse> getRouteResponses(String region, String apiId, String routeId) {
|
||||
getApi(region, apiId);
|
||||
String prefix = region + "::" + apiId + "::" + routeId + "::";
|
||||
return routeResponseStore.scan(k -> k.startsWith(prefix));
|
||||
}
|
||||
@@ -698,6 +720,7 @@ public class ApiGatewayV2Service {
|
||||
}
|
||||
|
||||
public List<IntegrationResponse> getIntegrationResponses(String region, String apiId, String integrationId) {
|
||||
getApi(region, apiId);
|
||||
String prefix = region + "::" + apiId + "::" + integrationId + "::";
|
||||
return integrationResponseStore.scan(k -> k.startsWith(prefix));
|
||||
}
|
||||
@@ -754,6 +777,7 @@ public class ApiGatewayV2Service {
|
||||
}
|
||||
|
||||
public List<Model> getModels(String region, String apiId) {
|
||||
getApi(region, apiId);
|
||||
String prefix = region + "::" + apiId + "::";
|
||||
return modelStore.scan(k -> k.startsWith(prefix));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user