mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(cloudformation): move ApiGatewayV2 types into ApiGatewayV2CfnProvisioner (#4021)
Extracts the six AWS::ApiGatewayV2::* types (Api, Authorizer, Deployment, Integration, Route, Stage) and the OpenAPI body subsystem out of the CloudFormationResourceProvisioner monolith into a dedicated ApiGatewayV2CfnProvisioner, continuing the per-service provisioner migration. Behavior is preserved for the attributes the monolith already set (Ref and each Fn::GetAtt). Moving AWS::ApiGatewayV2::Api into the registry subjects it to the schema-coverage gate, which surfaced the readOnly ExecuteApiArn attribute the monolith never published; it is now set to arn:<partition>:execute-api:<region>:<account>:<apiId>, the prefix a Lambda permission builds its SourceArn from. The monolith's failed-update tracking now delegates to the registry owner through a new mergeFailedUpdateResourceTracking hook, so the provisioner carries its body-materialized route, integration, and authorizer tracking forward itself.
This commit is contained in:
1 parent
e1ae6b3b1f
commit
dd60fefc4b
6 files changed
+948
-808
No files matched your search
+23
-9
@@ -8,10 +8,13 @@ import io.github.hectorvent.floci.services.apigatewayv2.model.Api;
|
||||
import io.github.hectorvent.floci.services.apigatewayv2.model.Authorizer;
|
||||
import io.github.hectorvent.floci.services.apigatewayv2.model.Route;
|
||||
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.ApiGatewayV2CfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.CloudFormationResourceRegistry;
|
||||
import io.github.hectorvent.floci.services.s3.S3Service;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
@@ -42,7 +45,7 @@ class ApiGatewayV2CfnProvisionerTest {
|
||||
provisioner = CfnProvisionerFixture.builder()
|
||||
.apiGatewayV2(apiGatewayV2Service)
|
||||
.objectMapper(mapper)
|
||||
.registry(new CloudFormationResourceRegistry(java.util.List.of()))
|
||||
.provisioners(new ApiGatewayV2CfnProvisioner(apiGatewayV2Service, mock(S3Service.class), mapper))
|
||||
.build();
|
||||
|
||||
Api api = new Api();
|
||||
@@ -52,6 +55,17 @@ class ApiGatewayV2CfnProvisionerTest {
|
||||
when(apiGatewayV2Service.updateApi(eq(REGION), eq(API_ID), anyMap())).thenReturn(api);
|
||||
}
|
||||
|
||||
@Test
|
||||
void publishesApiIdEndpointAndExecuteApiArn() throws Exception {
|
||||
StackResource api = provision(propertiesWithoutBody(), null, Map.of());
|
||||
|
||||
assertEquals("CREATE_COMPLETE", api.getStatus());
|
||||
assertEquals(API_ID, api.getAttributes().get("ApiId"));
|
||||
assertEquals("https://" + API_ID + ".execute-api.localhost", api.getAttributes().get("ApiEndpoint"));
|
||||
assertEquals("arn:aws:execute-api:us-east-1:000000000000:api-123",
|
||||
api.getAttributes().get("ExecuteApiArn"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void restoresExistingRoutesAndCleansPartialReplacementWhenRouteCreationFails() throws Exception {
|
||||
Route oldRoute = route("old-route", "GET /before");
|
||||
@@ -80,7 +94,7 @@ class ApiGatewayV2CfnProvisionerTest {
|
||||
assertEquals("old-route", replacement.getAttributes().get("__FlociApiGatewayV2BodyRouteIds"));
|
||||
verify(apiGatewayV2Service).deleteRoute(REGION, API_ID, "old-route");
|
||||
verify(apiGatewayV2Service).deleteRoute(REGION, API_ID, "partial-route");
|
||||
verify(apiGatewayV2Service).restoreRoute(REGION, API_ID, oldRoute, java.util.List.of());
|
||||
verify(apiGatewayV2Service).restoreRoute(REGION, API_ID, oldRoute, List.of());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,7 +154,7 @@ class ApiGatewayV2CfnProvisionerTest {
|
||||
assertEquals("old-route,replacement-route",
|
||||
replacement.getAttributes().get("__FlociApiGatewayV2BodyRouteIds"));
|
||||
verify(apiGatewayV2Service).restoreRoute(REGION, API_ID, oldRoute,
|
||||
java.util.List.of("replacement-route"));
|
||||
List.of("replacement-route"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -236,7 +250,7 @@ class ApiGatewayV2CfnProvisionerTest {
|
||||
"GET /protected".equals(request.get("routeKey"))
|
||||
&& "JWT".equals(request.get("authorizationType"))
|
||||
&& "body-authorizer".equals(request.get("authorizerId"))
|
||||
&& java.util.List.of("orders/read").equals(request.get("authorizationScopes"))));
|
||||
&& List.of("orders/read").equals(request.get("authorizationScopes"))));
|
||||
verify(apiGatewayV2Service).createRoute(eq(REGION), eq(API_ID), argThat(request ->
|
||||
"GET /public".equals(request.get("routeKey"))
|
||||
&& "NONE".equals(request.get("authorizationType"))
|
||||
@@ -403,7 +417,7 @@ class ApiGatewayV2CfnProvisionerTest {
|
||||
verify(apiGatewayV2Service).deleteAuthorizer(REGION, API_ID, "old-authorizer");
|
||||
verify(apiGatewayV2Service).deleteAuthorizer(REGION, API_ID, "replacement-authorizer");
|
||||
verify(apiGatewayV2Service).restoreAuthorizer(REGION, API_ID, oldAuthorizer);
|
||||
verify(apiGatewayV2Service).restoreRoute(REGION, API_ID, oldRoute, java.util.List.of());
|
||||
verify(apiGatewayV2Service).restoreRoute(REGION, API_ID, oldRoute, List.of());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -460,8 +474,8 @@ class ApiGatewayV2CfnProvisionerTest {
|
||||
assertEquals("old-one,old-two", replacement.getAttributes().get("__FlociApiGatewayV2BodyRouteIds"));
|
||||
verify(apiGatewayV2Service, never()).createRoute(eq(REGION), eq(API_ID),
|
||||
argThat(request -> "GET /after".equals(request.get("routeKey"))));
|
||||
verify(apiGatewayV2Service).restoreRoute(REGION, API_ID, oldOne, java.util.List.of());
|
||||
verify(apiGatewayV2Service).restoreRoute(REGION, API_ID, oldTwo, java.util.List.of());
|
||||
verify(apiGatewayV2Service).restoreRoute(REGION, API_ID, oldOne, List.of());
|
||||
verify(apiGatewayV2Service).restoreRoute(REGION, API_ID, oldTwo, List.of());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -496,8 +510,8 @@ class ApiGatewayV2CfnProvisionerTest {
|
||||
assertEquals("CREATE_COMPLETE", original.getStatus());
|
||||
assertEquals("CREATE_FAILED", removal.getStatus());
|
||||
assertEquals("old-one,old-two", removal.getAttributes().get("__FlociApiGatewayV2BodyRouteIds"));
|
||||
verify(apiGatewayV2Service).restoreRoute(REGION, API_ID, oldOne, java.util.List.of());
|
||||
verify(apiGatewayV2Service).restoreRoute(REGION, API_ID, oldTwo, java.util.List.of());
|
||||
verify(apiGatewayV2Service).restoreRoute(REGION, API_ID, oldOne, List.of());
|
||||
verify(apiGatewayV2Service).restoreRoute(REGION, API_ID, oldTwo, List.of());
|
||||
}
|
||||
|
||||
private StackResource provision(JsonNode properties, String existingPhysicalId,
|
||||
|
||||
+4
-1
@@ -34,6 +34,7 @@ import io.github.hectorvent.floci.services.cloudformation.provisioners.ApiGatewa
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.ApiGatewayDomainCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.ApiGatewayGatewayResponseCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.ApiGatewayRestApiCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.ApiGatewayV2CfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.AutoScalingGroupCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.AutoScalingLifecycleHookCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.AutoScalingScalingPolicyCfnProvisioner;
|
||||
@@ -320,6 +321,9 @@ final class CfnProvisionerFixture {
|
||||
discovered.add(new ApiGatewayGatewayResponseCfnProvisioner(apiGatewayService));
|
||||
discovered.add(new ApiGatewayRestApiCfnProvisioner(apiGatewayService, s3Service, objectMapper));
|
||||
}
|
||||
if (apiGatewayV2Service != null) {
|
||||
discovered.add(new ApiGatewayV2CfnProvisioner(apiGatewayV2Service, s3Service, objectMapper));
|
||||
}
|
||||
if (autoScalingService != null) {
|
||||
discovered.add(new AutoScalingGroupCfnProvisioner(autoScalingService));
|
||||
discovered.add(new AutoScalingLifecycleHookCfnProvisioner(autoScalingService));
|
||||
@@ -700,7 +704,6 @@ final class CfnProvisionerFixture {
|
||||
s3Service,
|
||||
lambdaService,
|
||||
iamService,
|
||||
apiGatewayV2Service,
|
||||
lambdaLayerService,
|
||||
objectMapper,
|
||||
customResourceResponseStore,
|
||||
|
||||
Reference in new issue
Block a user