Skip to content

Commit 0cd003b

Browse files
authored
Merge pull request #38 from schwamster/next
Next
2 parents df7ccb9 + 1e0375e commit 0cd003b

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

index.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,39 @@ class CreateCertificatePlugin {
4949
};
5050
}
5151

52+
/**
53+
* Gets the details for the custom certificate from the service settings.
54+
*
55+
* If no details have been set, `null` is returned.
56+
*
57+
* @return {Object|null}
58+
*/
59+
getCustomCertificateDetails() {
60+
return (this.serverless.service.custom || {}).customCertificate || null;
61+
}
62+
5263
initializeVariables() {
5364
if (!this.initialized) {
5465
this.enabled = this.evaluateEnabled();
5566
if (this.enabled) {
67+
const customCertificate = this.getCustomCertificateDetails() || {};
68+
5669
const credentials = this.serverless.providers.aws.getCredentials();
5770
this.route53 = new this.serverless.providers.aws.sdk.Route53(credentials);
58-
this.region = this.serverless.service.custom.customCertificate.region || 'us-east-1';
59-
this.domain = this.serverless.service.custom.customCertificate.certificateName;
71+
this.region = customCertificate.region || 'us-east-1';
72+
this.domain = customCertificate.certificateName;
6073
//hostedZoneId is mapped for backwards compatibility
61-
this.hostedZoneIds = this.serverless.service.custom.customCertificate.hostedZoneIds ? this.serverless.service.custom.customCertificate.hostedZoneIds : (this.serverless.service.custom.customCertificate.hostedZoneId) ? [].concat(this.serverless.service.custom.customCertificate.hostedZoneId) : [];
74+
this.hostedZoneIds = customCertificate.hostedZoneIds ? customCertificate.hostedZoneIds : (customCertificate.hostedZoneId) ? [].concat(customCertificate.hostedZoneId) : [];
6275
//hostedZoneName is mapped for backwards compatibility
63-
this.hostedZoneNames = this.serverless.service.custom.customCertificate.hostedZoneNames ? this.serverless.service.custom.customCertificate.hostedZoneNames : (this.serverless.service.custom.customCertificate.hostedZoneName) ? [].concat(this.serverless.service.custom.customCertificate.hostedZoneName) : [];
76+
this.hostedZoneNames = customCertificate.hostedZoneNames ? customCertificate.hostedZoneNames : (customCertificate.hostedZoneName) ? [].concat(customCertificate.hostedZoneName) : [];
6477
const acmCredentials = Object.assign({}, credentials, { region: this.region });
6578
this.acm = new this.serverless.providers.aws.sdk.ACM(acmCredentials);
66-
this.idempotencyToken = this.serverless.service.custom.customCertificate.idempotencyToken;
67-
this.writeCertInfoToFile = this.serverless.service.custom.customCertificate.writeCertInfoToFile || false;
68-
this.rewriteRecords = this.serverless.service.custom.customCertificate.rewriteRecords || false;
69-
this.certInfoFileName = this.serverless.service.custom.customCertificate.certInfoFileName || 'cert-info.yml';
70-
this.subjectAlternativeNames = this.serverless.service.custom.customCertificate.subjectAlternativeNames || [];
71-
this.tags = this.serverless.service.custom.customCertificate.tags || {};
79+
this.idempotencyToken = customCertificate.idempotencyToken;
80+
this.writeCertInfoToFile = customCertificate.writeCertInfoToFile || false;
81+
this.rewriteRecords = customCertificate.rewriteRecords || false;
82+
this.certInfoFileName = customCertificate.certInfoFileName || 'cert-info.yml';
83+
this.subjectAlternativeNames = customCertificate.subjectAlternativeNames || [];
84+
this.tags = customCertificate.tags || {};
7285

7386
unsupportedRegionPrefixes.forEach(unsupportedRegionPrefix => {
7487
if (this.region.startsWith(unsupportedRegionPrefix)) {
@@ -92,7 +105,13 @@ class CreateCertificatePlugin {
92105
* If the property's value is provided, this should be boolean, otherwise an exception is thrown.
93106
*/
94107
evaluateEnabled() {
95-
const enabled = this.serverless.service.custom.customCertificate.enabled;
108+
const customCertificate = this.getCustomCertificateDetails();
109+
110+
if (!customCertificate) {
111+
return false;
112+
}
113+
114+
const enabled = customCertificate.enabled;
96115
if (enabled === undefined) {
97116
return true;
98117
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-certificate-creator",
3-
"version": "1.5.1",
3+
"version": "1.5.2",
44
"description": "creates a certificate that can be used for custom domains for your api gateway",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)