Skip to content

Commit

Permalink
Merge pull request #615 from amplify-education/bugfix/AT-11105-http-$…
Browse files Browse the repository at this point in the history
…default-stage

AT-11105: Hardcoded HTTP api $default stage for the default base path
  • Loading branch information
rddimon committed Feb 6, 2024
2 parents e88cddb + 09149dc commit 7a040f9
Show file tree
Hide file tree
Showing 17 changed files with 729 additions and 811 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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.5] - 2023-02-06

### Fixed
- Hardcoded `$default` stage for the HTTP API and default base path. More info [here](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-stages.html)

## [7.3.4] - 2023-01-30

### Fixed
Expand Down
6 changes: 0 additions & 6 deletions dependabot.yml

This file was deleted.

66 changes: 27 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "serverless-domain-manager",
"version": "7.3.4",
"version": "7.3.5",
"engines": {
"node": ">=14"
},
Expand Down Expand Up @@ -29,7 +29,6 @@
"scripts": {
"integration-basic": "nyc mocha -r ts-node/register --project tsconfig.json test/integration-tests/basic/basic.test.ts",
"integration-deploy": "nyc mocha -r ts-node/register --project tsconfig.json test/integration-tests/deploy/deploy.test.ts",
"integration-debug": "nyc mocha -r ts-node/register --project tsconfig.json test/integration-tests/debug/debug.test.ts",
"test": "find ./test/unit-tests -name '*.test.ts' | xargs nyc mocha -r ts-node/register --project tsconfig.json --timeout 5000 && nyc report --reporter=text-summary",
"test:debug": "NODE_OPTIONS='--inspect-brk' mocha -j 1 -r ts-node/register --project tsconfig.json test/unit-tests/index.test.ts",
"integration-test": "npm run integration-basic && npm run integration-deploy",
Expand Down
128 changes: 64 additions & 64 deletions src/aws/acm-wrapper.ts
Expand Up @@ -18,81 +18,81 @@ const certStatuses = [
];

class ACMWrapper {
public acm: ACMClient;
public acm: ACMClient;

constructor (credentials: any, endpointType: string) {
const isEdge = endpointType === Globals.endpointTypes.edge;
this.acm = new ACMClient({
credentials,
region: isEdge ? Globals.defaultRegion : Globals.getRegion(),
retryStrategy: Globals.getRetryStrategy(),
requestHandler: Globals.getRequestHandler()
});
}
constructor (credentials: any, endpointType: string) {
const isEdge = endpointType === Globals.endpointTypes.edge;
this.acm = new ACMClient({
credentials,
region: isEdge ? Globals.defaultRegion : Globals.getRegion(),
retryStrategy: Globals.getRetryStrategy(),
requestHandler: Globals.getRequestHandler()
});
}

public async getCertArn (domain: DomainConfig): Promise<string> {
let certificateArn; // The arn of the selected certificate
let certificateName = domain.certificateName; // The certificate name
public async getCertArn (domain: DomainConfig): Promise<string> {
let certificateArn; // The arn of the selected certificate
let certificateName = domain.certificateName; // The certificate name

try {
const certificates = await getAWSPagedResults<CertificateSummary, ListCertificatesCommandInput, ListCertificatesCommandOutput>(
this.acm,
"CertificateSummaryList",
"NextToken",
"NextToken",
new ListCertificatesCommand({ CertificateStatuses: certStatuses })
);
// enhancement idea: weight the choice of cert so longer expires
// and RenewalEligibility = ELIGIBLE is more preferable
if (certificateName) {
certificateArn = this.getCertArnByCertName(certificates, certificateName);
} else {
certificateName = domain.givenDomainName;
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}`);
}
if (certificateArn == null) {
throw Error(`Could not find an in-date certificate for '${certificateName}'.`);
try {
const certificates = await getAWSPagedResults<CertificateSummary, ListCertificatesCommandInput, ListCertificatesCommandOutput>(
this.acm,
"CertificateSummaryList",
"NextToken",
"NextToken",
new ListCertificatesCommand({ CertificateStatuses: certStatuses })
);
// enhancement idea: weight the choice of cert so longer expires
// and RenewalEligibility = ELIGIBLE is more preferable
if (certificateName) {
certificateArn = this.getCertArnByCertName(certificates, certificateName);
} else {
certificateName = domain.givenDomainName;
certificateArn = ACMWrapper.getCertArnByDomainName(certificates, certificateName);
}
return certificateArn;
Logging.logInfo(`Found a certificate ARN: '${certificateArn}'`);
} catch (err) {
throw Error(`Could not search certificates in Certificate Manager.\n${err.message}`);
}
if (certificateArn == null) {
throw Error(`Could not find an in-date certificate for '${certificateName}'.`);
}
return certificateArn;
}

private getCertArnByCertName (certificates, certName): string {
const found = certificates.find((c) => c.DomainName === certName);
if (found) {
return found.CertificateArn;
}
return null;
private getCertArnByCertName (certificates, certName): string {
const found = certificates.find((c) => c.DomainName === certName);
if (found) {
return found.CertificateArn;
}
return null;
}

private static getCertArnByDomainName (certificates, domainName): string {
// The more specific name will be the longest
let nameLength = 0;
let certificateArn;
for (const currCert of certificates) {
const allDomainsForCert = [
currCert.DomainName,
...(currCert.SubjectAlternativeNameSummaries || [])
];
for (const currCertDomain of allDomainsForCert) {
let certificateListName = currCertDomain;
// Looks for wild card and take it out when checking
if (certificateListName[0] === "*") {
certificateListName = certificateListName.substring(1);
}
// Looks to see if the name in the list is within the given domain
// Also checks if the name is more specific than previous ones
if (domainName.includes(certificateListName) && certificateListName.length > nameLength) {
nameLength = certificateListName.length;
certificateArn = currCert.CertificateArn;
}
private static getCertArnByDomainName (certificates, domainName): string {
// The more specific name will be the longest
let nameLength = 0;
let certificateArn;
for (const currCert of certificates) {
const allDomainsForCert = [
currCert.DomainName,
...(currCert.SubjectAlternativeNameSummaries || [])
];
for (const currCertDomain of allDomainsForCert) {
let certificateListName = currCertDomain;
// Looks for wild card and take it out when checking
if (certificateListName[0] === "*") {
certificateListName = certificateListName.substring(1);
}
// Looks to see if the name in the list is within the given domain
// Also checks if the name is more specific than previous ones
if (domainName.includes(certificateListName) && certificateListName.length > nameLength) {
nameLength = certificateListName.length;
certificateArn = currCert.CertificateArn;
}
}
return certificateArn;
}
return certificateArn;
}
}

export = ACMWrapper;

0 comments on commit 7a040f9

Please sign in to comment.