mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(apigateway): leave the regional fields off edge-optimized domains (#9605)
An edge-optimized custom domain reports only its CloudFront distribution: the AWS CLI's create-domain-name example 1 (an EDGE domain) returns distributionDomainName and distributionHostedZoneId and no regional field. Floci wrote regionalDomainName and regionalHostedZoneId, and any regional certificate, on every domain. They are now serialized for regional domains only; the stored regional name is kept, because the custom domain filter still routes on it. The two routing tests that address a domain through its .regional.local host now create a REGIONAL domain. The GetDomainNames assertion now finds the domain under item, and a new case creates an EDGE domain with a regional certificate name and ARN and checks that CreateDomainName, GetDomainName and GetDomainNames leave all four regional fields off. The custom-domain guide no longer says every domain reports a regionalDomainName and both certificate ARNs. Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
1 parent
b678d5446c
commit
c15207b7e0
5 files changed
+82
-17
No files matched your search
@@ -319,11 +319,13 @@ and [response contract](https://docs.aws.amazon.com/apigateway/latest/developerg
|
||||
`GetDomainNames` accepts the `resourceOwner` values `SELF` and `OTHER_ACCOUNTS`.
|
||||
Other supplied values, including an empty value, return `ValidationException`.
|
||||
|
||||
A domain created with `CreateDomainName` is `AVAILABLE` at once. Its `regionalDomainName` is
|
||||
`<domain>.regional.local`, and a request whose `Host` header is either that name or the domain
|
||||
itself is routed through the domain's base path mappings to the mapped REST API stage. An
|
||||
`EDGE` domain also reports a `distributionDomainName` under `cloudfront.net` and the fixed
|
||||
CloudFront hosted zone `Z2FDTNDATAQYW2`; a `REGIONAL` domain reports neither, as on AWS. The
|
||||
A domain created with `CreateDomainName` is `AVAILABLE` at once. A request whose `Host` header is
|
||||
the domain itself or `<domain>.regional.local` is routed through the domain's base path mappings
|
||||
to the mapped REST API stage. A `REGIONAL` domain reports that name as its `regionalDomainName`,
|
||||
with a `regionalHostedZoneId` and its regional certificate. An `EDGE` domain reports only its
|
||||
distribution, as on AWS: a `distributionDomainName` under `cloudfront.net` and the fixed
|
||||
CloudFront hosted zone `Z2FDTNDATAQYW2`, and no regional field even when it was given a regional
|
||||
certificate. A `REGIONAL` domain reports no distribution. The
|
||||
`regionalHostedZoneId` is the zone the [General Reference](https://docs.aws.amazon.com/general/latest/gr/apigateway.html)
|
||||
publishes for the domain's region, or the placeholder `Z2FDTNDATAQYL2`, which is no AWS zone, in a
|
||||
region the table does not list. The id is set at creation, so a stored domain keeps the one it
|
||||
@@ -332,8 +334,8 @@ domain between the two types with `UpdateDomainName` creates or drops the distri
|
||||
domain created with no endpoint type is `EDGE`, as on AWS; it is `REGIONAL` when the request
|
||||
carries a regional certificate (`regionalCertificateArn` or `regionalCertificateName`) or the
|
||||
partition has no edge-optimized endpoints.
|
||||
`GetDomainName` returns the `domainNameArn`, the `endpointConfiguration`, both certificate ARNs
|
||||
and the `tags`. Tags are managed through `TagResource`, `UntagResource` and `GetTags` on
|
||||
`GetDomainName` returns the `domainNameArn`, the `endpointConfiguration`, its `certificateArn`, the
|
||||
`regionalCertificateArn` of a `REGIONAL` domain, and the `tags`. Tags are managed through `TagResource`, `UntagResource` and `GetTags` on
|
||||
`arn:aws:apigateway:<region>::/domainnames/<domain>`. A second mapping on a base path that
|
||||
already has one is a `ConflictException`. A `PRIVATE` endpoint type is refused: private custom
|
||||
domains are not emulated. Mutual TLS, ownership verification certificates, routing modes and
|
||||
|
||||
@@ -2722,13 +2722,18 @@ public class ApiGatewayController {
|
||||
node.putObject("endpointConfiguration").putArray("types").add(d.getEndpointConfigurationType());
|
||||
if (d.getCertificateName() != null) node.put("certificateName", d.getCertificateName());
|
||||
if (d.getCertificateArn() != null) node.put("certificateArn", d.getCertificateArn());
|
||||
node.put("regionalDomainName", d.getRegionalDomainName());
|
||||
node.put("regionalHostedZoneId", d.getRegionalHostedZoneId());
|
||||
if (d.getRegionalCertificateName() != null) {
|
||||
node.put("regionalCertificateName", d.getRegionalCertificateName());
|
||||
}
|
||||
if (d.getRegionalCertificateArn() != null) {
|
||||
node.put("regionalCertificateArn", d.getRegionalCertificateArn());
|
||||
// An edge-optimized domain reports only its distribution (aws-cli
|
||||
// examples/apigateway/create-domain-name.rst, Example 1). The regional name stays stored,
|
||||
// since the custom domain filter still routes on it.
|
||||
if (!"EDGE".equals(d.getEndpointConfigurationType())) {
|
||||
node.put("regionalDomainName", d.getRegionalDomainName());
|
||||
node.put("regionalHostedZoneId", d.getRegionalHostedZoneId());
|
||||
if (d.getRegionalCertificateName() != null) {
|
||||
node.put("regionalCertificateName", d.getRegionalCertificateName());
|
||||
}
|
||||
if (d.getRegionalCertificateArn() != null) {
|
||||
node.put("regionalCertificateArn", d.getRegionalCertificateArn());
|
||||
}
|
||||
}
|
||||
if (d.getDistributionDomainName() != null) {
|
||||
node.put("distributionDomainName", d.getDistributionDomainName());
|
||||
|
||||
+2
-1
@@ -70,7 +70,8 @@ class ApiGatewayCustomDomainIamAuthIntegrationTest {
|
||||
|
||||
given().contentType(ContentType.JSON)
|
||||
.body("{\"domainName\":\"" + DOMAIN + "\","
|
||||
+ "\"certificateArn\":\"arn:aws:acm:us-east-1:123456789012:certificate/abc\"}")
|
||||
+ "\"regionalCertificateArn\":\"arn:aws:acm:us-east-1:123456789012:certificate/abc\","
|
||||
+ "\"endpointConfiguration\":{\"types\":[\"REGIONAL\"]}}")
|
||||
.when().post("/domainnames")
|
||||
.then().statusCode(201)
|
||||
.body("regionalDomainName", equalTo(DOMAIN + ".regional.local"));
|
||||
|
||||
+2
-1
@@ -105,7 +105,8 @@ class ApiGatewayCustomDomainIntegrationTest {
|
||||
void createCustomDomain() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"domainName\":\"api.example.com\",\"certificateArn\":\"arn:aws:acm:us-east-1:123456789012:certificate/abc\"}")
|
||||
.body("{\"domainName\":\"api.example.com\",\"regionalCertificateArn\":\"arn:aws:acm:us-east-1:123456789012:certificate/abc\","
|
||||
+ "\"endpointConfiguration\":{\"types\":[\"REGIONAL\"]}}")
|
||||
.when().post("/domainnames")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
|
||||
+57
-1
@@ -20,7 +20,10 @@ import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasKey;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@@ -75,7 +78,60 @@ class ApiGatewayDomainNameIntegrationTest {
|
||||
""".formatted(domain, CERTIFICATE_ARN))
|
||||
.body("endpointConfiguration.types[0]", equalTo("EDGE"))
|
||||
.body("distributionDomainName", endsWith(".cloudfront.net"))
|
||||
.body("distributionHostedZoneId", equalTo("Z2FDTNDATAQYW2"));
|
||||
.body("distributionHostedZoneId", equalTo("Z2FDTNDATAQYW2"))
|
||||
.body("$", not(hasKey("regionalDomainName")))
|
||||
.body("$", not(hasKey("regionalHostedZoneId")));
|
||||
|
||||
deleteDomain(domain);
|
||||
}
|
||||
|
||||
@Test
|
||||
void edgeDomainReportsNoRegionalFields() {
|
||||
// aws-cli examples/apigateway/create-domain-name.rst, Example 1: an edge-optimized domain
|
||||
// reports only the distribution name and zone, nothing regional.
|
||||
String domain = "edge-only.apigw-domain-it.example.com";
|
||||
createDomain("""
|
||||
{"domainName":"%s","certificateArn":"%s"}
|
||||
""".formatted(domain, CERTIFICATE_ARN))
|
||||
.body("endpointConfiguration.types[0]", equalTo("EDGE"))
|
||||
.body("$", not(hasKey("regionalDomainName")))
|
||||
.body("$", not(hasKey("regionalHostedZoneId")));
|
||||
|
||||
given().when().get("/domainnames/" + domain).then()
|
||||
.statusCode(200)
|
||||
.body("$", not(hasKey("regionalDomainName")))
|
||||
.body("$", not(hasKey("regionalHostedZoneId")));
|
||||
|
||||
given().when().get("/domainnames").then()
|
||||
.statusCode(200)
|
||||
.body("item.find { it.domainName == '" + domain + "' }", notNullValue())
|
||||
.body("item.find { it.domainName == '" + domain + "' }", not(hasKey("regionalDomainName")))
|
||||
.body("item.find { it.domainName == '" + domain + "' }", not(hasKey("regionalHostedZoneId")));
|
||||
|
||||
deleteDomain(domain);
|
||||
}
|
||||
|
||||
@Test
|
||||
void edgeDomainLeavesOffTheRegionalCertificateItWasGiven() {
|
||||
String domain = "edge-regional-cert.apigw-domain-it.example.com";
|
||||
String[] regionalKeys = {"regionalDomainName", "regionalHostedZoneId",
|
||||
"regionalCertificateName", "regionalCertificateArn"};
|
||||
ValidatableResponse created = createDomain("""
|
||||
{"domainName":"%s",
|
||||
"certificateArn":"%s",
|
||||
"regionalCertificateArn":"%s",
|
||||
"regionalCertificateName":"regional-cert",
|
||||
"endpointConfiguration":{"types":["EDGE"]}}
|
||||
""".formatted(domain, CERTIFICATE_ARN, CERTIFICATE_ARN))
|
||||
.body("endpointConfiguration.types[0]", equalTo("EDGE"));
|
||||
ValidatableResponse fetched = given().when().get("/domainnames/" + domain).then().statusCode(200);
|
||||
ValidatableResponse listed = given().when().get("/domainnames").then().statusCode(200)
|
||||
.body("item.find { it.domainName == '" + domain + "' }", notNullValue());
|
||||
for (String key : regionalKeys) {
|
||||
created.body("$", not(hasKey(key)));
|
||||
fetched.body("$", not(hasKey(key)));
|
||||
listed.body("item.find { it.domainName == '" + domain + "' }", not(hasKey(key)));
|
||||
}
|
||||
|
||||
deleteDomain(domain);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user