Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.1.1] - 2022-07-28
### Fixed
- CodePipline issue for Route53
- Certificate expiration check
## [0.9.5] - 2019-02-21
### Added
- .gitignore file [#23](https://github.com/Droplr/serverless-api-cloudfront/pull/23)
Expand Down
32 changes: 24 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,29 @@ class ServerlessAppSyncCloudFrontPlugin {
this.options = options;

this.hooks = {
"package:createDeploymentArtifacts": this.createDeploymentArtifacts.bind(
this
),
"aws:info:displayStackOutputs": this.printSummary.bind(this),
"package:createDeploymentArtifacts": this.hookDecorator.bind(this, this.createDeploymentArtifacts),
"aws:info:displayStackOutputs": this.hookDecorator.bind(this, this.printSummary),
};
}

async createDeploymentArtifacts() {
if (this.getConfig("enabled", true) !== false) {
async hookDecorator(lifecycleFunc) {
// setup AWS resources
this.initAWSResources();

return await lifecycleFunc.call(this);
}

initAWSResources() {
const credentials = this.serverless.providers.aws.getCredentials();
const acmCredentials = Object.assign({}, credentials, {
region: "us-east-1",
});
this.acm = new this.serverless.providers.aws.sdk.ACM(acmCredentials);
this.route53 = new this.serverless.providers.aws.sdk.Route53(credentials);
}

async createDeploymentArtifacts() {
if (this.getConfig("enabled", true) !== false) {
const baseResources = this.serverless.service.provider
.compiledCloudFormationTemplate;

Expand Down Expand Up @@ -105,22 +113,30 @@ class ServerlessAppSyncCloudFrontPlugin {
}
} else {
certificateName = this.getConfig("domainName");
certificates.forEach((certificate) => {
for (const certificate of certificates) {
let certificateListName = certificate.DomainName;
// Looks for wild card and takes it out when checking
if (certificateListName[0] === "*") {
certificateListName = certificateListName.substr(1);
}

// Lookup expiration because expired AWS certs sometimes have an ISSUED status
let certDescription = await this.acm
.describeCertificate({ CertificateArn: certificate.CertificateArn })
.promise();
let isCertExpired = (Date.now() > certDescription.Certificate.NotAfter);

// 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 (
!isCertExpired &&
certificateName.includes(certificateListName) &&
certificateListName.length > nameLength
) {
nameLength = certificateListName.length;
certificateArn = certificate.CertificateArn;
}
});
};
}
} catch (err) {
throw Error(
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-appsync-cloudfront",
"version": "1.0.1",
"version": "1.1.1",
"engines": {
"node": ">=8.10"
},
Expand Down