diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b980cfc..239a1ac9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [7.3.1] - 2023-12-01 + +### Fixed +- Fixed hosted zone filtering. + ## [7.3.0] - 2023-11-30 ### Fixed diff --git a/package.json b/package.json index ba6726ee..557e01c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-domain-manager", - "version": "7.3.0", + "version": "7.3.1", "engines": { "node": ">=14" }, diff --git a/src/aws/acm-wrapper.ts b/src/aws/acm-wrapper.ts index c7b8400e..eddb860a 100644 --- a/src/aws/acm-wrapper.ts +++ b/src/aws/acm-wrapper.ts @@ -9,6 +9,7 @@ import { import Globals from "../globals"; import DomainConfig = require("../models/domain-config"); import {getAWSPagedResults} from "../utils"; +import Logging from "../logging"; const certStatuses = [ CertificateStatus.PENDING_VALIDATION, @@ -47,8 +48,9 @@ class ACMWrapper { certificateArn = this.getCertArnByCertName(certificates, certificateName); } else { certificateName = domain.givenDomainName; - certificateArn = this.getCertArnByDomainName(certificates, certificateName); + certificateArn = ACMWrapper.getCertArnByDomainName(certificates, certificateName); } + Logging.logInfo(`Found a certificate ARN: '${certificateArn}'`); } catch (err) { throw Error(`Could not search certificates in Certificate Manager.\n${err.message}`); } @@ -66,7 +68,7 @@ class ACMWrapper { return null; } - private getCertArnByDomainName(certificates, domainName): string { + private static getCertArnByDomainName(certificates, domainName): string { // The more specific name will be the longest let nameLength = 0; let certificateArn; diff --git a/src/aws/route53-wrapper.ts b/src/aws/route53-wrapper.ts index 944fd185..f93f8173 100644 --- a/src/aws/route53-wrapper.ts +++ b/src/aws/route53-wrapper.ts @@ -56,17 +56,20 @@ class Route53Wrapper { "NextMarker", new ListHostedZonesCommand({}) ); + Logging.logInfo(`Founded hosted zones list: ${hostedZones.map(zone => zone.Name)}.`); } catch (err) { throw new Error(`Unable to list hosted zones in Route53.\n${err.message}`); } + // removing the first part of the domain name, api.test.com => test.com + const domainNameHost = domain.givenDomainName.substring(domain.givenDomainName.indexOf(".") + 1); const targetHostedZone = hostedZones .filter((hostedZone) => { return !isPrivateDefined || isHostedZonePrivate === hostedZone.Config.PrivateZone; }) .filter((hostedZone) => { const hostedZoneName = hostedZone.Name.replace(/\.$/, ""); - return domain.givenDomainName.endsWith(hostedZoneName); + return domainNameHost.endsWith(hostedZoneName); }) .sort((zone1, zone2) => zone2.Name.length - zone1.Name.length) .shift(); diff --git a/src/index.ts b/src/index.ts index b9784ac5..9b830036 100644 --- a/src/index.ts +++ b/src/index.ts @@ -261,8 +261,6 @@ class ServerlessCustomDomain { await this.s3Wrapper.assertTlsCertObjectExists(domain); } if (!domain.certificateArn) { - const searchName = domain.certificateName || domain.givenDomainName; - Logging.logInfo(`Searching for a certificate with the '${searchName}' domain`); domain.certificateArn = await acm.getCertArn(domain); } domain.domainInfo = await apiGateway.createCustomDomain(domain); diff --git a/test/integration-tests/debug/pr-example/serverless.yml b/test/integration-tests/debug/pr-example/serverless.yml index e61a5a1d..0ee2f9ff 100644 --- a/test/integration-tests/debug/pr-example/serverless.yml +++ b/test/integration-tests/debug/pr-example/serverless.yml @@ -22,8 +22,8 @@ custom: autoDomain: true basePath: "" domainName: ${env:PLUGIN_IDENTIFIER}-http-${env:RANDOM_STRING}.${env:TEST_DOMAIN} - stage: "dev" createRoute53Record: true + endpointType: REGIONAL package: patterns: diff --git a/test/unit-tests/aws/route53-wrapper.test.ts b/test/unit-tests/aws/route53-wrapper.test.ts index 2b238445..0f9f3c4c 100644 --- a/test/unit-tests/aws/route53-wrapper.test.ts +++ b/test/unit-tests/aws/route53-wrapper.test.ts @@ -165,19 +165,24 @@ describe("Route53 wrapper checks", () => { { CallerReference: "", Config: {PrivateZone: false}, - Id: testId, - Name: "test_domain", + Id: "no_valid", + Name: "api.test_domain", }, { CallerReference: "", Config: {PrivateZone: true}, Id: "dummy_host_id", Name: "test_domain", - } + }, { + CallerReference: "", + Config: {PrivateZone: false}, + Id: testId, + Name: "test_domain", + }, ] }); const dc = new DomainConfig(getDomainConfig({ - domainName: "test_domain" + domainName: "devapi.test_domain" })); const actualId = await new Route53Wrapper().getRoute53HostedZoneId(dc, false);