mirror of
https://github.com/floci-io/floci.git
synced 2026-12-06 03:28:18 -05:00
fix(cloudformation): keep AWS::ApiGateway::RestApi on stack updates (#4512)
* fix(cloudformation): keep AWS::ApiGateway::RestApi on stack updates UpdateStack runs provision again for every resource, and the RestApi arm called CreateRestApi unconditionally. Each update minted a new API, pointed the stack at it and left the previous one behind, so the API id and invoke URL changed on every deploy. No RestApi property requires replacement, so an update now keeps the API from the previous provision and patches it in place: - Name and Description go through UpdateRestApi, and a template without Name keeps the name the API has. - A changed EndpointConfiguration is applied through the UpdateRestApi paths AWS documents for it, replace /endpointConfiguration/types/<type> and add or remove /endpointConfiguration/vpcEndpointIds, which UpdateRestApi now accepts under the rules CreateRestApi applies. - A Body or BodyS3Location is resolved before anything changes and is still applied with PutRestApi in overwrite mode. - RootResourceId comes from the API's root rather than the first resource listed, which is the root only on a freshly created API. - An API removed out of band is created again, as a replacement that a rollback deletes. The name, description and endpoint configuration are snapshotted before the patch, so a later resource that fails the update puts them back, and so does a Body that PutRestApi rejects. An update that re-applied a Body still reports that rollback is not implemented: PutRestApi replaced the API's resources, methods and models, which the snapshot does not hold. The Resources and Methods on the kept API rely on the update and delete handling from #4511. * fix(apigateway): accept the index form of the endpoint type patch path UpdateRestApi took replace /endpointConfiguration/types/<type> only when the path named the API's current type, as the API Gateway guide writes it. Terraform sends /endpointConfiguration/types/0 instead, which AWS accepts too, and Floci answered it with a 400. An API has exactly one endpoint type, so index 0 is accepted as well.
This commit is contained in:
1 parent
76adb9a97e
commit
a66e2a131d
6 files changed
+651
-54
No files matched your search
+76
@@ -1,9 +1,12 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
@@ -37,4 +40,77 @@ public class ApiGatewayUpdateRestApiIntegrationTest {
|
||||
.statusCode(200)
|
||||
.body("description", equalTo("updated description"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateRestApiChangesTheEndpointType() {
|
||||
String id = createApi("rest-api-endpoint-type");
|
||||
|
||||
patch(id, """
|
||||
[{"op":"replace","path":"/endpointConfiguration/types/REGIONAL","value":"EDGE"}]""")
|
||||
.statusCode(200)
|
||||
.body("endpointConfiguration.types", contains("EDGE"));
|
||||
|
||||
// The path names the type the API has now, and a rejected patch changes nothing.
|
||||
patch(id, """
|
||||
[{"op":"replace","path":"/endpointConfiguration/types/REGIONAL","value":"PRIVATE"}]""")
|
||||
.statusCode(400);
|
||||
given().get("/restapis/" + id).then().statusCode(200)
|
||||
.body("endpointConfiguration.types", contains("EDGE"));
|
||||
|
||||
// Terraform names the type by its index instead; an API has only the one at 0.
|
||||
patch(id, """
|
||||
[{"op":"replace","path":"/endpointConfiguration/types/0","value":"REGIONAL"}]""")
|
||||
.statusCode(200)
|
||||
.body("endpointConfiguration.types", contains("REGIONAL"));
|
||||
patch(id, """
|
||||
[{"op":"replace","path":"/endpointConfiguration/types/1","value":"EDGE"}]""")
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateRestApiAssociatesAndDisassociatesVpcEndpoints() {
|
||||
String id = createApi("rest-api-vpc-endpoints");
|
||||
|
||||
// A PRIVATE API needs a VPC endpoint, so the patch that makes it one associates one too.
|
||||
patch(id, """
|
||||
[{"op":"replace","path":"/endpointConfiguration/types/REGIONAL","value":"PRIVATE"},
|
||||
{"op":"add","path":"/endpointConfiguration/vpcEndpointIds","value":"vpce-1"},
|
||||
{"op":"add","path":"/endpointConfiguration/vpcEndpointIds","value":"vpce-2"}]""")
|
||||
.statusCode(200)
|
||||
.body("endpointConfiguration.types", contains("PRIVATE"))
|
||||
.body("endpointConfiguration.vpcEndpointIds", contains("vpce-1", "vpce-2"));
|
||||
|
||||
patch(id, """
|
||||
[{"op":"remove","path":"/endpointConfiguration/vpcEndpointIds","value":"vpce-1"}]""")
|
||||
.statusCode(200)
|
||||
.body("endpointConfiguration.vpcEndpointIds", contains("vpce-2"));
|
||||
patch(id, """
|
||||
[{"op":"remove","path":"/endpointConfiguration/vpcEndpointIds","value":"vpce-2"}]""")
|
||||
.statusCode(400);
|
||||
|
||||
patch(id, """
|
||||
[{"op":"replace","path":"/endpointConfiguration/types/PRIVATE","value":"REGIONAL"}]""")
|
||||
.statusCode(200)
|
||||
.body("endpointConfiguration.types", contains("REGIONAL"))
|
||||
.body("endpointConfiguration.vpcEndpointIds", empty());
|
||||
}
|
||||
|
||||
private static String createApi(String name) {
|
||||
return given()
|
||||
.contentType("application/json")
|
||||
.body("{\"name\":\"" + name + "\"}")
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
}
|
||||
|
||||
private static ValidatableResponse patch(String id, String operations) {
|
||||
return given()
|
||||
.contentType("application/json")
|
||||
.body("{\"patchOperations\":" + operations + "}")
|
||||
.patch("/restapis/" + id)
|
||||
.then();
|
||||
}
|
||||
}
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.XmlParser;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* UpdateStack keeps an AWS::ApiGateway::RestApi and the AWS::ApiGateway::Resource under it, in the
|
||||
* redeploy shape the Serverless Framework produces: only the Deployment's logical id changes. The
|
||||
* API's description and endpoint type change in place, a resource the template drops goes from the
|
||||
* kept API, and an update that fails puts the API back as it was.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ApiGatewayRestApiCfnUpdateIntegrationTest {
|
||||
|
||||
private static final String API_NAME = "cfn-restapi-update";
|
||||
/** The API's description and endpoint type, and the suffix of the Deployment's logical id. */
|
||||
private static final String TEMPLATE = """
|
||||
{
|
||||
"Resources": {
|
||||
"Api": {"Type":"AWS::ApiGateway::RestApi", "Properties":{"Name":"cfn-restapi-update",
|
||||
"Description":"%s", "EndpointConfiguration":{"Types":["%s"]}}},
|
||||
"Items": {"Type":"AWS::ApiGateway::Resource", "Properties":{
|
||||
"RestApiId":{"Ref":"Api"},
|
||||
"ParentId":{"Fn::GetAtt":["Api","RootResourceId"]},
|
||||
"PathPart":"items"}},
|
||||
"Options": {"Type":"AWS::ApiGateway::Method", "Properties":{
|
||||
"RestApiId":{"Ref":"Api"}, "ResourceId":{"Ref":"Items"},
|
||||
"HttpMethod":"OPTIONS", "AuthorizationType":"NONE",
|
||||
"Integration":{"Type":"MOCK"}}},
|
||||
"Deployment%s": {"Type":"AWS::ApiGateway::Deployment", "DependsOn":"Options",
|
||||
"Properties":{"RestApiId":{"Ref":"Api"}, "StageName":"local"}}
|
||||
},
|
||||
"Outputs":{"ApiId":{"Value":{"Ref":"Api"}},
|
||||
"ResourceId":{"Value":{"Ref":"Items"}}}
|
||||
}
|
||||
""";
|
||||
private static final String API_ONLY_TEMPLATE = """
|
||||
{
|
||||
"Resources": {
|
||||
"Api": {"Type":"AWS::ApiGateway::RestApi", "Properties":{"Name":"cfn-restapi-update",
|
||||
"Description":"second", "EndpointConfiguration":{"Types":["EDGE"]}}}
|
||||
},
|
||||
"Outputs":{"ApiId":{"Value":{"Ref":"Api"}}}
|
||||
}
|
||||
""";
|
||||
/**
|
||||
* The API's description and endpoint type, then any extra resources. No Method or Deployment:
|
||||
* their in-place updates have no rollback yet, so a failed update could not roll back cleanly.
|
||||
*/
|
||||
private static final String ROLLBACK_TEMPLATE = """
|
||||
{
|
||||
"Resources": {
|
||||
"Api": {"Type":"AWS::ApiGateway::RestApi", "Properties":{"Name":"cfn-restapi-rollback",
|
||||
"Description":"%s", "EndpointConfiguration":{"Types":["%s"]}}},
|
||||
"Items": {"Type":"AWS::ApiGateway::Resource", "Properties":{
|
||||
"RestApiId":{"Ref":"Api"},
|
||||
"ParentId":{"Fn::GetAtt":["Api","RootResourceId"]},
|
||||
"PathPart":"items"}}%s
|
||||
},
|
||||
"Outputs":{"ApiId":{"Value":{"Ref":"Api"}}}
|
||||
}
|
||||
""";
|
||||
/** Fails after the API has been patched: its parent does not exist. */
|
||||
private static final String FAILING_RESOURCE = """
|
||||
,
|
||||
"Broken": {"Type":"AWS::ApiGateway::Resource", "DependsOn":"Items", "Properties":{
|
||||
"RestApiId":{"Ref":"Api"}, "ParentId":"missing0", "PathPart":"broken"}}""";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateKeepsTheRestApiAndRemovesTheResourcesItDrops() {
|
||||
String stack = "apigw-cfn-restapi-update-it";
|
||||
try {
|
||||
stackAction(stack, "CreateStack", TEMPLATE.formatted("first", "REGIONAL", "1"));
|
||||
Map<String, String> created = outputsOnceStatusIs(stack, "CREATE_COMPLETE");
|
||||
|
||||
stackAction(stack, "UpdateStack", TEMPLATE.formatted("second", "EDGE", "2"));
|
||||
Map<String, String> updated = outputsOnceStatusIs(stack, "UPDATE_COMPLETE");
|
||||
|
||||
String apiId = created.get("ApiId");
|
||||
assertEquals(apiId, updated.get("ApiId"));
|
||||
assertEquals(created.get("ResourceId"), updated.get("ResourceId"));
|
||||
given().when().get("/restapis").then().statusCode(200)
|
||||
.body("item.findAll { it.name == '" + API_NAME + "' }.size()", equalTo(1));
|
||||
given().when().get("/restapis/" + apiId).then().statusCode(200)
|
||||
.body("description", equalTo("second"))
|
||||
.body("endpointConfiguration.types", contains("EDGE"));
|
||||
assertPaths(apiId, "/", "/items");
|
||||
|
||||
stackAction(stack, "UpdateStack", API_ONLY_TEMPLATE);
|
||||
assertEquals(apiId, outputsOnceStatusIs(stack, "UPDATE_COMPLETE").get("ApiId"));
|
||||
assertPaths(apiId, "/");
|
||||
} finally {
|
||||
deleteStack(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void failedUpdatePutsTheRestApiBack() {
|
||||
String stack = "apigw-cfn-restapi-rollback-it";
|
||||
try {
|
||||
stackAction(stack, "CreateStack", ROLLBACK_TEMPLATE.formatted("first", "REGIONAL", ""));
|
||||
String apiId = outputsOnceStatusIs(stack, "CREATE_COMPLETE").get("ApiId");
|
||||
|
||||
stackAction(stack, "UpdateStack", ROLLBACK_TEMPLATE.formatted("second", "EDGE", FAILING_RESOURCE));
|
||||
assertEquals(apiId, outputsOnceStatusIs(stack, "UPDATE_ROLLBACK_COMPLETE").get("ApiId"));
|
||||
|
||||
given().when().get("/restapis/" + apiId).then().statusCode(200)
|
||||
.body("description", equalTo("first"))
|
||||
.body("endpointConfiguration.types", contains("REGIONAL"));
|
||||
assertPaths(apiId, "/", "/items");
|
||||
} finally {
|
||||
deleteStack(stack);
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertPaths(String apiId, String... paths) {
|
||||
given().when().get("/restapis/" + apiId + "/resources").then().statusCode(200)
|
||||
.body("item.path", containsInAnyOrder(paths));
|
||||
}
|
||||
|
||||
private static void stackAction(String stack, String action, String template) {
|
||||
given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", action)
|
||||
.formParam("StackName", stack)
|
||||
.formParam("TemplateBody", template)
|
||||
.when().post("/").then().statusCode(200);
|
||||
}
|
||||
|
||||
private static Map<String, String> outputsOnceStatusIs(String stack, String status) {
|
||||
CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(stack);
|
||||
assertEquals(status, state.status(), state.reason());
|
||||
String xml = given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", stack)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().asString();
|
||||
return XmlParser.extractPairs(xml, "Outputs", "OutputKey", "OutputValue");
|
||||
}
|
||||
|
||||
private static void deleteStack(String stack) {
|
||||
given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DeleteStack")
|
||||
.formParam("StackName", stack)
|
||||
.when().post("/").then().statusCode(200);
|
||||
CfnStackWaits.awaitStackDeleted(stack);
|
||||
}
|
||||
}
|
||||
+138
-3
@@ -7,15 +7,19 @@ import io.github.hectorvent.floci.services.apigateway.ApiGatewayService;
|
||||
import io.github.hectorvent.floci.services.apigateway.model.ApiGatewayResource;
|
||||
import io.github.hectorvent.floci.services.apigateway.model.Authorizer;
|
||||
import io.github.hectorvent.floci.services.apigateway.model.Deployment;
|
||||
import io.github.hectorvent.floci.services.apigateway.model.EndpointConfiguration;
|
||||
import io.github.hectorvent.floci.services.apigateway.model.EndpointType;
|
||||
import io.github.hectorvent.floci.services.apigateway.model.RestApi;
|
||||
import io.github.hectorvent.floci.services.cloudformation.CloudFormationTemplateEngine;
|
||||
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
|
||||
import io.github.hectorvent.floci.services.s3.S3Service;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
@@ -51,9 +55,7 @@ class ApiGatewayRestApiCfnProvisionerTest {
|
||||
RestApi created = new RestApi();
|
||||
created.setId("api-1");
|
||||
when(api.createRestApi(eq("us-east-1"), anyMap())).thenReturn(created);
|
||||
ApiGatewayResource root = new ApiGatewayResource();
|
||||
root.setId("root-1");
|
||||
when(api.getResources("us-east-1", "api-1")).thenReturn(List.of(root));
|
||||
when(api.findRootResourceId("us-east-1", "api-1")).thenReturn(Optional.of("root-1"));
|
||||
|
||||
StackResource r = resource("AWS::ApiGateway::RestApi", "Api");
|
||||
provisioner.provision(r, props("{\"Name\": \"shop\"}"), ctx());
|
||||
@@ -65,6 +67,105 @@ class ApiGatewayRestApiCfnProvisionerTest {
|
||||
verify(api, never()).putRestApi(anyString(), anyString(), anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void restApiUpdateKeepsTheApiAndPatchesItInPlace() throws Exception {
|
||||
existingApi(restApi("api-1", "shop", "v1", "REGIONAL"));
|
||||
|
||||
StackResource r = resource("AWS::ApiGateway::RestApi", "Api");
|
||||
provisioner.provision(r, props("{\"Description\": \"v2\"}"), ctx("api-1"));
|
||||
|
||||
assertEquals("api-1", r.getPhysicalId());
|
||||
assertEquals("root-1", r.getAttributes().get("RootResourceId"));
|
||||
verify(api, never()).createRestApi(anyString(), anyMap());
|
||||
// An undeclared Name keeps the API's own rather than a newly generated one, and an
|
||||
// undeclared EndpointConfiguration is left alone.
|
||||
verify(api).updateRestApi("us-east-1", "api-1", List.of(
|
||||
op("replace", "/name", "shop"), op("replace", "/description", "v2")));
|
||||
assertFalse(provisioner.hasReplacementUpdate(r));
|
||||
}
|
||||
|
||||
@Test
|
||||
void restApiUpdateAppliesAChangedEndpointConfiguration() throws Exception {
|
||||
existingApi(restApi("api-1", "shop", null, "REGIONAL"));
|
||||
|
||||
provisioner.provision(resource("AWS::ApiGateway::RestApi", "Api"), props("""
|
||||
{"Name": "shop", "EndpointConfiguration": {"Types": ["PRIVATE"], "VpcEndpointIds": ["vpce-1"]}}
|
||||
"""), ctx("api-1"));
|
||||
|
||||
// The type's path names the type the API has now.
|
||||
verify(api).updateRestApi("us-east-1", "api-1", List.of(
|
||||
op("replace", "/name", "shop"), op("replace", "/description", null),
|
||||
op("replace", "/endpointConfiguration/types/REGIONAL", "PRIVATE"),
|
||||
op("add", "/endpointConfiguration/vpcEndpointIds", "vpce-1")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void restApiRollbackPutsBackWhatTheUpdatePatched() throws Exception {
|
||||
existingApi(restApi("api-1", "shop", "v1", "REGIONAL"));
|
||||
StackResource r = resource("AWS::ApiGateway::RestApi", "Api");
|
||||
provisioner.provision(r, props("""
|
||||
{"Name": "shop", "Description": "v2",
|
||||
"EndpointConfiguration": {"Types": ["PRIVATE"], "VpcEndpointIds": ["vpce-1"]}}
|
||||
"""), ctx("api-1"));
|
||||
when(api.getRestApi("us-east-1", "api-1")).thenReturn(restApi("api-1", "shop", "v2", "PRIVATE", "vpce-1"));
|
||||
|
||||
assertTrue(provisioner.rollbackUpdate(r));
|
||||
|
||||
verify(api).updateRestApi("us-east-1", "api-1", List.of(
|
||||
op("replace", "/name", "shop"), op("replace", "/description", "v1"),
|
||||
op("replace", "/endpointConfiguration/types/PRIVATE", "REGIONAL"),
|
||||
op("remove", "/endpointConfiguration/vpcEndpointIds", "vpce-1")));
|
||||
assertFalse(r.getAttributes().containsKey(CfnRollback.REST_API_UPDATE_SNAPSHOT_ATTR));
|
||||
}
|
||||
|
||||
@Test
|
||||
void restApiRollbackOfAnUpdateThatAppliedABodyIsNotImplemented() throws Exception {
|
||||
existingApi(restApi("api-1", "shop", "v1", "REGIONAL"));
|
||||
StackResource r = resource("AWS::ApiGateway::RestApi", "Api");
|
||||
provisioner.provision(r, props("""
|
||||
{"Name": "shop", "Body": {"openapi": "3.0.1", "info": {"title": "shop"}, "paths": {}}}
|
||||
"""), ctx("api-1"));
|
||||
verify(api).putRestApi(eq("us-east-1"), eq("api-1"), eq("overwrite"), anyString());
|
||||
|
||||
// PutRestApi replaced the API's resources, methods and models, which the snapshot does not hold.
|
||||
assertFalse(provisioner.rollbackUpdate(r));
|
||||
}
|
||||
|
||||
@Test
|
||||
void restApiUpdateWhoseBodyIsRejectedPutsThePatchBack() throws Exception {
|
||||
existingApi(restApi("api-1", "shop", "v1", "REGIONAL"));
|
||||
when(api.putRestApi(eq("us-east-1"), eq("api-1"), eq("overwrite"), anyString()))
|
||||
.thenThrow(new AwsException("BadRequestException", "Invalid OpenAPI input", 400));
|
||||
StackResource r = resource("AWS::ApiGateway::RestApi", "Api");
|
||||
|
||||
assertThrows(AwsException.class, () -> provisioner.provision(r, props("""
|
||||
{"Name": "shop", "Description": "v2", "Body": {"openapi": "3.0.1", "paths": {}}}
|
||||
"""), ctx("api-1")));
|
||||
|
||||
verify(api).updateRestApi("us-east-1", "api-1", List.of(
|
||||
op("replace", "/name", "shop"), op("replace", "/description", "v2")));
|
||||
verify(api).updateRestApi("us-east-1", "api-1", List.of(
|
||||
op("replace", "/name", "shop"), op("replace", "/description", "v1")));
|
||||
assertFalse(r.getAttributes().containsKey(CfnRollback.UPDATE_ROLLBACK_FAILURE_ATTR));
|
||||
}
|
||||
|
||||
@Test
|
||||
void restApiUpdateRecreatesAnApiRemovedOutOfBandAndItsRollbackDeletesIt() throws Exception {
|
||||
when(api.getRestApi("us-east-1", "api-1"))
|
||||
.thenThrow(new AwsException("NotFoundException", "Invalid API id specified", 404));
|
||||
when(api.createRestApi(eq("us-east-1"), anyMap())).thenReturn(restApi("api-2", "shop", null, "REGIONAL"));
|
||||
when(api.findRootResourceId("us-east-1", "api-2")).thenReturn(Optional.of("root-2"));
|
||||
StackResource r = resource("AWS::ApiGateway::RestApi", "Api");
|
||||
|
||||
provisioner.provision(r, props("{\"Name\": \"shop\"}"), ctx("api-1"));
|
||||
assertEquals("api-2", r.getPhysicalId());
|
||||
assertEquals("root-2", r.getAttributes().get("RootResourceId"));
|
||||
|
||||
assertTrue(provisioner.rollbackUpdate(r));
|
||||
assertEquals("api-1", r.getPhysicalId());
|
||||
verify(api).deleteRestApi("us-east-1", "api-2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourcePublishesResourceId() throws Exception {
|
||||
ApiGatewayResource res = new ApiGatewayResource();
|
||||
@@ -344,9 +445,43 @@ class ApiGatewayRestApiCfnProvisionerTest {
|
||||
return node == null ? null : node.asText();
|
||||
});
|
||||
when(engine.resolveNode(any())).thenAnswer(inv -> inv.getArgument(0));
|
||||
when(engine.resolveStringList(any())).thenAnswer(inv -> {
|
||||
List<String> values = new ArrayList<>();
|
||||
((JsonNode) inv.getArgument(0)).forEach(value -> values.add(value.asText()));
|
||||
return values;
|
||||
});
|
||||
return new ProvisionContext(engine, "us-east-1", "000000000000", "my-stack", priorPhysicalId);
|
||||
}
|
||||
|
||||
/** Stubs what an in-place update of {@code existing} looks up and patches. */
|
||||
private void existingApi(RestApi existing) {
|
||||
when(api.getRestApi("us-east-1", existing.getId())).thenReturn(existing);
|
||||
when(api.updateRestApi(eq("us-east-1"), eq(existing.getId()), any())).thenReturn(existing);
|
||||
when(api.findRootResourceId("us-east-1", existing.getId())).thenReturn(Optional.of("root-1"));
|
||||
}
|
||||
|
||||
private static RestApi restApi(String id, String name, String description, String endpointType,
|
||||
String... vpcEndpointIds) {
|
||||
RestApi restApi = new RestApi();
|
||||
restApi.setId(id);
|
||||
restApi.setName(name);
|
||||
restApi.setDescription(description);
|
||||
EndpointConfiguration endpoint = new EndpointConfiguration();
|
||||
endpoint.setTypes(List.of(EndpointType.valueOf(endpointType)));
|
||||
endpoint.setVpcEndpointIds(List.of(vpcEndpointIds));
|
||||
restApi.setEndpointConfiguration(endpoint);
|
||||
return restApi;
|
||||
}
|
||||
|
||||
/** A patch operation as the provisioner builds one; unlike {@code Map.of}, it takes a null value. */
|
||||
private static Map<String, String> op(String op, String path, String value) {
|
||||
Map<String, String> operation = new HashMap<>();
|
||||
operation.put("op", op);
|
||||
operation.put("path", path);
|
||||
operation.put("value", value);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/** A Resource created as res-1 at /orders, then replaced by res-2 at /items. */
|
||||
private StackResource replacedResource() throws Exception {
|
||||
when(api.createResource(eq("us-east-1"), eq("api-1"), eq("root-1"), anyMap()))
|
||||
|
||||
Reference in new issue
Block a user